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
|
---|---|---|---|---|---|---|
from itertools import combinations
N = int(input())
L = sorted(map(int, input().split()))
ans = 0
for a, b, c in combinations(L, 3):
if a < b < c and a + b > c:
ans += 1
print(ans)
| n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
if len(list(set([L[i], L[j], L[k]]))) < 3:
continue
if L[i] + L[j] <= L[k]:
continue
ans += 1
print(ans)
| 1 | 5,034,271,505,758 | null | 91 | 91 |
import string
import sys
input_str = ""
for i in sys.stdin:
input_str += i
for i in range(26):
char = string.ascii_lowercase[i]
CHAR = string.ascii_uppercase[i]
cnt = input_str.count(char) + input_str.count(CHAR)
print("{0} : {1}".format(char, cnt)) | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
A[i] = (A[i] + A[i - 1]) % k
for i in range(n + 1):
A[i] = (A[i] - i) % k
ans = 0
D = defaultdict(int)
for j in range(n, -1, -1):
ans += D[A[j]]
D[A[j]] += 1
if j + k - 1 < n + 1:
D[A[j + k - 1]] -= 1
if k == 1:
print(0)
else:
print(ans) | 0 | null | 69,462,161,449,548 | 63 | 273 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
N=I()
L=[]
R=[]
for i in range(N):
a,b=MI()
L.append(a)
R.append(b)
L.sort()
R.sort()
#中央値の最小値は,Lの中央値.中央値の最大値はRの中央値
#間は全部埋められそう?
if N%2==0:
Lm=(L[N//2]+L[N//2-1])
Rm=(R[N//2]+R[N//2-1])
else:
Lm=L[N//2]
Rm=R[N//2]
ans=Rm-Lm+1
print(ans)
main()
| N = int(input())
nums = list(map(int,input().split()))
count = 0
current_max = nums[0]
for i in range(len(nums)-1):
nv = nums[i+1]
if nv > current_max:
current_max = nv
else:
count += (current_max - nv)
print(count) | 0 | null | 11,007,576,134,592 | 137 | 88 |
n = int(input())
A = [int(j) for j in input().split()]
q = int(input())
m = [int(j) for j in input().split()]
total = []
for i in range(2**n):
bag = []
for j in range(n):
if ((i>>j)&1):
bag.append(A[j])
total.append(sum(bag))
for m1 in m:
if m1 in set(total):
print('yes')
else:
print('no')
| N = int(input())
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if (A[i] % 2 == 0):
if A[i] % 3 != 0 and A[i] % 5 != 0:
print('DENIED')
exit()
else:
continue
else:
continue
print('APPROVED') | 0 | null | 34,380,886,549,700 | 25 | 217 |
from itertools import permutations
from math import factorial
n = int(input())
p = tuple(map(int, input().split(' ')))
q = tuple(map(int, input().split(' ')))
l = [i for i in range(1, n+1)]
ls = list(permutations(l))
for i in range(factorial(n)):
if p==ls[i]:
a = i
if q==ls[i]:
b = i
print(abs(a-b)) | d = {n: 'hon' for n in "24579"}
d.update({n: 'pon' for n in "0168"})
d.update({"3": 'bon'})
print(d[input()[-1]]) | 0 | null | 59,788,634,954,060 | 246 | 142 |
for x in range(1, 10):
for y in range(1, 10):
print "{}x{}={}".format(x, y, x*y) | def solve():
for i in range(1,10):
for j in range(1,10):
print("{0}x{1}={2}".format(i,j,i*j))
solve() | 1 | 1,601,740 | null | 1 | 1 |
n = int(input())
DP = [None] * (n + 1) # 計算結果を保存する配列
DP[0] = 1 # 定義より
DP[1] = 1 # 定義より
def fib(n):
# フィボナッチ数を2からnまで順に求めていく
for i in range(2, n + 1):
DP[i] = DP[i-1] + DP[i-2]
return DP[n]
print(fib(n))
| def fib(n):
if n == 0 or n == 1:
ans[n] = 1
return 1
# ?????¢???????¨?????????????????´???§????????°?????????????????????
if ans[n] != -1:
return ans[n]
ans[n] = fib(n-1) + fib(n-2)
return ans[n]
N = int(input())
ans = [-1 for i in range(N+1)]
a = fib(N)
print(a) | 1 | 1,756,893,770 | null | 7 | 7 |
import sys
INF = 1 << 32 - 1
S = sys.stdin.readlines()
N, M, L = map(int, S[0].split())
dp = [[INF] * N for _ in range(N)]
for i in range(1, M + 1):
A, B, C = map(int, S[i].split())
dp[A - 1][B - 1] = C
dp[B - 1][A - 1] = C
for i in range(N):
dp[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
dp2 = [[INF] * N for _ in range(N)]
for i in range(N):
for j in range(N):
if dp[i][j] <= L:
dp2[i][j] = 1
for i in range(N):
dp2[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])
Q = int(S[M + 1])
for i in range(M + 2, M + 2 + Q):
s, t = map(int, S[i].split())
refuel = dp2[s - 1][t - 1]
if refuel >= 10 ** 3:
print(-1)
else:
print(refuel - 1)
| from enum import Enum
from queue import Queue
import numpy as np
import collections
import bisect
import sys
import math
from scipy.sparse.csgraph import floyd_warshall
BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001
def warshall_floyd(d,n):
#d[i][j]:iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
N,M,L = map(int,input().split())
d = [[float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
a,b,c = map(int,input().split())
d[a-1][b-1] = c
d[b-1][a-1] = c
for i in range(N):
d[i][i] = 0
d = floyd_warshall(d)
for i in range(N):
for j in range(i,N):
if d[i][j] <= L:
d[i][j] = 1
d[j][i] = 1
else:
d[i][j] = float("inf")
d[j][i] = float("inf")
d[i][i] = 1
d = floyd_warshall(d)
Q = int(input())
for q in range(Q):
s,t = map(int,input().split())
if d[s-1][t-1] == float("inf"):
print(-1)
else:
print(int(d[s-1][t-1])-1)
| 1 | 174,023,883,916,750 | null | 295 | 295 |
S = input()
T = input()
def count_diff(s, t):
N = 0
for i, j in zip(s, t):
if i != j:
N += 1
return N
ns = len(S)
nt = len(T)
res = nt
for i in range(ns - nt + 1):
sub = S[i:i+nt]
a = count_diff(sub, T)
if a < res:
res = a
print(res) | S = input()
T = input()
min_change = 10**9
for posi_1 in range(len(S)-len(T)+1):
tmp = 0
for posi_2 in range(len(T)):
if S[posi_1+posi_2] != T[posi_2]:
tmp += 1
min_change = min(tmp, min_change)
print(min_change) | 1 | 3,622,777,623,340 | null | 82 | 82 |
MOD = 10**9 + 7
def xgcd(a, b):
x0, y0, x1, y1 = 1, 0, 0, 1
while b != 0:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return a, x0, y0
def modinv(a, mod):
g, x, y = xgcd(a, mod)
assert g == 1, 'modular inverse does not exist'
return x % mod
factorials = [1]
def factorial(n, mod):
# n! % mod
assert n >= 0, 'Argument Error! n is "0 <= n".'
if len(factorials) < n+1:
for i in range(len(factorials), n+1):
factorials.append(factorials[-1]*i % mod)
return factorials[n]
def comb(n, r, mod):
# nCr % mod
assert n >= 0, 'Argument Error! n is "0 <= n".'
assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
return perm(n, r, mod) * modinv(factorial(r, mod), mod) % mod
def perm(n, r, mod):
# nPr % mod
assert n >= 0, 'Argument Error! n is "0 <= n".'
assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
return factorial(n, mod) * modinv(factorial(n-r, mod), mod) % mod
x, y = sorted(map(int, input().split()))
MOD = 10 ** 9 + 7
q, r = divmod(x+y, 3)
if r != 0:
print(0)
else:
try:
print(comb(q, y - q, MOD))
except AssertionError:
print(0) | N=10**9+7
x , y = map(int, input().split())
a=(2*x-y)//3
b=(2*y-x)//3
if 2*a+b!=x:
print(0)
exit()
n=a+b
r=a
def fac(n,r,N):
ans=1
for i in range(r):
ans=ans*(n-i)%N
return ans
def combi(n,r,N):
if n<r or n<0 or r<0:
ans = 0
return ans
r= min(r, n-r)
ans = fac(n,r,N)*pow(fac(r,r,N),N-2,N)%N
return ans
ans = combi(n,r,N)
print(ans)
| 1 | 149,268,830,011,222 | null | 281 | 281 |
n, k = map(int, input().split())
l = [0] * n
for i in range(k):
d = int(input())
a = list(map(int, input().split()))
for j in range(d):
l[a[j] - 1] += 1
count = 0
for i in range(n):
if l[i] == 0:
count += 1
print(count) | #import time
def main():
N, K = map(int, input().split())
matrix = [list(map(int, input().split())) for i in range(2*K)]
sunuke = [0]*(N+1)
for i in range(K):
for j in matrix[2*i+1]:
sunuke[j] += 1
ans = sunuke.count(0) -1
return ans
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]") | 1 | 24,739,383,449,820 | null | 154 | 154 |
r,c = [int(i) for i in input().split()]
a = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
a[i] = [int(j) for j in input().split()]
for i in range(r):
rowSum = 0
for j in range(c):
rowSum += a[i][j]
a[i].append(rowSum)
for i in range(c+1):
columnSum = 0
for j in range(r):
columnSum += a[j][i]
a[r][i] = columnSum
for i in range(r+1):
for j in range(c):
print(a[i][j],end=' ')
print(a[i][c]) | r, c = [int(s) for s in input().split()]
rows = [[0 for i in range(c + 1)] for j in range(r + 1)]
for rc in range(r):
in_row = [int(s) for s in input().split()]
for cc, val in enumerate(in_row):
rows[rc][cc] = val
rows[rc][-1] += val
rows[-1][cc] += val
rows[-1][-1] += val
for row in rows:
print(' '.join([str(i) for i in row])) | 1 | 1,357,848,275,762 | null | 59 | 59 |
def main():
W,H,x,y,r=map(int,input().split())
if x<=0 or y<=0:
print('No')
elif W>=2*r and H>=2*r and W>=x+r and H>=y+r:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| x = input()
y = x.split(" ")
y = [int(z) for z in y]
w = y[0]
h = y[1]
x = y[2]
r = y[4]
y = y[3]
if (x <= w-r and x >= r) and (y <= h-r and y >= r):
print("Yes")
else:
print("No") | 1 | 451,735,408,740 | null | 41 | 41 |
if __name__ == '__main__':
s = input()
q = int(input())
for i in range(q):
code = input().split()
op, a, b = code[0], int(code[1]), int(code[2])
if op == 'print':
print(s[a:b+1])
elif op == 'reverse':
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
elif op == 'replace':
s = s[:a] + code[3] + s[b+1:] | #coding: utf-8
#itp1_9d
def rev(s,a,b):
b=b+1
t=s[a:b]
u=t[::-1]
x=s[:a]
y=s[b:]
return x+u+y
def rep(s,a,b,w):
b=b+1
x=s[:a]
y=s[b:]
return x+w+y
s=raw_input()
n=int(raw_input())
for i in xrange(n):
d=raw_input().split()
a=int(d[1])
b=int(d[2])
if d[0]=="print":
print s[a:b+1]
elif d[0]=="reverse":
s=rev(s,a,b)
elif d[0]=="replace":
w=d[3]
s=rep(s,a,b,w) | 1 | 2,113,438,040,948 | null | 68 | 68 |
height_list = []
for i in range(10):
height_list.append(input())
height_list.sort()
height_list.reverse()
for height in height_list[:3]:
print height | moutain = [0 for i in range(10)]
for i in range(10):
moutain[i] = int(raw_input())
moutain.sort(reverse=True)
for i in range(3):
print moutain[i]
| 1 | 30,342,450 | null | 2 | 2 |
class findroop:
def __init__(self, n, nex):
self.n = n
self.next = nex
#遷移start回でループに入る、end回でループする
#A->B->C->D->B: return=(1, 4)
#C->D->B->C : return=(0, 3)
#O(n)
def findroop(self, start):
roopstart = -1
roopend = -1
visited = [False for i in range(self.n)]
visitlist = []
now = start
for i in range(self.n):
if visited[now]:
roopend = i
break
else:
visited[now] = True
visitlist.append(now)
now = self.next(now)
for i in range(len(visitlist)):
if visitlist[i] == now:
roopstart = i
return (roopstart, roopend)
N,X,M = list(map(int, input().split()))
fr = findroop(M, lambda x: x**2 % M)
roopstart, roopend = fr.findroop(X)
ans = 0
if N <= roopstart:
for i in range(N):
ans += X
X = (X**2)%M
else:
for i in range(roopstart):
ans += X
X = (X**2)%M
N -= roopstart
roopsum = 0
for i in range(roopend-roopstart):
roopsum += X
X = (X**2) % M
ans += (N // (roopend-roopstart)) * roopsum
N = N % (roopend-roopstart)
for i in range(N):
ans += X
X = (X**2) % M
print(ans) | import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
def li():
return [int(x) for x in input().split()]
N, X, MOD = li()
n = X
nums = [X]
loop_start_i = -INF
for i in range(1, N):
n = pow(n, 2, MOD)
if n in nums:
loop_start_i = nums.index(n)
break
nums.append(n)
# total %= MOD
loop_length = len(nums) - loop_start_i
loop_cnt = (N - loop_start_i) // loop_length
r = (N - loop_start_i) % loop_length
sum_per_loop = sum(nums[loop_start_i:])
ans = sum(nums[:loop_start_i]) + sum_per_loop * loop_cnt + sum(nums[loop_start_i:loop_start_i+r])
print(ans) | 1 | 2,795,618,749,380 | null | 75 | 75 |
a,b = [int(x) for x in input().split()]
def gcd(x,y):
if y == 0:
return x
return gcd(y,x%y)
print(a*b//gcd(a,b)) | W,H,x,y,r=map(int, input().split(" "))
if x<r or y<r or x+r>W or y+r>H :
print('No')
else :
print('Yes') | 0 | null | 56,797,911,683,280 | 256 | 41 |
from collections import deque
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
points = {"r":r,"s":s,"p":p}
d = {"r":"p","s":"r","p":"s"}
que = deque([None]*k)
ans = 0
for ti in t:
x = que.popleft()
if d[ti] != x:
#print(d[ti])
que.append(d[ti])
ans+=points[d[ti]]
else:
#print(None)
que.append(None)
#que.popleft()
#print(que,ti)
print(ans) | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = input()
last = ["" for _ in range(k)]
move = {"r": "p", "p": "s", "s": "r"}
pts = {"r": r, "p": p, "s": s}
score = 0
for i in range(n):
if move[t[i]] != last[i%k]:
score += pts[move[t[i]]]
last[i%k] = move[t[i]]
else:
last[i%k] = ""
print(score) | 1 | 106,726,791,549,180 | null | 251 | 251 |
def sel_sort(A, N):
''' 選択ソート '''
count = 0
for n in range(N):
minm = n
for m in range(n, N):
if A[m] < A[minm]:
minm = m
if minm != n:
A[n], A[minm] = A[minm], A[n]
count += 1
return (A, count)
if __name__ == '__main__':
N = int(input())
A = list(map(int, input().split(' ')))
ans = sel_sort(A, N)
print(' '.join([str(x) for x in ans[0]]))
print(ans[1])
| # -*- coding: utf-8 -*-
def selection_sort(n, a):
cnt = 0
for i in range(n):
minj = i
for j in range(i, n):
if a[j] < a[minj]:
minj = j
if i != minj:
tmp = a[minj]
a[minj] = a[i]
a[i] = tmp
cnt += 1
return a, cnt
if __name__ == '__main__':
n = int(input())
a = [int(n) for n in input().split()]
ans, cnt = selection_sort(n, a)
print(' '.join(map(str, ans)))
print(cnt) | 1 | 21,139,451,718 | null | 15 | 15 |
X, Y, Z = list(map(str, input().split()))
print(Z+' '+X+' '+Y) | import sys
sys.setrecursionlimit(10**6)
def solve(n,a):
wa=0
for i in range(n):
if(i%2==0):
wa+=a[i]
kotae=wa
for i in range(n//2):
wa+=a[(n//2-i-1)*2+1]
wa-=a[(n//2-i-1)*2]
if(wa>kotae):
kotae=wa
return kotae
def dfs(n,a,k):
global zen
zen.append([n,k])
if(k==1):
return max(a)
ari=a[n-1]+dfs(n-2,a[:n-2],k-1)
if(n==k*2-1):
return ari
nasi=dfs(n-1,a[:n-1],k)
return max(ari,nasi)
n=int(input())
a=list(map(int,input().split()))
if(n%2==0):
print(solve(n,a))
else:
data=[[a[0],a[0]],[max(a[:2]),max(a[:2])]]
#data.append([max(a[:3]),sum(a[:3])-min(a[:3])])
data.append([max(a[:3]),a[0]+a[2]])
for i in range(3,n):
if(i%2==1):
ari=a[i]+data[i-2][0]
nasi=data[i-1][1]
saiyo=max(ari,nasi)
data.append([saiyo,saiyo])
else:
ooi=a[i]+data[i-2][1]
nasi=data[i-1][1]
ari=a[i]+data[i-2][0]
sukunai=max(ari,nasi)
data.append([sukunai,ooi])
print(data[n-1][0]) | 0 | null | 37,694,853,319,328 | 178 | 177 |
def main():
labels = list(map(int, input().split(' ')))
n = int(input())
for i in range(n):
dice = Dice(labels)
t, f = map(int, input().split(' '))
for j in range(8):
if j%4 == 0:
dice.toE()
if f == dice.front:
break
dice.toN()
for j in range(4):
if t == dice.top:
break
dice.toE()
print(dice.right)
class Dice:
def __init__(self, labels):
self.labels = labels
self._tb = (0, 5)
self._fb = (1, 4)
self._lr = (3, 2)
def toN(self):
tb = self._tb
self._tb = self._fb
self._fb = tuple(reversed(tb))
return self
def toS(self):
tb = self._tb
self._tb = tuple(reversed(self._fb))
self._fb = tb
return self
def toW(self):
tb = self._tb
self._tb = tuple(reversed(self._lr))
self._lr = tb
return self
def toE(self):
tb = self._tb
self._tb = self._lr
self._lr = tuple(reversed(tb))
return self
def get_top(self):
return self.labels[self._tb[0]]
def get_front(self):
return self.labels[self._fb[0]]
def get_right(self):
return self.labels[self._lr[1]]
top = property(get_top)
front = property(get_front)
right = property(get_right)
if __name__ == '__main__':
main() | import sys
import math
def str_input():
S = raw_input()
if S[len(S)-1] == "\r":
return S[:len(S)-1]
return S
def float_to_str(num):
return str("{:.10f}".format(num))
def list_input(tp):
return map(tp, str_input().split())
# # # # # # # # # # # # # # # # # # # # # # # # #
class Dice:
pip = [0 for i in xrange(6)]
def __init__(self, arg):
self.pip = arg
def rollDir(self, dr):
nextPip = [0 for i in xrange(6)]
if dr == "N":
nextPip[0] = self.pip[1]
nextPip[1] = self.pip[5]
nextPip[2] = self.pip[2]
nextPip[3] = self.pip[3]
nextPip[4] = self.pip[0]
nextPip[5] = self.pip[4]
elif dr == "E":
nextPip[0] = self.pip[3]
nextPip[1] = self.pip[1]
nextPip[2] = self.pip[0]
nextPip[3] = self.pip[5]
nextPip[4] = self.pip[4]
nextPip[5] = self.pip[2]
self.pip = nextPip
def roll(self, dr):
if dr == "N" or dr == "E":
self.rollDir(dr)
elif dr == "S":
self.rollDir("N")
self.rollDir("N")
self.rollDir("N")
elif dr == "W":
self.rollDir("E")
self.rollDir("E")
self.rollDir("E")
dice = Dice(list_input(int))
for i in xrange(input()):
a, b = list_input(int)
while dice.pip[0] != a:
if dice.pip[2] != a and dice.pip[3] != a:
dice.roll("N")
else:
dice.roll("N")
dice.roll("W")
dice.roll("S")
while dice.pip[1] != b:
dice.roll("N")
dice.roll("W")
dice.roll("S")
print dice.pip[2] | 1 | 251,717,262,340 | null | 34 | 34 |
S = input()
result = 0
if "R" in S:
if "RR" in S:
result = S.count("R")
else:
result = 1
print(result)
| S = input()[0:3]
i=S.count('RRR')
j=S.count('RR')
k=S.count('R')
l=S.count('RSR')
print(max(i,j,k-l)) | 1 | 4,881,064,829,560 | null | 90 | 90 |
import sys
a,b,c = map(int,sys.stdin.readline().split())
if a < b and b < c:
print('Yes')
else:
print('No') | a,b,c = raw_input().strip().split(" ")
if int(a) < int(b) < int(c):
print "Yes"
else:
print "No" | 1 | 377,548,022,852 | null | 39 | 39 |
a,b,c=map(int,input().split())
if b%c==0 or a%c==0:
print(int((b-a)/c)+1)
else:
print(int((b-a)/c)) | import math
while True:
try:
n=input()
x=100000
for i in xrange(n):
x=math.ceil(x*1.05/1000)*1000
print(int(x))
except EOFError: break | 0 | null | 3,824,677,908,140 | 104 | 6 |
k = int(input())
a, b = map(int, input().split())
if a % k == 0:
print("OK")
exit()
nex = k * ((a // k) + 1)
if nex <= b:
print("OK")
else:
print("NG") | k=int(input())
print("ACL"*k)
| 0 | null | 14,385,805,370,222 | 158 | 69 |
import math
n=int(input())
ans=n-1
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
ans=min(ans,(i-1)+(n//i)-1)
print(ans) | N, X, Y = map(int, input().split())
d = Y-X+1
l = [0]*(N+1)
for i in range(1, N+1):
for j in range(i, N+1):
m = min(j-i, abs(X-i)+1+abs(Y - j))
l[m] += 1
print(*l[1:-1], sep="\n")
| 0 | null | 102,795,760,346,600 | 288 | 187 |
k = int(input())
a, b=map(int, input().split())
c=0
for i in range(a, b+1):
if i%k == 0:
c += 1
else:
pass
if c == 0:
print("NG")
else:
print("OK") | X,K,D = map(int,input().split())
X = abs(X)
ans = 0
if X>=D and D*K<=X:
ans = X - D*K
if X>=D and D*K>X:
K=K-int(X/D)
X=X%D
if K%2==0:
ans=X
else:
ans = abs(X-D)
if X<D:
if K%2==0:
ans = X
else:
ans = abs(X-D)
print(ans) | 0 | null | 16,025,821,665,700 | 158 | 92 |
# -*- coding: utf-8 -*-
from sys import stdin
import math
# 0 0 1 1
A = list(map(float, stdin.readline().split()))
x1, y1, x2, y2 = A[0], A[1], A[2], A[3]
distance = math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1,2))
print(format(distance,'.8f'))
| A,B,C,K=map(int,input().split())
print(1*min(A,K)-1*max(0,K-A-B))
| 0 | null | 10,883,961,170,072 | 29 | 148 |
import sys
readline = sys.stdin.readline
N = int(readline())
A = []
B = []
for _ in range(N):
a, b = map(int, readline().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
mi = A[N//2-1]+A[N//2]
ma = B[N//2-1]+B[N//2]
else:
mi = A[N//2]
ma = B[N//2]
print(ma-mi+1)
| N = int(input())
print(N ** 2)
| 0 | null | 81,444,872,093,360 | 137 | 278 |
n,m = map(int, input().split())
s = input()
now = 0
MIN = 0
ans = []
while now < n:
for i in range(min(n-now,m),0,-1):
nex = now + i
if s[nex] == "0":
now = nex
MIN += 1
break
else:
print(-1)
exit()
now = 0
while now < n:
for i in range(min(n-now,m),0,-1):
nex = now + i
if s[n-nex] == "0":
now = nex
ans.append(i)
break
print(*reversed(ans))
| N, K = map(int, input().split())
h = list(map(int, input().split()))
cn = 0
for i in range(N):
if h[i] >= K:
cn = cn + 1
print(cn)
| 0 | null | 158,935,456,924,292 | 274 | 298 |
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools
@functools.lru_cache(None)
def dfs(i,sum_v,val):
if i == n:
return sum_v == val
if dfs(i+1,sum_v,val):
return True
if dfs(i+1,sum_v + A[i],val):
return True
return False
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
for i in range(q):
if dfs(0,0,m[i]):
print("yes")
else:
print("no")
| N = int(input())
A = list(map(int,input().split()))
Q = int(input())
M = list(map(int,input().split()))
def bitsearch():
nums = [0] * (2 ** N)
for i in range(2 ** N):
num = 0
for j in range(N):
if (i >> j) & 1:
num += A[j]
nums[i] = num
for q in range(Q):
if M[q] in nums:
print("yes")
else:
print("no")
bitsearch()
| 1 | 98,081,185,080 | null | 25 | 25 |
def goes_to_zero(n):
cnt = 0
while(n > 0):
n %= bin(n).count('1')
cnt += 1
return cnt
N = int(input())
X = input()
XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0
for i in range(N):
if X[i] == "0":
print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
else:
if XCM == 0:
print(0)
else:
print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1) | N=int(input())
alpha=[chr(ord('a') + i) for i in range(26)]
l=[]
def ans(le,alp):
s=len(set(alp))
if le==N:
l.append(alp)
return
for i in range(s+1):
ans(le+1,alp+alpha[i])
ans(1,"a")
for i in l:
print(i) | 0 | null | 30,488,907,953,550 | 107 | 198 |
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ans = arr[0]
i = 1
j = 1
while i < n-1:
ans += arr[j]
#print (arr[j])
if i % 2 == 0:
j += 1
i += 1
print (ans) | x = 1
y = 1
while x != 0 or y != 0:
n = map(int,raw_input().split())
x = n[0]
y = n[1]
if x == 0 and y == 0:
break
elif x <= y:
print x,y
elif x > y:
print y,x | 0 | null | 4,877,334,084,480 | 111 | 43 |
a,b,c,d = map(int,input().split())
while a > 0 and c > 0 :
c -= b
a -= d
if c <= 0 :
print('Yes')
else :
print('No') | n = int(input())
a = list(map(int, input().split()))
if n == 0 and a[0] != 1:
print(-1)
exit(0)
b = [0] * (n + 2)
for i in range(n, 0, -1):
b[i - 1] = b[i] + a[i]
t = 1 - a[0]
ans = 1
for i in range(n):
m = min(t * 2, b[i])
if m < a[i + 1]:
print(-1)
exit(0)
ans += m
t = m - a[i + 1]
print(ans)
| 0 | null | 24,165,406,851,388 | 164 | 141 |
class Dice:
def __init__(self):
self.d = list(map(int, input().split()))
def setNum(self, n0, n1, n2, n3, n4, n5):
self.d[0], self.d[1], self.d[2], self.d[3], self.d[4], self.d[5] = (
n0,
n1,
n2,
n3,
n4,
n5,
)
def roll(self, direction):
if direction == "E":
self.setNum(
self.d[3], self.d[1], self.d[0], self.d[5], self.d[4], self.d[2]
)
elif direction == "N":
self.setNum(
self.d[1], self.d[5], self.d[2], self.d[3], self.d[0], self.d[4]
)
elif direction == "S":
self.setNum(
self.d[4], self.d[0], self.d[2], self.d[3], self.d[5], self.d[1]
)
elif direction == "W":
self.setNum(
self.d[2], self.d[1], self.d[5], self.d[0], self.d[4], self.d[3]
)
def top(self):
return self.d[0]
def setTop(self, t):
if self.d[0] == t:
return
elif self.d[1] == t:
self.roll("N")
elif self.d[2] == t:
self.roll("W")
elif self.d[3] == t:
self.roll("E")
elif self.d[4] == t:
self.roll("S")
elif self.d[5] == t:
self.roll("N")
self.roll("N")
def getRight(self, f):
if self.d[2] == f:
return self.d[4]
elif self.d[3] == f:
return self.d[1]
elif self.d[4] == f:
return self.d[3]
else:
return self.d[2]
dice = Dice()
q = int(input())
for i in range(q):
t, f = map(int, input().split())
dice.setTop(t)
print(dice.getRight(f))
| N = int(input())
A = list(map(int,input().split()))
Q = int(input())
M = list(map(int,input().split()))
def bitsearch():
nums = [0] * (2 ** N)
for i in range(2 ** N):
num = 0
for j in range(N):
if (i >> j) & 1:
num += A[j]
nums[i] = num
for q in range(Q):
if M[q] in nums:
print("yes")
else:
print("no")
bitsearch()
| 0 | null | 183,604,948,228 | 34 | 25 |
A, B = map(int, input().split())
#最大公約数
def gcd(x, y):
while y:
x, y = y, x % y
return x
#最小公倍数
def lcm(x, y):
return x * y // gcd(x, y)
print(lcm(A, B))
| import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions
def main():
a,b = map(int, input().split())
print(a*b//fractions.gcd(a, b))
if __name__ == '__main__':
main()
| 1 | 112,822,093,260,672 | null | 256 | 256 |
from itertools import accumulate
from bisect import bisect_left
n, m = map(int, input().split())
a = sorted(map(int, input().split()))
cs = [0] + list(accumulate(a))
c = 0
s = 0
def f(x):
global c, s
c = 0
s = 0
for i in range(n):
left = bisect_left(a, x - a[i])
c += n - left
s += cs[n] - cs[left] + (n - left) * a[i]
return c
ok = 0
ng = 2 * 10 ** 5 + 1
while abs(ok - ng) > 1:
x = (ok + ng) // 2
if f(x) >= m:
ok = x
else:
ng = x
print(s - (c - m) * ok)
| N = int(input())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
def median(arr):
arr.sort()
n = len(arr)
if n % 2 == 1:
return arr[(n + 1) // 2 - 1]
else:
return (arr[n//2 - 1] + arr[n//2]) / 2
med_a = median(A)
med_b = median(B)
if N % 2 == 1:
ans = int(med_b) - int(med_a) + 1
else:
ans = med_b * 2 - med_a * 2 + 1
ans = int(ans)
print(ans) | 0 | null | 62,853,313,569,082 | 252 | 137 |
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a)+min(b)
for i in range(M):
x,y,z = map(int,input().split())
s = a[x-1]+b[y-1]-z
ans = (s if s < ans else ans)
print(ans) | N,X,M = [int(a) for a in input().split()]
amari = [0]*M
i = 1
A = X
amari[A] = i
l = [X]
ichi = i
while i<=M:
i += 1
A = A**2 % M
if amari[A]: i += M
else:
amari[A] = i
l.append(A)
if i==N: i = M+1
else:
if i>M+1: ni = i-M - amari[A]
else: ni = 0
#for j in range(M):
# if amari[j]: print(j, amari[j])
#print(i,len(l))
ichi = len(l) - ni
#print(l)
if ni:
ni_times, san = divmod((N - ichi), ni)
#print(ichi, '%d*%d'%(ni,ni_times), san)
print(sum(l[:ichi]) +
sum(l[ichi:])*ni_times +
sum(l[ichi:ichi+san]))
else:
#print(ichi, '%d*%d'%(ni,ni_times), san)
print(sum(l)) | 0 | null | 28,390,442,381,664 | 200 | 75 |
set = raw_input().split()
if int(set[0]) < int(set[1]) < int(set[2]):
print 'Yes'
else:
print 'No' | # coding: utf-8
# Your code here!
N=input().split()
a=int(N[0])
b=int(N[1])
c=int(N[2])
if a < b < c:
print("Yes")
else:
print("No")
| 1 | 382,410,905,338 | null | 39 | 39 |
from collections import deque
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
score = dict(r=P, s=R, p=S)
ans = 0
q = deque()
for i in range(K):
s = T[i]
ans += score[s]
q.append(s)
for i in range(K, N):
s = T[i]
s_pre_k = q.popleft()
if s == s_pre_k:
q.append('n')
else:
ans += score[s]
q.append(s)
print(ans)
|
mod = 10**9+7
MAX_N = 10 ** 6
fact = [1]
fact_inv = [0] * (MAX_N + 4)
for i in range(MAX_N + 3):
fact.append(fact[-1] * (i + 1) % mod)
fact_inv[-1] = pow(fact[-1], mod - 2, mod)
for i in range(MAX_N + 2, -1, -1):
fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod
def mod_comb_k(n, k, mod):
return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod
OK = False
X, Y = map(int, input().split())
for i in range(0, max(X, Y)+1):
if (Y - (X - i*2)*2) == i and X-2*i >= 0:
x = i
y = X - i*2
print(mod_comb_k(x + y, min(x, y), mod))
OK = True
break
if not OK:
print(0) | 0 | null | 128,550,190,806,492 | 251 | 281 |
n,k,s = map(int, input().split())
if s!=10**9:
x = [10**9]*n
else:
x = [1]*n
for i in range(k):
x[i]=s
print(*x)
| n,k,s = map(int, input().split())
ans = []
if s == 10**9:
for i in range(k):
ans.append(10**9)
for i in range(n-k):
ans.append(1)
else:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(s+1)
print(*ans) | 1 | 91,243,641,552,800 | null | 238 | 238 |
n=int(input());s=[*input()];count=0
count=s.count('R')*s.count('G')*s.count('B')
for i in range(n+1):
for j in range(i,n+1):
k=2*j-i
if k<n:
if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
count-=1
print(count) | N = int(input())
S = list(input())
R = []
G = []
B = [0 for _ in range(N)]
b_cnt = 0
for i in range(N):
if S[i] == 'R':
R.append(i)
elif S[i] == 'G':
G.append(i)
else:
B[i] = 1
b_cnt += 1
answer = 0
for r in R:
for g in G:
answer += b_cnt
if (g-r)%2 == 0 and B[(r+g)//2] == 1:
answer -= 1
if 0 <= 2*g-r < N and B[2*g-r] == 1:
answer -= 1
if 0 <= 2*r-g < N and B[2*r-g] == 1:
answer -= 1
print(answer) | 1 | 36,223,466,608,996 | null | 175 | 175 |
n = int(input())
furui = [i for i in range(10**6+2)]
ans = 9999999999999
yakusuu = []
for i in range(1,int(n**0.5)+1+1):
if n%i == 0:
yakusuu.append(i)
for i in yakusuu:
ans = min(i+n//i,ans)
# print(i,ans)
print(ans-2)
| N = int(input())
x = int(N**(0.5)) + 1
while True:
if N % x == 0:
print((x-1)+((N//x)-1))
break
x -= 1
| 1 | 161,685,868,109,468 | null | 288 | 288 |
def solve():
N,X,Y = [int(i) for i in input().split()]
distance_cnt = {}
for i in range(1, N+1):
for j in range(i+1, N+1):
distance = min(j-i, abs(X-i)+abs(Y-j)+1)
distance_cnt[distance] = distance_cnt.get(distance, 0) + 1
for i in range(1, N):
print(distance_cnt.get(i, 0))
if __name__ == "__main__":
solve() | from sys import stdin
input = stdin.readline
K = int(input())
print("ACL" * K)
| 0 | null | 23,280,064,762,430 | 187 | 69 |
N, X, Y = map(int, input().split())
count = [0]*(N+1)
for i in range(1, N+1):
for k in range(i+1, N+1):
distik = min(k-i, abs(k-X) + abs(i - Y)+1, abs(k-Y) + abs(i-X)+1)
count[distik] += 1
for i in range(1, N):
print(count[i])
| def main():
n, x, y = map(int, input().split())
distances = [0 for _ in range(n)]
for i in range(1, n+1):
for j in range(i+1, n+1):
distances[min(j-i, min(abs(i-x)+abs(j-y), abs(j-x)+abs(i-y))+1)] += 1
for v in distances[1:]:
print(v)
if __name__ == '__main__':
main()
| 1 | 44,326,390,646,918 | null | 187 | 187 |
def sheep_and_wolves():
condition = input()
condition_list = condition.split()
S = int(condition_list[0])
W = int(condition_list[1])
if S > W:
print('safe')
return
elif S <= W:
print('unsafe')
return
sheep_and_wolves() | s,t = map(int,input().split())
if t >= s:
print("unsafe")
else:
print("safe") | 1 | 28,996,479,634,560 | null | 163 | 163 |
n, k = list(map(int, input().split()))
s = []
for i in range(k):
a, b = list(map(int, input().split()))
s.append((a, b))
dp = [0]*(n+1)
v = 0
mod = 998244353
for i in range(1, n+1):
if i == 1:
for l, r in s:
if i+l <= n:
dp[i+l] += 1
if i+r+1 <= n:
dp[i+r+1] -= 1
else:
v += dp[i]
v %= mod
for l, r in s:
if i+l <= n:
dp[i+l] += v
if i+r+1 <= n:
dp[i+r+1] -= v
print(v % mod)
| N = int(input())
print(N // 2 - 1 if N % 2 == 0 else (N-1) // 2) | 0 | null | 78,340,959,399,968 | 74 | 283 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
ans = 0
for i in range(1,N+1):
if i % 3 == 0 or i % 5 == 0:
continue
ans += i
print(ans) | from sys import stdin
from math import sqrt
x1, y1, x2, y2 = [float(x) for x in stdin.readline().rstrip().split()]
print(sqrt((x2-x1)**2 + (y2-y1)**2))
| 0 | null | 17,464,075,102,012 | 173 | 29 |
n = int(input())
for a in range(-118,120):
for b in range(-119,119):
if a ** 5 - b **5 == n :
print(a,b)
exit() | X = int(input())
found = False
for a in range(-200, 200):
if found: break;
for b in range(-200, 200):
if a ** 5 - b ** 5 == X:
print(a, b)
found = True
break
| 1 | 25,675,165,562,340 | null | 156 | 156 |
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
count = 0
for i in range(q):
s.append(t[i])
j = 0
while t[i] != s[j]:
j += 1
if j != n:
count += 1
del s[n]
print(count)
| class UnionFind:
from typing import List, Set
def __init__(self, n):
self.n = n
self.parent = [-1] * n
def union(self, x, y) -> int:
x = self.leader(x)
y = self.leader(y)
if x == y:
return 0
if self.parent[x] > self.parent[y]:
x, y = y, x
self.parent[x] += self.parent[y]
self.parent[y] = x
return self.parent[x]
def same(self, x, y) -> bool:
return self.leader(x) == self.leader(y)
def leader(self, x) -> int:
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.leader(self.parent[x])
return self.parent[x]
def size(self, x) -> int:
return -self.parent[self.leader(x)]
def groups(self) -> List[Set[int]]:
groups = dict()
for i in range(self.n):
p = self.leader(i)
if not groups.get(p):
groups[p] = set()
groups[p].add(i)
return list(groups.values())
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
uf.union(a-1, b-1)
print(len(uf.groups()) - 1) | 0 | null | 1,195,377,979,746 | 22 | 70 |
S,T=input().split()
print('{}{}'.format(T,S)) | n,m = map(int,input().split())
s = input()
s = s[::-1]
tmp = 0
sum1 = 0
ans = []
while tmp < n:
for i in range(m, 0, -1):
flag = False
if tmp + i <= n:
if s[tmp+i] == '0':
tmp += i
flag = True
sum1 += 1
ans.append(i)
break
if not flag:
print(-1)
exit()
for i in ans[::-1]:
print(i, end = ' ')
| 0 | null | 121,064,171,628,412 | 248 | 274 |
a = input()
day = ['SUN','MON','TUE','WED','THU','FRI','SAT']
values = [7,6,5,4,3,2,1]
d = dict(zip(day,values))
print(d[a])
| day = input('')
if day == 'SUN':
print('7')
elif day == 'MON':
print('6')
elif day == 'TUE':
print('5')
elif day == 'WED':
print('4')
elif day == 'THU':
print('3')
elif day == 'FRI':
print('2')
else:
print('1') | 1 | 132,712,859,330,610 | null | 270 | 270 |
s, t = input().split()
a, b = [int(x) for x in input().split()]
u = input()
if u == s:
a -= 1
else:
b -= 1
print(a, b) | 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) | 0 | null | 45,184,007,101,800 | 220 | 141 |
ls = list(map(int,input().split()))
print(str(min(ls))*max(ls)) | # n,k = map(int,input().split())
# A = list(map(int,input().split()))
# c = 0
# from collections import Counter
# d = Counter()
# d[0] = 1
# ans = 0
# r = [0]*(n+1)
# for i,x in enumerate(A):
# if i>=k-1:
# d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす
# c = (c+x-1)%k
# ans += d[c]
# d[c] += 1
# r[i+1] = c
# print(ans)
n,k = map(int,input().split())
A = list(map(int,input().split()))
S = [0]
for a in A:
S.append(S[-1] + a)
# print(S)
from collections import defaultdict
dic = defaultdict(int)
ans = 0
for i,s in enumerate(S):
if i >=k:
dic[(S[i-k] - (i-k))%k]-=1
ans += dic[(S[i]- i)%k]
# print(i,s,(S[i]- i)%k,dic[(S[i]- i)%k],ans)
dic[(S[i]- i)%k] += 1
print(ans)
#(12-6)%4 | 0 | null | 110,686,165,478,432 | 232 | 273 |
s = int(input())
m = s // 60
s = s % 60
h = m // 60
m = m % 60
print("{}:{}:{}".format(h, m, s)) | #coding: utf-8
n = int(input())
color = ["white" for i in range(n)]
d = [[] for i in range(n)]
global t
t = 0
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
data = list(map(int,input().split()))
u = data[0]
k = data[1]
if i == 0:
start = u
for v in data[2:2+k]:
M[u-1][v-1] = True
def search(u,t):
t += 1
color[u-1] = "gray"
d[u-1].append(t)
for v in range(1,n+1):
if M[u-1][v-1] and color[v-1] == "white":
t = search(v,t)
color[u-1] = "black"
t += 1
d[u-1].append(t)
return t
t = search(start, t)
for i in range(1,n+1):
if color[i-1] == "white":
t = search(i, t)
for i in range(n):
print(i+1, d[i][0], d[i][1])
| 0 | null | 163,046,705,350 | 37 | 8 |
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
x = int(input())
if 30 <= x:
print("Yes")
else:
print("No")
| def main():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
ans = 0
for i in range(N):
if int(S[i]) % P == 0:
ans += (i + 1)
print(ans)
exit()
sum_rem = [0] * N
sum_rem[0] = int(S[N - 1]) % P
ten = 10
for i in range(1, N):
a = (int(S[N - 1 - i]) * ten) % P
sum_rem[i] = (a + sum_rem[i - 1]) % P
ten = (ten * 10) % P
ans = 0
count = [0] * P
count[0] = 1
for i in range(N):
ans += count[sum_rem[i]]
count[sum_rem[i]] += 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 31,865,733,678,350 | 95 | 205 |
h,w=map(int,input().split())
s=[input() for _ in range(h)]
dp=[[10**9]*w for _ in range(h)]
dp[0][0]=(s[0][0]=='#')+0
for i in range(h):
for j in range(w):
a=dp[i-1][j]
b=dp[i][j-1]
if s[i-1][j] == "." and s[i][j] == "#":
a+=1
if s[i][j-1] == "." and s[i][j] == "#":
b+=1
dp[i][j]=min(a,b,dp[i][j])
print(dp[-1][-1])
| H,W=list(map(int,input().split()))
l=[list(input()) for i in range(H)]
inf=10**9
DP=[[inf]*W for i in range(H)]
DP[0][0]=0 if l[0][0]=="." else 1
for i in range(H):
for j in range(W):
if i>0:
DP[i][j]=min(DP[i][j],DP[i-1][j]+1) if l[i-1][j] == "." and l[i][j]=="#" else min(DP[i][j],DP[i-1][j])
if j>0:
DP[i][j]=min(DP[i][j],DP[i][j-1]+1) if l[i][j-1] == "." and l[i][j]=="#" else min(DP[i][j],DP[i][j-1])
print(DP[H-1][W-1]) | 1 | 49,216,339,372,380 | null | 194 | 194 |
import fractions
A,B=map(int,input().split())
def lcm(x,y):
return int((x*y)/fractions.gcd(x,y))
print(lcm(A,B)) | from fractions import gcd
def lcm(x, y):
return (x * y) // gcd(x, y)
def main():
a,b = map(int,input().split())
print(lcm(a, b))
main()
| 1 | 113,149,095,574,372 | null | 256 | 256 |
from math import *
a, b, C = (int(i) for i in input().split())
C = pi * C / 180
c = sqrt(a**2 + b**2 - 2 * a * b * cos(C))
h = b * sin(C)
S = a * h / 2
L = a + b + c
print("{:.8f} {:.8f} {:.8f}".format(S, L, h)) | # AGC 043 A
H,W = map(int, input().split())
table = [input() for _ in range(H)]
inf = 10**9
dp = [[inf] * (W+1) for _ in range(H+1)]
dp[0][0] = 0 if table[0][0] == "." else 1
for h in range(H):
for w in range(W):
flg = table[h][w] == "." and (table[h][w+1] == "#" if w < W-1 else True)
dp[h][w+1] = min(dp[h][w+1], dp[h][w] + 1 if flg else dp[h][w])
flg = table[h][w] == "." and (table[h+1][w] == "#" if h < H-1 else True)
dp[h+1][w] = dp[h][w] + 1 if flg else dp[h][w]
print(dp[H-1][W-1])
| 0 | null | 24,706,630,656,808 | 30 | 194 |
import math
a,b,x = map(int,input().split())
if x > a*a*b/2:
tan = 2*(a*a*b - x)/(a*a*a)
elif x <= a*a*b/2:
tan = a*b*b/(2*x)
print(math.degrees(math.atan(tan))) | name = input()
str_name = str(name)
print(str_name[:3]) | 0 | null | 88,573,209,653,876 | 289 | 130 |
import sys
N,K = map(int,input().split())
array = [ I for I in map(int,input().split()) if (1 <= I <= 1000) ]
if not ( 1 <= K <= N and K <= N <= 1000 ): sys.exit()
print(sum(sorted(array)[:K])) | nk=input().split()
n=int(nk[0])
k=int(nk[1])
data=list(map(int,input().split()))
data.sort()
s=0
for i in range(k):
s += data[i]
print(s) | 1 | 11,489,922,082,080 | null | 120 | 120 |
l = int(input())
ans = 0
for i in range(l * 10 ** 3):
s = ((l * 10 ** 3 - i) / 2) ** 2
ans = max(ans, s * i / (10 ** 9))
print(ans) | HP, n = map(int, input().split())
AB = [list(map(int,input().split())) for _ in range(n)]
# DP
## DP[i]は、モンスターにダメージ量iを与えるのに必要な魔力の最小コスト
## DPの初期化
DP = [float('inf')] * (HP+1); DP[0] = 0
## HP分だけDPを回す.
for now_hp in range(HP):
## 全ての魔法について以下を試す.
for damage, cost in AB:
### 与えるダメージは、現在のダメージ量+魔法のダメージか体力の小さい方
next_hp = min(now_hp+damage, HP)
### 今の魔法で与えるダメージ量に必要な最小コストは、->
####->現在わかっている値か今のHPまでの最小コスト+今の魔法コストの小さい方
DP[next_hp] = min(DP[next_hp], DP[now_hp]+cost)
print(DP[-1]) | 0 | null | 64,087,107,101,120 | 191 | 229 |
def main():
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
dp = [[-10**18]*2, [-10**18]*2]
dp[0][0] = 0
for i in range(n):
dp2 = [[-10**18]*2, [-10**18]*2]
# 使う場合
dp2[1][0] = max(dp2[1][0], dp[0][0]+a[i])
dp2[1][1] = max(dp2[1][1], dp[0][1]+a[i])
# 使わない場合
dp2[0][1] = max(dp2[0][1], dp[0][0])
# 更新
dp2[0][0] = max(dp2[0][0], dp[1][0])
dp2[0][1] = max(dp2[0][1], dp[1][1])
dp = dp2
print(max(dp[1][1], dp[0][0]))
return
dp = [[-10**18]*3, [-10**18]*3]
dp[0][0] = 0
for i in range(n):
# 使う場合
dp2 = [[-10**18]*3, [-10**18]*3]
dp2[1][0] = max(dp2[1][0], dp[0][0]+a[i])
dp2[1][1] = max(dp2[1][1], dp[0][1]+a[i])
dp2[1][2] = max(dp2[1][2], dp[0][2]+a[i])
# 使わない場合
dp2[0][1] = max(dp2[0][1], dp[0][0])
dp2[0][2] = max(dp2[0][2], dp[0][1])
# 更新
dp2[0][0] = max(dp2[0][0], dp[1][0])
dp2[0][1] = max(dp2[0][1], dp[1][1])
dp2[0][2] = max(dp2[0][2], dp[1][2])
dp = dp2
print(max(dp[1][2], dp[0][1]))
main()
| n = int(input())
A = list(map(int, input().split()))
dp = [0] * (n+1)
dp[2] = max(A[0], A[1])
s = A[0]
for i, a in enumerate(A, 1):
if i <= 2:
continue
if i%2: # 奇数
dp[i] = max(dp[i-1], a+dp[i-2])
s += a
else: # 偶数
dp[i] = max(a+dp[i-2], s)
print(dp[-1]) | 1 | 37,540,399,301,504 | null | 177 | 177 |
n = (int)(input())
a = list(map(int, input().split(" ")))
q = (int)(input())
m = list(map(int, input().split(" ")))
lst = []
for i in range(2 ** n, 0, -1):
temp = 0
for j in range(n):
if (i >> j) & 1:
temp += a[j]
lst.append(temp)
for k in range(q):
if m[k] in lst:
print("yes")
else:
print("no")
| n=input()
print(' '.join(map(str,map(int,raw_input().split())[::-1]))) | 0 | null | 532,708,471,970 | 25 | 53 |
from collections import deque
n = int(input())
Ps = []
for _ in range(n):
lis = list(map(int, input().split()))
if len(lis)>2:
Ps.append(lis[2:])
else:
Ps.append([])
ans = [-1]*n
ans[0] = 0
queue = deque()
checked = deque()
[queue.append([p, 1]) for p in Ps[0]]
checked.append(1)
while queue:
t, pa = queue.popleft()
if not t in checked:
for i in Ps[t-1]:
queue.append([i, t])
ans[t-1] = ans[pa-1]+1
checked.append(t)
for i, a in enumerate(ans):
print(i+1, a)
| import sys
from collections import defaultdict
from queue import Queue
def main():
input = sys.stdin.buffer.readline
n = int(input())
g = defaultdict(list)
for i in range(n):
line = list(map(int, input().split()))
if line[1] > 0:
g[line[0]] = line[2:]
q = Queue()
q.put(1)
dist = [-1] * (n + 1)
dist[1] = 0
while not q.empty():
p = q.get()
for nxt in g[p]:
if dist[nxt] == -1:
dist[nxt] = dist[p] + 1
q.put(nxt)
for i in range(1, n + 1):
print(i, dist[i])
if __name__ == "__main__":
main()
| 1 | 3,711,868,524 | null | 9 | 9 |
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -10**18
for i in range(N):
now = i
visit = [False]*N
visit[now] = True
l = []
while True:
nex = P[now]-1
l.append(C[nex])
if visit[nex]:
break
visit[nex] = True
now = nex
s = sum(l)
acc = 0
for j in range(min(K, len(l))):
acc += l[j]
ans = max(ans, acc+max(0, (K-j-1)//len(l)*s))
print(ans) | 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) | 0 | null | 13,915,423,016,130 | 93 | 149 |
import sys
input = sys.stdin.readline
import numpy as np
N, M = map(int, input().split())
L = list(map(int, input().split()))
A = np.zeros(1<<18)
for i in L:
A[i] += 1
C = (np.fft.irfft(np.fft.rfft(A) * np.fft.rfft(A)) + .5).astype(np.int64)
G = C.cumsum()
count = np.searchsorted(G, N*N-M)
rest = N*N-M - G[count-1]
temp = (C[:count]*np.arange(count, dtype=np.int64)).sum() + count*rest
ans = sum(L)*2*N - temp
print(ans) | ans = list(map(int,input().split()))
print(15-sum(ans)) | 0 | null | 60,528,218,633,312 | 252 | 126 |
N = int(input())
l = []
for i in range(N+1):
if i % 5 == 0 or i % 3 == 0:
l.append(0)
else:
l.append(i)
print(sum(l)) | a,b=sorted(list(map(int, input().split())))
m=b%a
while m>=1:
b=a
a=m
m=b%a
print(a) | 0 | null | 17,414,385,695,870 | 173 | 11 |
def select(S):
for i in range(0, n):
minj = i
for j in range(i, n):
if int(S[j][1]) < int(S[minj][1]):
minj = j
(S[i], S[minj]) = (S[minj], S[i])
return S
def bubble(B):
flag = True
while flag:
flag = False
for j in reversed(range(1, n)):
if int(B[j][1]) < int(B[j-1][1]):
(B[j-1], B[j]) = (B[j], B[j-1])
flag = True
return B
def isStable(inA, out):
for i in range(0, n):
for j in range(i+1, n):
for a in range(0, n):
for b in range(a+1, n):
if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
return "Not stable"
return "Stable"
n = int(input())
A = input().split(' ')
B = bubble(A[:])
print(" ".join(B))
print(isStable(A, B))
S = select(A[:])
print(" ".join(S))
print(isStable(A, S)) | n, m = map(int, raw_input().split())
c = map(int, raw_input().split())
dp = [n+1] * (n+1)
dp[n] = 0
for rest in xrange(n, 0, -1):
for i in xrange(m):
if c[i] <= rest:
dp[rest - c[i]] = min(dp[rest - c[i]], 1 + dp[rest])
print dp[0] | 0 | null | 80,527,342,070 | 16 | 28 |
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
n = int(input())
C = input()
C_cunt = Counter(C)
cunt_r = C_cunt['R']
ans = 0
for i in range(cunt_r):
if C[i] == 'W':
ans += 1
print(ans)
if __name__=='__main__':
main() | def plus(x):
yen = 0
if x < 4:
yen = yen + 100000
if x < 3:
yen = yen + 100000
if x < 2:
yen = yen + 100000
return yen
x, y = map(int, input().split())
res = plus(x) + plus(y)
if x == 1 and y == 1:
res = res + 400000
print(res) | 0 | null | 73,161,295,593,122 | 98 | 275 |
# E - Rotation Matching
n, m = map(int, input().split())
l, r = 1, n
for i in range(m):
if 2 * (r - l) == n or 2 * (r - l + 1) == n:
l += 1
print(l, r)
l, r = l + 1, r - 1
| def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
A, B, M = getNM()
# それぞれ冷蔵庫の値段
ref_a = getList()
ref_b = getList()
# 一枚だけ使える
ticket = [getList() for i in range(M)]
ans = min(ref_a) + min(ref_b)
for i in ticket:
opt = ref_a[i[0] - 1] + ref_b[i[1] - 1] - i[2]
ans = min(ans, opt)
print(ans) | 0 | null | 41,469,133,865,992 | 162 | 200 |
#ABC156B
n,k = map(int,input().split())
ans = 0
while n > 0 :
n = n // k
ans = ans + 1
print(ans) | N,K = map(int,input().split())
tmp = 1
for i in range(1,40):
if N >= K**i:
tmp = i+1
else:
print(tmp)
break
| 1 | 63,921,292,898,980 | null | 212 | 212 |
n=int(input())
print((n*n*n)/27) | '''
@sksshivam007 - Template 1.0
'''
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
toret = {}
for tup in temp:
toret[tup[0]] = tup[1]
return toret
def sortDictWithKey(passedDic):
return dict(OrderedDict(sorted(passedDic.items())))
INF = float('inf')
mod = 10 ** 9 + 7
n, k = MAP()
a = [0]*(k+1)
for i in range(k, 0, -1):
temp = pow((k//i), n, mod)
ans = temp%mod
for j in range(2, k//i + 1):
ans -= a[j*i]%mod
a[i] = ans%mod
final = 0
for i in range(len(a)):
final+=(a[i]*i)%mod
print(final%mod) | 0 | null | 42,057,187,985,088 | 191 | 176 |
n = int(input())
d = {}
for i in range(n):
s = input()
if s in d:
d[s] += 1
else:
d[s] = 1
mx = max(d.values())
ans = ['']
for k, v in d.items():
if v == mx:
ans.append(k)
ans.sort()
print(*ans, sep='\n')
| a, b=map(int,input().split())
if a<b:
print("a < b")
elif a>b:
print("a > b")
elif a==b:
print("a == b")
else:
pass | 0 | null | 35,050,720,896,630 | 218 | 38 |
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
p_1, p_2, p_3, p_infinit = 0, 0, 0, 0
dis_list = []
for i in range(n):
dis_list.append(abs(x[i] - y[i]))
sum_d = abs(x[i] - y[i])
p_1 += sum_d
p_2 += sum_d ** 2
p_3 += sum_d ** 3
p_2 = math.sqrt(p_2)
p_3 = p_3 ** (1 / 3)
print(p_1)
print(p_2)
print(p_3)
print(max(dis_list))
| def dist(A_lst, B_lst, p):
s = 0
for a, b in zip(A_lst, B_lst):
s += abs(a - b) ** p
return s ** (1 / p)
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
print("{:.6f}".format(dist(A, B, 1)))
print("{:.6f}".format(dist(A, B, 2)))
print("{:.6f}".format(dist(A, B, 3)))
chebyshev = max(abs(a - b) for a, b in zip(A, B))
print("{:.6f}".format(chebyshev))
| 1 | 210,116,333,794 | null | 32 | 32 |
n = int(input())
for i in range(n):
nums = sorted(map(int, input().split()))
print("YES" if nums[2]**2 == nums[1]**2 + nums[0]**2 else "NO") | import sys
n = input()
for a,b,c in map(lambda x: sorted(map(int,x.split())),sys.stdin.readlines()):
print("YES" if a*a+b*b==c*c else "NO") | 1 | 297,282,300 | null | 4 | 4 |
# -*- coding: utf-8 -*-
N = int(input().strip())
XL_list = [list(map(int, input().rstrip().split())) for i in range(N)]
#-----
section = []
for X,L in XL_list:
section.append( ( X - L , X + L ) )
section.sort(key= lambda x: x[1])
prev_tail = -float("inf")
cnt = 0
for left,right in section:
if prev_tail <= left:
cnt += 1
prev_tail = right
print(cnt)
| N = int(input())
rob = []
for i in range(N):
x, l = map(int,input().split())
t = x + l
rob.append((t,x,l))
rob.sort()
Max = -float("inf")
ans = 0
for i in range(len(rob)):
t = rob[i][0]
x = rob[i][1]
l = rob[i][2]
if x-l < Max:
continue
else:
ans += 1
Max = t
print(ans) | 1 | 90,213,252,269,348 | null | 237 | 237 |
S = input()
S_inv = S[-1::-1]
counter = 0
for i in range(len(S)//2):
if S[i]!=S_inv[i]:
counter +=1
print(counter)
| s = list(input())
n = len(s)-1
count = 0
if s != s[::-1]:
for i in range(0,(n+1)//2):
if s[i] != s[n-i]:
count += 1
print(count) | 1 | 119,883,923,776,960 | null | 261 | 261 |
#!/usr/bin/env python3
import sys
from itertools import chain
MAX = 10 ** 18
def solve(N: int, A: "List[int]"):
A = sorted(A)
answer = 1
for a in A:
answer *= a
if answer > MAX:
return -1
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, A = map(int, line.split())
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(N, A)
print(answer)
if __name__ == "__main__":
main()
| str = input()
if '7' in str:
print("Yes")
else:
print("No") | 0 | null | 25,243,994,900,940 | 134 | 172 |
from collections import deque
def input_bordered_grid(h, w, wall):
grid = [wall * (w + 2)]
for _ in range(1, h+1):
grid.append(wall + input() + wall)
grid.append(wall * (w + 2))
return grid
h, w = map(int, input().split())
grid = input_bordered_grid(h, w, '#')
move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
longest = 0
for sy in range(1, h+1):
for sx in range(1, w+1):
if grid[sy][sx] == '#':
continue
dist = [[-1] * (w+2) for _ in range(h+2)]
dist[sy][sx] = 0
q = deque()
q.append((sy, sx))
while q:
y, x = q.popleft()
longest = max(longest, dist[y][x])
for dy, dx in move:
yy = y + dy
xx = x + dx
if dist[yy][xx] == -1 and grid[yy][xx] == '.':
q.append((yy, xx))
dist[yy][xx] = dist[y][x] + 1
print(longest)
| from collections import deque
import copy
H,W=map(int,input().split())
MAP=[list(input()) for y in range(H)]
def Maze(_x, _y):
MAP2=copy.deepcopy(MAP)
q=deque([[_x,_y]])
MAP2[_y][_x]=0
while q:
xy=q.popleft()
for d in [(0,-1),(-1,0),(0,1),(1,0)]:
x2,y2=xy[0]+d[0],xy[1]+d[1]
if x2<0 or y2<0 or x2>=W or y2>=H:
continue
if MAP2[y2][x2]=='.':
q.append([x2,y2])
MAP2[y2][x2]=MAP2[xy[1]][xy[0]]+1
maxM=0
for y in range(H):
for x in range(W):
if type(MAP2[y][x])==int:
maxM=max(maxM, MAP2[y][x])
return maxM
ans=0
for y in range(H):
for x in range(W):
if MAP[y][x]=='.':
ans=max(ans, Maze(x,y))
print(ans) | 1 | 94,659,837,242,880 | null | 241 | 241 |
A,B=input().split()
a=int(A)
b=B[0]+B[2]+B[3]
print(a*int(b)//100) | ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
a,b = input().split()
b = b[:-3] + b[-2:]
ans = int(a) * int(b)
ans = ans // 100
print(ans)
| 1 | 16,571,894,778,032 | null | 135 | 135 |
def main():
s = input()
if s[-1]=='s':
print(s,'es',sep='')
else:
print(s,'s',sep='')
if __name__ == "__main__":
main() | name = input()
length = len(name)
if "s" == name[length-1]:
name = name + "es"
else:
name = name + "s"
print(name) | 1 | 2,415,899,335,200 | null | 71 | 71 |
def main():
n, k = map(int, input().split())
d_lst = [0 for _ in range(k)]
a_lst = [0 for _ in range(k)]
for i in range(k):
d_lst[i] = int(input())
a_lst[i] = list(map(int, input().split()))
snuke_lst = [0 for _ in range(n)]
for i in range(k):
for a in a_lst[i]:
snuke_lst[a - 1] = 1
ans = n - sum(snuke_lst)
print(ans)
if __name__ == "__main__":
main()
| N = int(input())
array = list(map(int, input().split()))
cnt = 0
for i in range(N):
minij = i
for j in range(i, N):
if array[j] < array[minij]:
minij = j
if minij != i:
array[i], array[minij] = array[minij], array[i]
cnt += 1
print(' '.join(map(str, array)))
print( "%d" % (cnt))
| 0 | null | 12,233,615,056,700 | 154 | 15 |
def main():
N = int(input())
A = list(map(int, input().split()))
xor = 0
for a in A:
xor ^= a
ans = [xor ^ a for a in A]
print(*ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
X=I()
if X>=30:
print("Yes")
else:
print("No")
main()
| 0 | null | 9,130,008,462,816 | 123 | 95 |
global cnt
cnt = 0
def merge(A, left, mid, right):
L = A[left:mid] + [float("inf")]
R = A[mid:right] + [float("inf")]
i = 0
j = 0
global cnt
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += 1
def mergesort(A, left, right):
rsl = []
if left+1 < right:
mid = int((left+right)/2)
mergesort(A, left, mid)
mergesort(A, mid, right)
rsl = merge(A, left, mid, right)
return rsl
n = int(input())
S = list(map(int, input().split()))
mergesort(S, 0, n)
print(*S)
print(cnt)
| import bisect
N = int(input())
c = list(input())
c_sorted = sorted(c)
R_count = bisect.bisect_right(c_sorted, 'R')
ans = 0
for i in range(R_count):
if c[i] != 'R':
ans += 1
print(ans) | 0 | null | 3,208,848,261,410 | 26 | 98 |
def Euclidean(input_list):
# print input_list
x = input_list[1]
y = input_list[0]
r = x % y
if r != 0:
list = [r, y]
list.sort()
return Euclidean(list)
else:
return y
list = map(int, raw_input().split(" "))
list.sort()
print Euclidean(list) | from fractions import gcd
import sys
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
def modinv(a, mod):
return pow(a, mod - 2, mod)
n = int(input())
if n == 1:
print(1)
exit()
A = list(map(int, input().split()))
lcm = A[0]
for i in range(n):
g = gcd(lcm, A[i])
lcm *= A[i] // g
ans = 0
for i in range(n):
gyaku = modinv(A[i], mod)
ans += lcm * gyaku
ans %= mod
print(ans)
| 0 | null | 43,935,123,464,420 | 11 | 235 |
import math
a, b, x = map(int, input().split())
theta = math.atan((-2) * x / (a ** 3) + 2 * b / a)
if a * math.tan(theta) > b:
theta = math.atan2(a * b * b, 2 * x)
print(math.degrees(theta)) | import math
a,b,x = map(int,input().split())
if x >= a**2*b/2:
tan = 2*(b/a-x/(a**3))
y = math.atan(tan)
else :
tan = a*(b**2)/(2*x)
y = math.atan(tan)
print(math.degrees(y)) | 1 | 162,917,390,928,962 | null | 289 | 289 |
import numpy as np
N, K = map(int,input().split())
A = tuple(map(int,input().split()))
for p in range(1,N-K+1):
if A[K+p-1] > A[p-1]:
print("Yes")
else:
print("No") | S=input()
days=[]
day=0
for i in range(3):
if S[i]=='R':
day+=1
else:
day=0
days.append(day)
print(max(days)) | 0 | null | 6,033,543,432,228 | 102 | 90 |
x, n = list(map(int, input().split()))
q = list(map(int, input().split()))
p = [i for i in range(0, 102) if i not in q]
for i in range(len(p)):
if p[i] < x:
continue
# p[i] >= x
break
if p[i] == x:
print(p[i])
else:
if p[i] - x < x - p[i - 1]:
print(p[i])
else:
print(p[i - 1]) | import sys
# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n = ni()
a = na()
d = [0, 0, 0]
ans = 1
for ai in a:
ans *= d.count(ai)
ans %= MOD
for i in range(3):
if d[i] == ai:
d[i] += 1
break
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 72,116,979,615,482 | 128 | 268 |
def main():
import sys
from copy import deepcopy
input = sys.stdin.readline
R, C, K = [int(x) for x in input().strip().split()]
G = [[0] * (C+1) for r in range(R+1)]
for k in range(K):
r, c, v = [int(x) for x in input().strip().split()]
G[r][c] = v
# for r in range(R+1):
# print(G[r])
ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
for r in range(1, R+1):
for c in range(1, C+1):
ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
for i in range(1, 4):
ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])
print(max(ans[R%2][-1]))
if __name__ == '__main__':
main()
|
r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for _ in range(k):
ri, ci, vi = map(int, input().split())
v[ri - 1][ci - 1] = vi
dp = [[0, 0, 0, 0] for _ in range(c)]
for i in range(r):
for j in range(c):
dpj = dp[j][:]
if j == 0:
dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
else:
dp[j][0] = max(max(dpj), dp[j - 1][0])
dp[j][1] = dp[j - 1][1]
dp[j][2] = dp[j - 1][2]
dp[j][3] = dp[j - 1][3]
if v[i][j] > 0:
dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j])
print(max(dp[c - 1]))
| 1 | 5,557,678,951,726 | null | 94 | 94 |
n = int(raw_input())
minv = int(raw_input())
maxv = -1*10**9
for j in range( n-1 ):
num = int( raw_input( ) )
diff = num - minv
if maxv < diff:
maxv = diff
if num < minv:
minv = num
print maxv | n = int(input().rstrip())
R = [0 for _ in range(n)]
for i in range(n):
R[i] = int(input().rstrip())
margin = - 10**9
min_R = R[0]
for j in range(1, n):
margin = max(margin, R[j] - min_R)
min_R = min(min_R, R[j])
print(margin)
| 1 | 14,171,223,542 | null | 13 | 13 |
from collections import deque
def deque_divisor(n):
d = deque()
for i in range(int(n**(1/2)),0,-1):
if i**2 == n:
d.append(i)
continue
if n % i == 0:
d.appendleft(i)
d.append(n//i)
return d
n = int(input())
candidate = (set(deque_divisor(n)) | set(deque_divisor(n-1)))
candidate.discard(1)
ans = 0
for i in candidate:
k = n
while k % i == 0:
k //= i
k %= i
if k == 1:
ans += 1
print(ans) | #約数全列挙
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
n=int(input())
#n%k!=0
cnt=len(make_divisors(n-1))-1
#n%k==0
lst=make_divisors(n)
for k in lst:
if k!=1:
t=n
while t%k==0:
t//=k
if (t-1)%k==0:
cnt+=1
print(cnt) | 1 | 41,383,131,035,558 | null | 183 | 183 |
raw_input()
a = raw_input().split(" ")
a.reverse()
print " ".join(a) | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
n, m, k = map(int, input().split())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
aa = [0] + list(accumulate(a))
ba = [0] + list(accumulate(b))
r = 0
for i1, aae in enumerate(aa):
if aae > k:
break
else:
time_remain = k - aae
b_num = bisect(ba, time_remain)
r = max(r, i1 + b_num - 1)
print(r)
if __name__ == '__main__':
main() | 0 | null | 5,872,577,891,908 | 53 | 117 |
import math
x1,y1,x2,y2 = (float(x) for x in input().split())
print(round(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2), 8))
| import math
x1,y1,x2,y2 =map(float, input().split())
length = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print("{0:04f}".format(length)) | 1 | 156,980,985,238 | null | 29 | 29 |
inputEnzan=input().split()
def keisan(inputEnzan):
while True:
stockFornumber=[]
index=0
length=len(inputEnzan)
if length==1:
break
while index<length:
if inputEnzan[index]=="+" or inputEnzan[index]=="-" or inputEnzan[index]=="*":
if len(stockFornumber)==2:
if inputEnzan[index]=="+":
inputEnzan[index]=stockFornumber[0]+stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
elif inputEnzan[index]=="-":
inputEnzan[index]=stockFornumber[0]-stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
else:
inputEnzan[index]=stockFornumber[0]*stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
else:
stockFornumber=[]
pass
else:
if len(stockFornumber)==2:
del stockFornumber[0]
stockFornumber.append(int(inputEnzan[index]))
index+=1
while "null" in inputEnzan:
inputEnzan.remove("null")
print(inputEnzan[0])
keisan(inputEnzan)
| n,m = [int(x) for x in input().split( )]
a = [[0 for x in range(m)] for y in range(n)]
b = []
for i in range(n):
retsu = [int(x) for x in input().split( )]
a[i] = retsu
for j in range(m):
b.append(int(input()))
answer = []
for i in range(n):
value = 0
for j in range(m):
value += a[i][j]*b[j]
answer.append(value)
for ans in answer:
print(ans)
| 0 | null | 609,727,037,358 | 18 | 56 |
# 筐体の手が'k'回前と同じ場合, その回は勝てないが, 'k'回後は勝てる
# 筐体が出した各回の手をメモ, ただし'k'回前と同じ場合のみ ’-1’をメモする
# 勝ち手が'k'回前と同じ場合は加算なし, それ以外('-1'を含む)は勝ち点を加算
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = 0
memo = []
for i in range(n):
if i < k or t[i] != memo[i-k]:
memo.append(t[i])
if t[i] == 'r': ans += p
elif t[i] == 's': ans += r
else: ans += s
else:
memo.append('-1')
print(ans)
| str = input()
if len(str)%2 == 1:
print('No')
else:
for i in range(0,len(str),2):
moji = str[i:i+2]
# print(moji)
if moji != 'hi':
ans = 1
break
else:
ans = 0
if ans==1:
print('No')
else:
print('Yes') | 0 | null | 79,809,902,412,672 | 251 | 199 |
import math
a,b,C = map(float,input().split())
S = 1/2*a*b*math.sin(C*math.pi/180)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180))
L = a+b+c
h = 2*S/a
print(format(S,'.8f'))
print(format(L,'.8f'))
print(format(h,'.8f'))
| import math
def main():
a, b, ang_ab = [float(x) for x in input().split()]
rad_ab = (ang_ab/180)*math.pi
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad_ab))
h = b*math.sin(rad_ab)
s = (a*h)/2
l = a+b+c
print("{:f} {:f} {:f}".format(s, l, h))
if __name__ == '__main__':
main()
| 1 | 170,020,425,890 | null | 30 | 30 |
# -*- coding: utf-8 -*-
class dice_class:
def __init__(self, top, front, right, left, back, bottom):
self.top = top
self.front = front
self.right = right
self.left = left
self.back = back
self.bottom = bottom
def roll(self, s):
for i in s:
if i == 'E':
self.rollE()
elif i == 'N':
self.rollN()
elif i == 'S':
self.rollS()
elif i == 'W':
self.rollW()
def rollE(self):
tmp = self.top
self.top = self.left
self.left = self.bottom
self.bottom = self.right
self.right = tmp
def rollN(self):
tmp = self.top
self.top = self.front
self.front = self.bottom
self.bottom = self.back
self.back = tmp
def rollS(self):
tmp = self.top
self.top = self.back
self.back = self.bottom
self.bottom = self.front
self.front = tmp
def rollW(self):
tmp = self.top
self.top = self.right
self.right = self.bottom
self.bottom = self.left
self.left = tmp
if __name__ == "__main__":
a = map(int, raw_input().split())
s = str(raw_input())
dice = dice_class(a[0], a[1], a[2], a[3], a[4], a[5])
dice.roll(s)
print dice.top | c = {"N": (1, 5, 2, 3, 0, 4), "S": (4, 0, 2, 3, 5, 1), "E": (3, 1, 0, 5, 4, 2), "W": (2, 1, 5, 0, 4, 3)}
d = list(map(int, input().split()))
for x in input():
d = [d[y] for y in c[x]]
print(d[0])
| 1 | 233,808,895,940 | null | 33 | 33 |
N=int(input())
S = [0]*N
for i in range(N):
S[i]=str(input())
print('AC x {0}'.format(S.count('AC')))
print('WA x {0}'.format(S.count('WA')))
print('TLE x {0}'.format(S.count('TLE')))
print('RE x {0}'.format(S.count('RE'))) | #!/usr/bin/env python
letters = []
for i in range(26):
letters.append(chr(i + 97) + " : ")
contents = []
while True:
try:
text = input()
except EOFError:
break
contents.append(text)
#65-90 uppercase
#97-122lowercase
i = 0
for y in letters:
value = 0
for text in contents:
for x in text:
if x.isupper():
x = x.lower()
if x in y:
value += 1
elif x.islower():
if x in y:
value += 1
letters[i] = letters[i] + str(value)
i += 1
for x in letters:
print(x) | 0 | null | 5,190,079,468,860 | 109 | 63 |
import sys
for i in sys.stdin.readlines():
a,b = map(int,i.split())
print len(str(a+b)) | N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in L:
for j in L:
for k in L:
if i < j < k:
if i + j + k > max(i,j,k) * 2:
ans += 1
else:
print(ans) | 0 | null | 2,550,627,534,400 | 3 | 91 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.