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
|
---|---|---|---|---|---|---|
ans = ''
r, c = map(int, input().split(' '))
i = 0
L = [0] * (c + 1)
while i < r:
a = list(map(int, input().split(' ')))
atot = 0
j = 0
while j < c:
atot += a[j]
L[j] += a[j]
j += 1
ans += ' '.join(map(str, a)) + ' ' + str(atot) + '\n'
L[c] += atot
i += 1
if ans != '':
ans += ' '.join(map(str, L))
print(ans)
| r,c = map(int,input().split())
a = [list(map(int,input().split(" "))) for i in range(r)]
for i in range(r):
r_total = sum(a[i])
a[i].append(r_total)
c_total = []
for j in range(c+1):
s = 0
for k in range(r):
s += a[k][j]
c_total.append(s)
a.append(c_total)
for z in range(r+1):
for w in range(c+1):
print(a[z][w],end="")
if w != c:
print(" ",end="")
print() | 1 | 1,355,296,579,648 | null | 59 | 59 |
r=int(input())
print(2*3.14*r) |
R=int(input())
print((R*2)*3.14) | 1 | 31,216,363,562,020 | null | 167 | 167 |
import math
r = int(input())
R = 2*math.pi*r
print(R) | m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
end = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if d1 == end[m1-1]:
print(1)
else:
print(0) | 0 | null | 77,993,646,042,960 | 167 | 264 |
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(m):
ans += a[i]
if n < ans:
print(-1)
else:
print(n-ans) | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, m, *a = map(int, read().split())
suma = sum(a)
if n < suma:
print(-1)
else:
print(n - suma)
if __name__ == '__main__':
main()
| 1 | 31,834,895,207,310 | null | 168 | 168 |
input()
P=map(int,input().split())
ans,mn=0,2*10**5
for x in P:
if mn>=x: ans+=1; mn=x
print(ans)
| N = int(input())
P = list(map(int, input().split()))
mi = 202020
ans = 0
for p in P:
if p < mi:
ans += 1
mi = p
print(ans)
| 1 | 85,441,724,057,228 | null | 233 | 233 |
S=input()
ans=0
if 'R' in S:
ans+=1
for i in range(2):
if S[i]==S[i+1]=='R':
ans+=1
print(ans) | s = input()
ans = 0
strek = 0
for i in range(3):
if s[i] == 'R':
tmp = "R"
strek += 1
ans = max(strek, ans)
else:
strek = 0
print(ans) | 1 | 4,899,000,489,280 | null | 90 | 90 |
from collections import deque
def dfs(q):
if len(q)==N:
print(''.join(q))
return
for i in range(min(26, ord(max(q))-ord('a')+2)):
q.append(alpha[i])
dfs(q)
q.pop()
N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a'])) | N = int(input())
s = "a"
ans = []
def dfs(s,n):
if len(s) == n:
ans.append(s)
return
last = 0
for i in range(len(s)):
last = max(last,ord(s[i]))
limit = chr(last+1)
for i in range(26):
temp = chr(97+i)
if temp <= limit:
dfs(s+temp,n)
dfs(s,N)
print(*ans,sep="\n") | 1 | 52,073,989,355,612 | null | 198 | 198 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
while y: x,y = y,x%y
return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
"""Return a tuple list of divisor of n"""
return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True]*(MAX_NUM+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX_NUM**0.5)+1):
if not is_prime[i]: continue
for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
"""Return a list of prime factorization numbers of n"""
res = []
for i in range(2,int(n**0.5)+1):
while n%i==0: res.append(i); n //= i
if n != 1: res.append(n)
return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
n = II()
xl = [MII() for _ in range(n)]
lr_x = [[x-l, x+l] for x, l in xl]
lr_x.sort(key=lambda x: x[1])
now = -(10**9)
cnt = 0
for l, r in lr_x:
if now <= l:
cnt += 1
now = r
print(cnt)
if __name__ == '__main__':
main() | def main():
N, M = map(int, input().split())
if N == M:
print("Yes")
exit(0)
print("No")
if __name__ == "__main__":
main()
| 0 | null | 86,570,895,458,500 | 237 | 231 |
n,k,s = map(int,input().split())
if s == 10**9:
t = 1
else:
t = s+1
ls = [t]*n
for i in range(k):
ls[i] = s
print(*ls) | n,k,s = map(int,input().split())
if s == 10**9:
ans = [1]*n
for i in range(k):
ans [i] = s
else:
ans = [s+1]*n
for i in range(k):
ans[i] = s
for i in ans:
print(i,end = " ")
| 1 | 90,773,326,866,002 | null | 238 | 238 |
danmen = input()
down = []
edge = []
pool = []
for (i, line) in enumerate(danmen):
if line == "\\":
down.append(i)
elif down and line == "/":
left = down.pop()
area = i - left
while edge:
if edge[-1] > left:
edge.pop()
area += pool.pop()
else:
break
edge.append(left)
pool.append(area)
print(sum(pool))
print(len(pool), *pool) | N=int(input())
x=input()
num=0
n=0
def twice(a):
ans=0
while a:
ans+=a%2
a//=2
return ans
ma=5*10**5
dp=[0]*ma
for i in range(1,ma):
dp[i]=dp[i%twice(i)]+1
c=x.count("1")
a=int(x,2)%(c+1)
if c==1:
for i in range(N):
if x[i]=="0":
print(dp[(a+pow(2,N-i-1,2))%2]+1)
else:
print(0)
exit()
b=int(x,2)%(c-1)
for i in range(N):
if x[i]=="0":
print(dp[(a+pow(2,N-i-1,c+1))%(c+1)]+1)
else:
print(dp[(b-pow(2,N-i-1,c-1))%(c-1)]+1) | 0 | null | 4,189,993,019,672 | 21 | 107 |
def north(d):
d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
def west(d):
d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]
def east(d):
d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]
def south(d):
d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]
F = {'N': north, 'W': west, 'E': east, 'S': south}
d, os = list(map(int, input().split())), input()
for o in os:
F[o](d)
print(d[0]) | S = input()
s = S[::-1]
cnt = [0]*2019
cnt[0] = 1
number = 0
d = 1
for i in s:
number += int(i)*d
cnt[number % 2019] += 1
d *= 10
d = d % 2019
ans = 0
for i in cnt:
ans += i*(i-1) // 2
print(ans) | 0 | null | 15,452,136,311,318 | 33 | 166 |
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)) | hei = int(input())
wei = int(input())
n = int(input())
kuro =0
count = 0
if hei > wei:
data = hei
else:
data = wei
while kuro<n:
kuro +=data
count +=1
print(count) | 0 | null | 125,871,504,878,658 | 289 | 236 |
# C
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
countS = Counter(S)
maxS = max(countS.values())
ans = []
for key,value in countS.items():
if value == maxS:
ans.append(key)
for a in sorted(ans):
print(a)
| from collections import Counter
n = int(input())
d = list(input() for _ in range(n))
D = Counter(d)
m = max(D.values())
l = []
for i,j in D.most_common():
if m != j:
break
l.append(i)
l.sort()
for i in l:
print(i) | 1 | 69,954,054,218,474 | null | 218 | 218 |
X=list(map(int,input().split()))
for i in range(0,5):
if X[i]==0:
print(i+1)
break
| a,b = list(map(int,input().split()))
print("%d %d %f" % ((a//b),(a%b),float((a/b)))) | 0 | null | 7,033,151,765,724 | 126 | 45 |
# 数字を取得
N = int(input())
# 数値分ループ
calc = []
for cnt in range(1, N + 1):
# 3もしくは5の倍数であれば、加算しない
if cnt % 3 != 0 and cnt % 5 != 0:
calc.append(cnt)
# 合計を出力
print(sum(calc)) | N = int(input())
SUM = 0
for i in range(1, N + 1):
if i % 3 != 0:
if i % 5 != 0:
SUM += i
print(SUM) | 1 | 34,927,375,381,238 | null | 173 | 173 |
import math
s = input()
print(s[:3]) | a = input()
print(a[0] + a[1] + a[2]) | 1 | 14,873,170,770,940 | null | 130 | 130 |
def main():
s, t = input().split(' ')
print(t, end='')
print(s)
if __name__ == '__main__':
main()
| N, K = map(int, input().split())
mod = 10**9 + 7
fact_count = [0 for _ in range(K+1)]
for k in range(1, K+1):
fact_count[k] = K//k
ans = 0
count = [0 for _ in range(K+1)]
for k in range(K, 0, -1):
c = pow(fact_count[k], N, mod)
j = 2*k
l = 2
while(j<=K):
c -= count[j]
l += 1
j = k*l
count[k] = c
c = c*k%mod
ans += c
ans %= mod
print(ans)
| 0 | null | 69,888,520,518,080 | 248 | 176 |
MOD = 1e9 + 7
n = int(input())
ans = [[0, 1, 1, 8]]
for i in range(n-1):
a, b, c, d = ans.pop()
a = (a * 10 + b + c) % MOD
b = (b * 9 + d) % MOD
c = (c * 9 + d) % MOD
d = (d * 8) % MOD
ans.append([a, b, c, d])
a, b, c, d = ans.pop()
print(int(a)) | from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())
INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7
def main():
n = int(rl())
x = pow(10, n, MOD) - 2*pow(9, n, MOD) + pow(8, n, MOD)
print(x % MOD)
stdout.close()
if __name__ == "__main__":
main() | 1 | 3,136,787,307,694 | null | 78 | 78 |
n = int(input())
a = list(map(int, input().split()))
a = [(i, j) for i, j in enumerate(a, start=1)]
a.sort(key=lambda x: x[1])
a = [str(i) for i, j in a]
print(' '.join(a)) | import bisect
import sys
input = sys.stdin.readline
n,d,a= map(int, input().split())
x= [list(map(int, input().split())) for i in range(n)]
x.sort()
y=[]
for i in range(n):
y.append(x[i][0])
x[i][1]=-(-x[i][1]//a)
# どのモンスターまで倒したか管理しながら進める。
ans=0
# いつ効力が切れるか記録
z=[0]*(n+1)
# 今の攻撃力
atk=0
for i in range(n):
atk+=z[i]
if x[i][1]-atk>0:
ans+=x[i][1]-atk
q=bisect.bisect_right(y,x[i][0]+2*d,i,n)
z[q]-=x[i][1]-atk
atk+=x[i][1]-atk
print(ans) | 0 | null | 131,087,040,987,450 | 299 | 230 |
N, M = map(int,input().split())
ans = []
if N %2 == 0:
L1 = list(range(1,N//2+1))
L2 = list(range(N//2+1,N+1))
L = len(L1)
i = 0
j = 0
# print(L)
for m in range(M):
if m %2 == 0:
ans.append([L1[L//2-1-i],L1[L//2+i]])
i += 1
else:
ans.append([L2[L//2-1-j], L2[L//2+1+j]])
j += 1
else:
for i in range(1,M+1):
ans.append([i,N+1-i])
for a in ans:
print(*a) | import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: 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)]
INF = float('inf')
def solve():
s, w = MI()
if w >= s:
print('unsafe')
else:
print('safe')
if __name__ == '__main__':
solve()
| 0 | null | 28,918,274,821,746 | 162 | 163 |
n = int(input())
d = input()
x = d[0]
count = 1
for i in d:
if i != x:
count += 1
x = i
print(count) | n = int(input())
s = input()
res = 1
for i in range(n-1):
if s[i] != s[i+1]:
res += 1
print(res) | 1 | 170,495,820,973,918 | null | 293 | 293 |
def main():
d,t,s = map(int, input().split())
if s*t >= d:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| import sys
# A - Don't be late
D, T, S = map(int, input().split())
if S * T >= D:
print('Yes')
else:
print('No') | 1 | 3,607,194,949,560 | null | 81 | 81 |
N = input()
R = [int(raw_input()) for _ in xrange(N)]
S = [0 for i in xrange(N)]
S[N-1] = R[N-1]
for i in xrange(N-2, -1, -1):
S[i] = max(R[i], S[i+1])
ans = float('-inf')
for i in xrange(N-1):
ans = max(ans, S[i+1]-R[i])
print ans | n = input()
maxv = - 1 * pow(10, 9)
minv = input()
for _ in xrange(1, n):
Rj = input()
maxv = max(maxv, Rj - minv)
minv = min(minv, Rj)
print maxv | 1 | 14,151,636,598 | null | 13 | 13 |
import math
r = input()
l = 2 * math.pi * float(r)
s = math.pi * float(r) * float(r)
print("%f %f" % (s, l)) | print(['win','bust'][sum(list(map(int,input().split())))>=22]) | 0 | null | 60,041,078,756,852 | 46 | 260 |
H,W = map(int,input().split())
if H ==1 or W ==1:
print(1)
else:
a = H*W
if a%2 == 0:
print(int(a/2))
else:
print(int(a/2)+1) | if __name__ == '__main__':
N, M = map(int, input().split())
S = []
C = []
for i in range(M):
s, c = map(int, input().split())
s -= 1
S.append(s)
C.append(c)
for num in range(0, pow(10, N)):
st_num = str(num)
if len(str(st_num))!=N: continue
cnt = 0
for m in range(M):
if int(st_num[S[m]])==C[m]:
cnt += 1
if cnt==M:
print(st_num)
quit()
print(-1)
| 0 | null | 55,750,875,016,892 | 196 | 208 |
import math
import itertools
n = int(input())
k = int(input())
f = len(str(n))
if f < k:
print(0)
else:
#f-1桁以内に収まる数
en = 1
for i in range(k):
en *= f-1-i
de = math.factorial(k)
s = en // de * pow(9, k)
#f桁目によって絞る
kami = int(str(n)[0])
en = 1
for i in range(k-1):
en *= f-1-i
de = math.factorial(k-1)
s += (en // de * pow(9, k-1)) * (kami-1)
#以下上1桁は同じ数字
keta = list(range(f-1))
num = list(range(1,10))
b = kami * pow(10, f-1)
m = 0
if k == 1:
m = b
if m <= n:
s += 1
else:
for d in itertools.product(num, repeat=k-1):
for c in itertools.combinations(keta, k-1):
m = b
for i in range(k-1):
m += d[i] * pow(10, c[i])
if m <= n:
s += 1
print(s)
| def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#inf = 10**17
#mod = 10**9 + 7
n = input().rstrip()
k = int(input())
ln = len(n)
# dp[i][j]:左からi桁まで見たとき0でない桁がj個ある場合の数
dp1 = [[0]*(k+1) for _ in range(ln+1)]
dp2 = [[0]*(k+1) for _ in range(ln+1)]
dp2[0][0] = 1
cnt = 0
for i in range(ln):
if n[i] != '0':
if cnt < k:
cnt += 1
dp2[i+1][cnt] = 1
else:
dp2[i+1][cnt] = dp2[i][cnt]
for i in range(ln):
dp1[i+1][0] = 1
for j in range(1, k+1):
dp1[i+1][j] += dp1[i][j] + dp1[i][j-1] * 9
if n[i] != '0':
dp1[i+1][j] += dp2[i][j-1] * (int(n[i])-1)
if j < k:
dp1[i+1][j] += dp2[i][j]
print(dp1[-1][k] + dp2[-1][k])
if __name__ == '__main__':
main() | 1 | 76,069,813,268,640 | null | 224 | 224 |
from sys import stdin, setrecursionlimit
def main():
n = int(stdin.readline())
print(n // 2) if n % 2 == 0 else print((n + 1) // 2)
if __name__ == "__main__":
setrecursionlimit(10000)
main() | from collections import deque
u = int(input())
g = [[i for i in map(int, input().split())] for _ in range(u)]
graph = [[] for _ in range(u)]
ans = [-1] * u
for i in range(u):
for j in range(g[i][1]):
graph[i].append(g[i][2 + j] - 1)
que = deque()
que.append(0)
ans[0] = 0
while que:
v = que.popleft()
for nv in graph[v]:
if ans[nv] != -1:
continue
ans[nv] = ans[v] + 1
que.append(nv)
for i in range(u):
print(i+1, ans[i])
| 0 | null | 29,704,100,996,570 | 206 | 9 |
def az16():
list = []
n = input()
for i in range(0,n):
list.append(raw_input().split())
for mark in ["S","H","C","D"]:
for i in range(1,14):
if [mark,repr(i)] not in list:
print mark,i
az16() | all_set = ['S ' + str(i) for i in range(1, 14)] + ['H ' + str(i) for i in range(1, 14)] + ['C ' + str(i) for i in range(1, 14)] + ['D ' + str(i) for i in range(1, 14)]
r = int(input())
for _ in range(r):
x = input()
if x in all_set:
del all_set[all_set.index(x)]
for i in all_set:
print(i)
| 1 | 1,037,499,094,660 | null | 54 | 54 |
l,r,n = map(int,input().split(" "))
count = 0
for i in range(l,r+1):
if i % n == 0:
count += 1
print(count)
| l,R, d = map(int, input().split())
a =0
for i in range(l,R+1):
if i % d == 0:
a = a+1
print(a)
| 1 | 7,630,868,875,604 | null | 104 | 104 |
h,n=map(int,input().split())
l=list(map(int,input().split()))
a=0
for i in range(n):
a+=l[i]
if a>=h:
print("Yes")
else:
print("No") | T1,T2,A1,A2,B1,B2=map(int, open(0).read().split())
C1,C2=A1-B1,A2-B2
if C1<0: C1,C2=-C1,-C2
Y1=C1*T1
Y2=Y1+C2*T2
if Y2>0:
print(0)
elif Y2==0:
print("infinity")
else:
print(1+Y1//(-Y2)*2-(Y1%(-Y2)==0)) | 0 | null | 104,741,572,274,872 | 226 | 269 |
def count(s1, s2):
dst = 0
for c1, c2 in zip(s1, s2):
if c1 != c2: dst+=1
return dst
def execute(S, T):
dst = len(T)
for i in range(len(S) - len(T)+1):
s = S[i:i+len(T)]
c = count(s, T)
if c < dst:
dst = c
return dst
if __name__ == '__main__':
S = input()
T = input()
print(execute(S, T)) | S,T=input().split()
A,B=map(int,input().split())
U=input()
if(U==S):
print("{}".format(A-1)+" {}".format(B))
else:
print("{}".format(A)+" {}".format(B-1)) | 0 | null | 37,874,265,770,924 | 82 | 220 |
import sys
n = int(input())
dic =set()
t = sys.stdin.readlines()
for i in t:
i,op = i.split()
if i == 'insert':
dic.add(op)
else:
if op in dic:
print('yes')
else:
print('no') | import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = np.array(input().split(), dtype=np.int64)
total = 0
for shamt in range(65):
bits = np.count_nonzero(A & 1)
total += (bits * (N - bits)) << shamt
A >>= 1
if not A.any():
break
print(total % MOD) | 0 | null | 61,776,346,718,678 | 23 | 263 |
S = int(input())
dp = [0] * (S + 1)
dp[0] = 1
M = 10 ** 9 + 7
for i in range(1, S + 1):
num = 0
for j in range(i - 2):
num += dp[j]
dp[i] = num % M
print(dp[S])
| S = int(input())
p = 10**9 +7
def pow_mod(p,a,n):
res = 1
while n > 0:
if n % 2 == 1:
res = (res * a) % p
n = n // 2
a = (a*a)%p
return res
n = 2000
fac = [1]
foo = 1
for i in range(1,n+1):
foo = (foo*i)%p
fac.append(foo)
#コンビネーションのmod
def comb_mod(n,k):
res = (fac[n] * pow_mod(p,fac[k],p-2) * pow_mod(p,fac[n-k],p-2)) % p
return res
ans = 0
for i in range(1,1+S//3):
t = S - 3*i
ans = (ans + comb_mod(t+i-1,t)) %p
print(ans) | 1 | 3,276,156,512,608 | null | 79 | 79 |
# from sys import stdin
# input = stdin.readline
from collections import Counter
def solve():
x,n = map(int,input().split())
if n != 0:
p = set(map(int,input().split()))
if n == 0 or x not in p:
print(x)
return
else:
for i in range(100):
if x - i not in p:
print(x - i)
return
if x + i not in p:
print(x + i)
return
if __name__ == '__main__':
solve()
| n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
h.reverse()
if k>n:
k=n
for i in range (k):
h[i] = 0
print(sum(h)) | 0 | null | 46,278,116,005,702 | 128 | 227 |
n=int(input())
s=input().split()
q=int(input())
t=input().split()
cnt=0
for i in range(q):
for j in range(n):
if s[j]==t[i]:
cnt+=1
break
print(cnt)
| def main():
D = int(input())
c = list(map(int,input().split()))
s = []
for d in range(D):
s.append(list(map(int,input().split())))
t = []
for d in range(D):
t.append(int(input())-1)
last = [0 for i in range(26)]
v = 0
for d in range(D):
v += s[d][t[d]]
last[t[d]] = d+1
for i in range(26):
v -= c[i]*(d+1-last[i])
print(v)
if __name__ == '__main__':
main() | 0 | null | 4,962,843,967,972 | 22 | 114 |
while True:
h, w = map(int, input().split())
if w+h == 0:
break
line = "#"*w
for y in range(h):
print(line)
print()
| while True:
H, W = map(int, input().split())
if (H, W) == (0, 0):
break
[print("#"*W+"\n") if i == H-1 else print("#"*W) for i in range(H)] | 1 | 774,441,783,204 | null | 49 | 49 |
import math
pi=math.pi
def rtod(rad):
return 180/pi*rad
a,b,x=map(int,input().split())
if b/2<x/a**2:
ans=2*(a**2*b-x)/a**3
ans=math.atan(ans)
print(rtod(ans))
else:
ans=b**2/(2*x)*a
ans=math.atan(ans)
print(rtod(ans))
| ans = 100000
n = int(raw_input())
for i in xrange(n):
ans *= 1.05
ans = int((ans+999)/1000)*1000;
print ans | 0 | null | 81,419,729,915,950 | 289 | 6 |
from collections import deque
import copy
H, W = map(int, input().split())
S = [input() for _ in range(H)]
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(H*W):
for i in range(H*W):
for j in range(H*W):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
d = [[float("inf")]*(H*W) for i in range(H*W)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H-1):
for j in range(W-1):
if S[i][j] == ".":
if S[i+1][j] == ".":
d[i*W+j][(i+1)*W+j] = 1
d[(i+1)*W+j][i*W+j] = 1
if S[i][j+1] == ".":
d[i*W+j][i*W+(j+1)] = 1
d[i*W+(j+1)][i*W+j] = 1
for i in range(W-1):
if S[H-1][i] == "." and S[H-1][i+1] == ".":
d[(H-1)*W+i][(H-1)*W+(i+1)] = 1
d[(H-1)*W+(i+1)][(H-1)*W+i] = 1
for i in range(H-1):
if S[i][W-1] == "." and S[i+1][W-1] == ".":
d[i*W+(W-1)][(i+1)*W+(W-1)] = 1
d[(i+1)*W+(W-1)][i*W+(W-1)] = 1
for i in range(H*W):
d[i][i] = 0 #自身のところに行くコストは0
ans = 0
data = warshall_floyd(d)
for items in data:
for item in items:
if item != float("inf"):
ans = max(ans, item)
print(ans)
| a,b = input().split()
a = int(a)
b = int(b)
d = a // b
r = a % b
f = a / b
f = "{0:.8f}".format(f)
fmt = "{v} {c} {n}"
s = fmt.format(v = d,c = r,n = f)
print(s) | 0 | null | 47,817,765,081,850 | 241 | 45 |
n = int(input())
l = list(map(int, input().split()))
sum = 0
for i in range(n):
sum += l[i]
print(min(l), max(l), sum)
| N=int(input())
D=[map(int, input().split()) for i in range(N)]
x, y = [list(i) for i in zip(*D)]
s=0
l=[]
for i in range(N):
if x[i]==y[i]:
s+=1
if i==N-1:
l.append(s)
elif x[i]!=y[i]:
l.append(s)
s=0
if max(l)>=3:
print("Yes")
else:
print("No") | 0 | null | 1,594,015,207,100 | 48 | 72 |
from scipy import misc
N = int(input())
K = int(input())
d = len(str(N))
first = int(str(N)[0])
if K == 1:
print(9*(d-1)+first)
elif K == 2:
if d == 1:
print('0')
else:
for i in range(1,d):
if str(N)[i] != '0':
second_dig = i+1
second_num = int(str(N)[i])
break
else:
second_dig = d
second_num = 0
print(((d-1)*(d-2)//2*81)+(first-1)*(d-1)*9+(d-second_dig)*9+second_num)
else:
if K < 3:
print('0')
else:
found_second = False
found_third = False
for i in range(1,d):
if str(N)[i] != '0':
if found_second == False:
second_dig = i+1
second_num = int(str(N)[i])
found_second = True
else:
third_dig = i+1
third_num = int(str(N)[i])
found_third = True
break
if found_second == False:
print((d-1)*(d-2)*(d-3)//6*729+(first-1)*((d-1)*(d-2)//2*81))
elif found_third == False:
print((d-1)*(d-2)*(d-3)//6*729+(first-1)*((d-1)*(d-2)//2*81)+(second_num-1)*(d-second_dig)*9+(d-second_dig)*(d-second_dig-1)//2*81)
else:
print((d-1)*(d-2)*(d-3)//6*729+(first-1)*((d-1)*(d-2)//2*81)+(second_num-1)*(d-second_dig)*9+(d-second_dig)*(d-second_dig-1)//2*81+(d-third_dig)*9+third_num) | N = input()
K = int(input())
L = len(N)
dp = [[[0 for j in range(L + 10)] for i in range(L + 10)] for _ in range(2)]
dp[0][0][0] = 1
for i in range(L):
Ni = int(N[i])
for j in range(L):
if Ni == 0:
dp[0][i + 1][j + 0] += dp[0][i][j + 0] * 1
dp[0][i + 1][j + 1] += dp[0][i][j + 0] * 0
dp[1][i + 1][j + 0] += dp[0][i][j + 0] * 0 + dp[1][i][j + 0] * 1
dp[1][i + 1][j + 1] += dp[0][i][j + 0] * 0 + dp[1][i][j + 0] * 9
else:
dp[0][i + 1][j + 0] += dp[0][i][j + 0] * 0
dp[0][i + 1][j + 1] += dp[0][i][j + 0] * 1
dp[1][i + 1][j + 0] += dp[0][i][j + 0] * 1 + dp[1][i][j + 0] * 1
dp[1][i + 1][j + 1] += dp[0][i][j + 0] * (Ni - 1) + dp[1][i][j + 0] * 9
#print(dp[0])
#print(dp[1])
print(dp[0][L][K] + dp[1][L][K]) | 1 | 76,015,539,217,312 | null | 224 | 224 |
n, k = map( int, input().split() )
r, s, p = map( int, input().split() )
t = str( input() )
t_list = [ c for c in t ]
for i in range( k, n ):
if t_list[ i ] == t_list[ i - k ]:
t_list[ i ] = "x"
score = 0
for hand in t_list:
if hand == "r":
score += p
elif hand == "s":
score += r
elif hand == "p":
score += s
print( score ) | l, r, d = map(int, input().split())
result=0
for i in range(r-l+1):
if (l+i) % d == 0:
result+=1
print(result)
| 0 | null | 57,255,544,348,100 | 251 | 104 |
hei = int(input())
wei = int(input())
n = int(input())
kuro =0
count = 0
if hei > wei:
data = hei
else:
data = wei
while kuro<n:
kuro +=data
count +=1
print(count) | import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
x = gete(int)
print('Yes' if x >= 30 else 'No')
if __name__ == "__main__":
main() | 0 | null | 47,336,391,164,320 | 236 | 95 |
import sys
input_num = int(sys.stdin.readline())
ans = ''
for i in range(3, input_num + 1):
if i % 3 == 0 or '3' in str(i):
ans += ' ' + str(i)
print ans | #!/usr/bin/env python3
from collections import Counter
def main():
S = input()
N = len(S)
T = [0] * (N+1)
for i in range(N-1,-1,-1):
T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019
l = Counter(T)
ans = 0
for v in l.values():
ans += v * (v-1) // 2
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 15,793,531,084,844 | 52 | 166 |
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def lcm(x,y):
return x*y//gcd(x,y)
def lgcd(l):
return reduce(gcd,l)
def llcm(l):
return reduce(lcm,l)
def powmod(n,i,mod):
return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
return x.bit_length()
def div10(x):
return len(str(x))-(x==0)
def intput():
return int(input())
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def ilint():
return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
def ston(c, c0='a'):
return ord(c)-ord(c0)
def ntos(x, c0='a'):
return chr(x+ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self,x,d=1):
self.setdefault(x,0)
self[x] += d
def list(self):
l = []
for k in self:
l.extend([k]*self[k])
return l
class comb():
def __init__(self, n, mod=None):
self.l = [1]
self.n = n
self.mod = mod
def get(self,k):
l,n,mod = self.l, self.n, self.mod
k = n-k if k>n//2 else k
while len(l)<=k:
i = len(l)
l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
return l[k]
def pf(x):
C = counter()
p = 2
while x>1:
k = 0
while x%p==0:
x //= p
k += 1
if k>0:
C.add(p,k)
p = p+2-(p==2) if p*p<x else x
return C
X,Y=mint()
if (X+Y)%3!=0:
print(0)
exit()
k=abs(X-Y)
N=min(X,Y)-k
if N<0:
print(0)
exit()
n=2*(N//3)+k
C=comb(n,MOD)
print(C.get(N//3)) | while True :
a = raw_input().split()
x = int(a[0])
y = int(a[1])
if x == 0 and y == 0 :
break
elif x < y :
print u"%d %d" % (x, y)
else :
print u"%d %d" % (y, x) | 0 | null | 75,515,893,197,832 | 281 | 43 |
#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())
ans = 1
while(True):
n = n//k
if(n == 0):
break
ans += 1
print(ans) | 1 | 64,066,591,119,076 | null | 212 | 212 |
a=input()
n=int(input())
for i in range(n):
b=input().split()
if b[0]=='print':
print(a[int(b[1]):int(b[2])+1])
elif b[0]=='replace':
a=a[:int(b[1])]+b[3]+a[int(b[2])+1:]
elif b[0]=='reverse':
c=(a[int(b[1]):int(b[2])+1])
c=c[::-1]
a=a[:int(b[1])]+c+a[int(b[2])+1:]
| s=input()
for i in range(int(input())):
sou_com=input().split()
if sou_com[0]=='print':
print(s[int(sou_com[1]):int(sou_com[2])+1])
elif sou_com[0]=='reverse':
s=s[:int(sou_com[1])]\
+s[int(sou_com[1]):int(sou_com[2])+1][::-1]\
+s[int(sou_com[2])+1:]
elif sou_com[0]=='replace':
s=s[:int(sou_com[1])]\
+sou_com[3]\
+s[int(sou_com[2])+1:] | 1 | 2,083,847,752,850 | null | 68 | 68 |
#coding:UTF-8
n = map(int,raw_input().split())
n.sort()
print n[0],n[1],n[2] | a,b,c = map(int, input().split())
A = min(min(a, b),c)
C = max(max(a,b),c)
B = (a+b+c) - (A+C)
print(A, B, C)
| 1 | 421,508,246,918 | null | 40 | 40 |
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()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
def segfunc(x, y):
return min(x, y)
ide_ele = float('inf')
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
# 最短手数k回でクリアできるとすると、
# 1 ~ M の内1つをk回選んで合計をNにする
N, M = getNM()
S = input()
trap = set()
for i in range(len(S)):
if S[i] == '1':
trap.add(i)
# これABC011 123引き算と同じでは
# 案1 dpを使う
# dp[i]: iマスに止まる時の最短手順
# dp[i]の時 dp[i + 1] ~ dp[i + M]についてmin(dp[i] + 1, dp[i + j])を見ていく
# 決まったらdpを前から見ていき最短手順がdp[i] - 1になるものを探す(辞書順)
# → M <= 10 ** 5より多分無理
# セグ木使えばいける?
# dp[i] = dp[i - M] ~ dp[i - 1]の最小値 + 1
# dp[i - M] ~ dp[i - 1]の最小値はlogNで求められるので全体でNlogN
dp = [float('inf')] * (N + 1)
dp[0] = 0
seg = SegTree([float('inf')] * (N + 1), segfunc, ide_ele)
seg.update(0, 0)
# dp[i]をレコード
for i in range(1, N + 1):
# もしドボンマスなら飛ばす(float('inf')のまま)
if i in trap:
continue
# dp[i - M] ~ dp[i - 1]の最小値をサーチ
min_t = seg.query(max(0, i - M), i)
seg.update(i, min_t + 1)
dp[i] = min_t + 1
# goalに到達できないなら
if dp[-1] == float('inf'):
print(-1)
exit()
# 何回の試行で到達できるかをグルーピング
dis = [[] for i in range(dp[-1] + 1)]
for i in range(len(dp)):
if dp[i] == float('inf'):
continue
dis[dp[i]].append(i)
# ゴールから巻き戻っていく
now = dp[-1]
now_index = N
ans = []
# 辞書順で1 4 4 < 3 3 3なので
# 一番前にできるだけ小さい数が来るようにする
for i in range(now, 0, -1):
# dp[i] - 1回で到達できる
# 現在地点からMマス以内
# で最も現在地点から遠いところが1つ前のマス
index = bisect_left(dis[i - 1], now_index - M)
# サイコロの目を決める
ans.append(now_index - dis[i - 1][index])
# 現在地点更新
now_index = dis[i - 1][index]
for i in ans[::-1]:
print(i) | import sys
N, M = map(int, input().split())
S = input()
tmp = 0
for i in range(N+1):
if S[i] == '1':
tmp += 1
if tmp == M:
print(-1)
sys.exit()
else:
tmp = 0
ans = []
i = N
while i > M:
ind = S[i-M:i].find('0')
ans.append(M-ind)
i -= M - ind
ans.append(i)
print(*ans[::-1]) | 1 | 139,330,320,746,948 | null | 274 | 274 |
# -*- coding: utf-8 -*-
import functools
@functools.lru_cache(maxsize=None)
def fib(n):
if n <= 1:
return 1
else:
return fib(n - 1) + fib(n - 2)
if __name__ == '__main__':
n = int(input())
print(fib(n))
| D=int(input())
c=[int(i) for i in input().split()]
a=[]
for i in range(D):
a.append([int(i) for i in input().split()])
last=[0 for i in range(26)]
zoku=0
for d in range(D):
t=int(input())
zoku+=a[d][t-1]
last[t-1]=d+1
for i in range(26):
zoku-=c[i]*(d+1-last[i])
print(zoku) | 0 | null | 4,998,486,828,970 | 7 | 114 |
n = input()
if n[-1]== "2" or n[-1]== "4" or n[-1]== "5" or n[-1]== "7" or n[-1]== "9":
print("hon")
elif n[-1]== "3":
print("bon")
else:
print("pon") | s = input()
map = {'SSS': 0, 'SSR': 1, 'SRS': 1, 'RSS': 1, 'SRR': 2, 'RSR': 1, 'RRS': 2, 'RRR': 3}
for key in map.keys():
if s == key:
print(map[key])
break | 0 | null | 12,094,581,087,050 | 142 | 90 |
import math
n = int(input())
x = list(map(float, (input().split())))
y = list(map(float, (input().split())))
l = [0.0]*n
for i in range(n):
l[i] = abs(x[i]-y[i])
print(sum(l))
che = max(l)
for i in range(n):
l[i] = abs(x[i]-y[i])**2
print(math.sqrt(sum(l)))
for i in range(n):
l[i] = abs(x[i]-y[i])**3
print(math.pow(sum(l), 1.0/3.0))
print(che) | n=eval(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
def minkowski(p,x_1,x_2,n):
if p==0:
return float(max([abs(x_1[i]-x_2[i]) for i in range(n)]))
else:
return sum([(abs(x_1[i]-x_2[i]))**p for i in range(n)])**(1/p)
for i in range(4):
print(minkowski((i+1)%4,x,y,n)) | 1 | 213,328,135,868 | null | 32 | 32 |
import bisect
import collections
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
cuml=[0]*(N+1)
cuml[0]=A[0]
l=[]
cuml2=[]
l2=[]
buf=[]
ans=0
for i in range(N):
cuml[i+1]=cuml[i]+A[i+1]
#print(cuml)
for i in range(N+1):
cuml2.append([(cuml[i]-i)%K,i])
cuml[i]=(cuml[i]-i)%K
#print(cuml2,cuml)
cuml2.sort(key=lambda x:x[0])
piv=cuml2[0][0]
buf=[]
for i in range(N+1):
if piv!=cuml2[i][0]:
l2.append(buf)
piv=cuml2[i][0]
buf=[]
buf.append(cuml2[i][1])
l2.append(buf)
#print(l2)
cnt=0
for i in range(len(l2)):
for j in range(len(l2[i])):
num=l2[i][j]
id=bisect.bisect_left(l2[i], num + K)
#print(j,id)
cnt=cnt+(id-j-1)
print(cnt)
| #!/usr/bin/env python3
import sys
from collections import Counter
input = sys.stdin.readline
INF = 10**9
n, k = [int(item) for item in input().split()]
a = [int(item) - 1 for item in input().split()]
cumsum = [0] * (n + 1)
for i in range(n):
cumsum[i+1] = cumsum[i] + a[i]
cumsum[i+1] %= k
ls = list(set(cumsum))
dic = dict()
for i, item in enumerate(ls):
dic[item] = i
cnt = [0] * (n + 10)
num = 0
ans = 0
for i, item in enumerate(cumsum):
index = dic[item]
ans += cnt[index]
cnt[index] += 1
num += 1
if num >= k:
left = cumsum[i - k + 1]
index = dic[left]
if cnt[index] > 0:
cnt[index] -= 1
num -= 1
print(ans) | 1 | 137,197,523,068,480 | null | 273 | 273 |
n, t = map(int, input().split())
dish = [list(map(int, input().split())) for _ in range(n)]
dish.sort(key=lambda x: x[0])
dp = [[0 for _ in range(3005)] for _ in range(3005)]
ans = 0
for i in range(n):
for j in range(t):
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
nj = j + dish[i][0]
if nj < t:
dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + dish[i][1])
now = dp[i][t- 1] + dish[i][1]
ans = max(ans, now)
print(ans) | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#inf = 10**17
#mod = 10**9 + 7
n,t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
ab.sort(key=lambda x: x[0])
dp = [-1]*(t+1)
dp[0] = 0
for a, b in ab:
for j in range(t-1, -1, -1):
if dp[j] >= 0:
if j+a<=t:
dp[j+a] = max(dp[j+a], dp[j]+b)
else:
dp[-1] = max(dp[-1], dp[j]+b)
print(max(dp))
if __name__ == '__main__':
main() | 1 | 151,030,707,292,000 | null | 282 | 282 |
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
aMax = a[-1]
l = len(a)
count = 0
k = 0
kSet = set()
for i in range(n):
value = a[i]
if not(value in kSet):
if i != 0 and a[i-1] == value:
count -= 1
kSet.add(value)
continue
count += 1
j = 2
k = 0
while k < aMax:
k = a[i] * j
kSet.add(k)
j += 1
print(count) | N = int(input())
A = list(map(int, input().split()))
A.sort()
MAX = 10**6+1
cnt = [0]*MAX
for x in A:
if cnt[x] != 0:
cnt[x] = 2
else:
for i in range(x, MAX, x):
cnt[i] += 1
ans = 0
for x in A:
# 2回以上通った数字 (cnt[x]>1) は,その数字より小さい約数が存在する (割り切れる他の数が存在する)。
if cnt[x] == 1:
ans += 1
print(ans) | 1 | 14,353,677,496,220 | null | 129 | 129 |
n = int(input())
s = list(map(int, input().split()))
s.sort()
dp = [0] * ((10 ** 6) + 100)
for ss in s:
dp[ss] += 1
A = max(s)
pairwise = True
setwise = True
for i in range(2, A + 1):
cnt = 0
for j in range(i, A + 1, i):
cnt += dp[j]
if cnt > 1:
pairwise = False
if cnt >= n:
setwise = False
break
if pairwise:
print("pairwise coprime")
elif setwise:
print("setwise coprime")
else:
print("not coprime")
| from functools import reduce
from math import gcd
n = int(input())
A = list(map(int, input().split()))
def furui(x):
memo = [0]*(x+1)
primes = []
for i in range(2, x+1):
if memo[i]: continue
primes.append(i)
memo[i] = i
for j in range(i*i, x+1, i):
if memo[j]: continue
memo[j] = i
return memo, primes
memo, primes = furui(10**6+5)
pr = [True]*(10**6+5)
for a in A:
if a == 1: continue
while a != 1:
w = memo[a]
if not pr[w]:
break
pr[w] = False
while a%w == 0:
a = a // w
else:
continue
break
else:
print('pairwise coprime')
exit()
if reduce(gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| 1 | 4,056,761,902,050 | null | 85 | 85 |
#!/usr/bin/env python3
def main():
print(int(input()) ** 3 / 27)
if __name__ == '__main__':
main()
| print(((1/3)*float(input("")))**3) | 1 | 47,250,163,720,256 | null | 191 | 191 |
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019
t = [0]
r = 1
for i in range(len(S)):
q = (t[-1] + (int(S[i]) * r)) % MOD
t.append(q)
r *= 10
r %= MOD
cnt = Counter(t)
cnt_mc = cnt.most_common()
ans = 0
for _, j in cnt_mc:
if j >= 2:
ans += j * (j - 1) // 2
print(ans) | from collections import defaultdict
s = input()
rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
n = n + int(i)*m
c[n % 2019] += 1
m = m * 10 % 2019
for v in c.values():
a += v * (v-1) // 2
print(a)
| 1 | 30,999,432,372,612 | null | 166 | 166 |
#template
def inputlist(): return [int(j) for j in input().split()]
#template
mod = 10**9 + 7
N = int(input())
A = inputlist()
s = sum(A)
ans = 0
for i in range(N):
s -= A[i]
ans += A[i]*s
ans %= mod
print(ans) | import sys
import math
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
mid = (ok + ng) // 2
ans = sum(list(map(lambda x: math.ceil(x / mid) - 1, A)))
# for i in range(N):
# ans += A[i]//mid -1
# if A[i]%mid !=0:
# ans +=1
if ans <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
| 0 | null | 5,153,536,261,952 | 83 | 99 |
n = int(input())
print("ACL" * n) | n=int(input())
r="ACL"*n
print(r) | 1 | 2,200,786,674,952 | null | 69 | 69 |
N = int(input())
a_list = list(map(int, input().split()))
all_xor = 0
res = []
for a in a_list:
all_xor ^= a
for a in a_list:
res.append(a ^ all_xor)
print(*res)
| # n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#ls=list(map(int,input().split()))
#for i in range(m):
# for _ in range(int(input())):
#from collections import Counter
#from fractions import Fraction
n=int(input())
arr=list(map(int,input().split()))
var=arr[0]
for i in range(1,n):
var^=arr[i]
for i in range(n):
print(arr[i]^var,end=" ")
#ls = [list(map(int, input().split())) for i in range(n)]
#for _ in range(int(input())):
| 1 | 12,505,915,524,708 | null | 123 | 123 |
k=int(input())
s=input()
l=len(s)
if l<=k:
print(s)
else:
s=list(s)
t=[]
for i in range(k):
t.append(s[i])
t.append('...')
print(''.join(t))
| #import time
def main():
K = int(input())
S = input()
if len(S) <= K:
return S
else:
return S[:K] + "..."
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]") | 1 | 19,740,068,018,720 | null | 143 | 143 |
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
dd = defaultdict(int)
ans = 0
for i in range(n):
diff = i - A[i]
ans += dd[diff]
summ = A[i] + i
dd[summ] += 1
print(ans)
| inp = input()
if inp[0] == inp[1] and inp[1] == inp[2]:
print("No")
else:
print("Yes") | 0 | null | 40,552,301,097,212 | 157 | 201 |
#10_B
import math
a,b,C=map(int,input().split())
S=a*b*math.sin((C*2*math.pi)/360)/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos((C*2*math.pi)/360))
L=a+b+c
h=2*float(S)/a
print(str(S)+'\n'+str(L)+'\n'+str(h)+'\n')
| import math
a,b,c=map(float,input().split())
h=b*math.sin(c/180.0*math.pi)
ad=a-b*math.cos(c/180.0*math.pi)
d=(h*h+ad*ad)**0.5
l = a + b + d
s = a * h / 2.0
print('{0:.6f}'.format(s))
print('{0:.6f}'.format(l))
print('{0:.6f}'.format(h)) | 1 | 172,294,766,732 | null | 30 | 30 |
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
def main():
N,M,L = map(int,input().split())
edge = np.zeros((N,N))
for _ in range(M):
a,b,c = map(int,input().split())
edge[a-1][b-1] = edge[b-1][a-1] = c
length = floyd_warshall(edge,directed=False)
ref = np.where(length<=L,1,0)
ans = floyd_warshall(ref,directed=False)
Q = int(input())
for _ in range(Q):
s,t = map(int,input().split())
if ans[s-1][t-1] == float("inf"):
print(-1)
else:
print(int(ans[s-1][t-1])-1)
if __name__ == "__main__":
main()
|
n = int(input())
ans = 0
count = 0
a, b, c = 1, 1, 1
while a <= n:
# print("A : {0}".format(a))
# print("追加パターン : {0}".format( (n // a) ))
if a == 1 :
ans = ans + ( (n // a) - 1)
else :
if n // a == 1 :
ans = ans + 1
else :
if n % a == 0 :
ans = ans + ( (n // a) - 1)
else :
ans = ans + ( (n // a) )
# if n % a == 0 :
# ans = ans + ( (n / a) - 1 )
# else :
# ans = ans + ( (n // a) - 1 )
# ans = ans + (n / a) - 1
# print("A : {0}".format(a))
# while a * b < n:
# print("B : {0}".format(b))
# ans += 1
# b += 1
# c = 1
a += 1
b, c = 1, 1
# print("計算実行回数 : {0}".format(count))
print(ans - 1) | 0 | null | 88,107,800,716,172 | 295 | 73 |
a=int(input())
cnt=0
t=100
while t<a:
t=(t*101)//100
cnt+=1
print(cnt) |
def insertionsort(A, n, g, cnt):
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 = []
n = int(raw_input())
for i in range(n):
A.append(int(raw_input()))
cnt = 0
G = [1]
while G[-1] * 3 + 1 < n:
G.append(G[-1] * 3 + 1)
G.reverse()
m = len(G)
for i in range(m):
cnt = insertionsort(A, n, G[i], cnt)
print m
print " ".join(map(str, G))
print cnt
for num in A:
print num | 0 | null | 13,656,327,952,176 | 159 | 17 |
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N,K,S = MI()
if S == 10**9:
ANS = [10**9]*K + [1]*(N-K)
else:
ANS = [S]*K + [10**9]*(N-K)
print(*ANS)
| def e_handshake():
import numpy as np
N, M = [int(i) for i in input().split()]
A = np.array(input().split(), np.int64)
A.sort()
def shake_cnt(x):
# 幸福度が x 以上となるような握手を全て行うときの握手の回数
# 全体から行わない握手回数を引く
return N**2 - np.searchsorted(A, x - A).sum()
# 幸福度の上昇が right 以上となるような握手はすべて行い、
# left となるような握手はいくつか行って握手回数が M 回になるようにする
left = 0
right = 10 ** 6
while right - left > 1:
mid = (left + right) // 2
if shake_cnt(mid) >= M:
left = mid
else:
right = mid
# 幸福度が right 以上上がるような握手をすべて行ったとして、回数と総和を計算
X = np.searchsorted(A, right - A) # 行わない人数
Acum = np.zeros(N + 1, np.int64) # 累積和で管理する
Acum[1:] = np.cumsum(A)
happiness = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()
# 幸福度が right 未満の上昇となる握手を、握手回数が M になるまで追加で行う
shake = N * N - X.sum()
happiness += (M - shake) * left
return happiness
print(e_handshake()) | 0 | null | 99,673,456,518,790 | 238 | 252 |
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
s=input()
n=len(s)
ans=0
for i in range(n//2):
if s[i]!=s[-1-i]:
ans+=1
print(ans) | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
N = int(input())
S = input()
if N % 2 == 0:
if S[:N//2] == S[N//2:]:
print("Yes")
else:
print("No")
else:
print("No") | 0 | null | 133,635,103,300,740 | 261 | 279 |
exchange_cnt = 0
def insertion_sort(w_list, g):
"""一般化した Insertion ソート
通常の Insertion ソートは gap が 1 固定だが、ここでは、
gap を引数 g で指定できる。
当然、g < len(w_list) でないといけない。
"""
global exchange_cnt
N = len(w_list)
for i in range(g, N):
v = w_list[i]
j = i - g
while j >= 0 and w_list[j] > v:
w_list[j+g] = w_list[j]
j -= g
exchange_cnt += 1
w_list[j+g] = v
def make_gap_sequence(n):
"""gap sequence を作成
とりあえず、Wiki にのっていたやり方のひとつを採用。
N ^ 1.5 のオーダーになるという。
"""
seq = []
k = 1
while True:
gap = 2 ** k - 1
if gap > n:
break
seq.append(gap)
k += 1
seq.reverse() # in place なので効率が良い。
return seq
def make_gap_sequence_2(n):
"""もうひとつの gap sequence の作成方法
Wiki にのっていた Shell によるオリジナルの方法。
これだと最悪の場合、N ^ 2 のオーダーになってしまうようだ。
"""
seq = []
k = 1
while True:
gap = n // (2 ** k)
if gap <= 1:
break
seq.append(gap)
k += 1
seq.append(1)
return seq
def shell_sort(w_list):
N = len(w_list)
# N から gap sequence を決める。
# どう決めるかで効率が変わってくるのだが、どう決めるかは難問。
# gap_sequence = make_gap_sequence(N)
gap_sequence = make_gap_sequence_2(N)
for g in gap_sequence:
insertion_sort(w_list, g)
return gap_sequence
n = int(input())
w_list = []
for _ in range(n):
w_list.append(int(input()))
gap_seq = shell_sort(w_list)
print(len(gap_seq))
print(*gap_seq)
print(exchange_cnt)
for i in w_list:
print(i)
| # E - Bomber
from collections import Counter
h, w, m = map(int, input().split())
hw = [tuple(map(int, input().split())) for i in range(m)]
ys, xs = zip(*hw)
ymax, = Counter(ys).most_common(1)
xmax, = Counter(xs).most_common(1)
bombed = max(ymax[1], xmax[1])
if bombed < m:
if ymax[1] > xmax[1]:
xs = [b for a, b in hw if a != ymax[0]]
xmax, = Counter(xs).most_common(1)
bombed += xmax[1]
else:
ys = [a for a, b in hw if b != xmax[0]]
ymax, = Counter(ys).most_common(1)
bombed += ymax[1]
print(bombed)
| 0 | null | 2,357,407,380,860 | 17 | 89 |
def main():
num = list(map(int,input().split()))
if num[0]+num[1]+num[2]<22:
print('win')
else:
print('bust')
main() | x, y, z = map(int,input().split())
a = x + y + z
if (a >= 22):
print("bust")
else:
print("win") | 1 | 118,756,683,480,370 | null | 260 | 260 |
def main(M_1: int, D_1: int, M_2: int, D_2: int):
print(M_2 - M_1)
if __name__ == "__main__":
M_1, D_1 = map(int, input().split())
M_2, D_2 = map(int, input().split())
main(M_1, D_1, M_2, D_2)
| N,K = map(int, input().split())
L,R = [0]*K, [0]*K
count = 0
for _ in range(K):
a,b = map(int, input().split())
for _1 in range(_):
x,y = L[_1],R[_1]
if x <= a <= y or x <= b <= y :
L[_1] = min(a,x)
R[_1] = max(b,y)
break
else:
L[_],R[_] =a,b
count += 1
L,R = L[0:count+1],R[0:count+1]
MOD = 998244353
dp = [0]*(4*10**5+100)
for l, r in zip(L, R):
dp[min(N + 1, 1 + l)] += 1
dp[min(N + 1, 1 + r + 1)] -= 1
for i in range(2,N+1):
number = dp[i-1] + dp[i]
if number > MOD:
number -= MOD
dp[i] = number
for l, r in zip(L,R):
dp[i + l] += number
dp[i + l] %= MOD
dp[i + r +1] -= number
dp[i + r +1] %= MOD
print(dp[N]%MOD) | 0 | null | 63,572,291,754,080 | 264 | 74 |
import sys
X=map(int, sys.stdin.readline().split())
print X.index(0)+1
| import sys
from collections import Counter
from itertools import combinations
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7
INF = float("inf")
def main():
N = int(input())
L = list(map(int, input().split()))
count = Counter(L)
key = count.keys()
set_list = combinations(key, 3)
answer = 0
for s in set_list:
a = s[0]
b = s[1]
c = s[2]
if (a + b) > c and (b + c) > a and (c + a) > b:
answer += count[a] * count[b] * count[c]
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 9,228,449,799,930 | 126 | 91 |
X, Y = map(int, input().split())
ans = 0
if X == 1:
ans += 300000
elif X == 2:
ans += 200000
elif X == 3:
ans += 100000
else:
ans += 0
if Y == 1:
ans += 300000
elif Y == 2:
ans += 200000
elif Y == 3:
ans += 100000
else:
ans += 0
if X == 1 and Y == 1:
ans += 400000
print(ans) | def Qc():
x, n = map(int, input().split())
if 0 < n:
p = list(map(int, input().split()))
for i in range(101):
if x - i not in p:
print(x - i)
exit()
if x + i not in p:
res = x + 1
print(x + i)
exit()
else:
# 整数列がなにもない場合は自分自身が含まれていない最近値になる
print(x)
exit()
if __name__ == "__main__":
Qc()
| 0 | null | 77,332,061,273,610 | 275 | 128 |
import bisect
import collections
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
cuml=[0]*(N+1)
cuml[0]=A[0]
l=[]
cuml2=[]
l2=[]
buf=[]
ans=0
for i in range(N):
cuml[i+1]=cuml[i]+A[i+1]
#print(cuml)
for i in range(N+1):
cuml2.append([(cuml[i]-i)%K,i])
cuml[i]=(cuml[i]-i)%K
#print(cuml2,cuml)
cuml2.sort(key=lambda x:x[0])
piv=cuml2[0][0]
buf=[]
for i in range(N+1):
if piv!=cuml2[i][0]:
l2.append(buf)
piv=cuml2[i][0]
buf=[]
buf.append(cuml2[i][1])
l2.append(buf)
#print(l2)
cnt=0
for i in range(len(l2)):
for j in range(len(l2[i])):
num=l2[i][j]
id=bisect.bisect_left(l2[i], num + K)
#print(j,id)
cnt=cnt+(id-j-1)
print(cnt)
| import numpy as np
from collections import defaultdict
N, K = map(int, input().split())
As = np.array([0] + list(map(int, input().split())))
#Find (i, j) that satisfies "sum(As[i:j]) % K == j - i"
#If 0 < j - i < K then
#sum(As[i:j]) % K == j - i % K
#<-> (sum(As[:j]) - j) % K == (sum(As[:i]) - i) % K
mods = As % K
csum_mods = np.cumsum(mods)
magic_array = (csum_mods - np.arange(0, N+1)) % K
indices = defaultdict(list)
for i, m in enumerate(magic_array.tolist()):
indices[m].append(i)
ans = 0
for ls in indices.values():
j = 1
for i in range(len(ls)):
while j < len(ls):
if ls[j] - ls[i] < K:
j += 1
else:
break
ans += j - i - 1
print(ans)
| 1 | 137,398,898,831,520 | null | 273 | 273 |
N, M = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
A_ls = [i for i in A_ls if i >= sum(A_ls) / (4 * M)]
if len(A_ls) >= M:
print('Yes')
else:
print('No') | import sys
x = sys.stdin.readline()
print int(x) ** 3 | 0 | null | 19,616,502,220,320 | 179 | 35 |
input_line = input()
a,b = input_line.strip().split(' ')
a = int(a)
b = int(b)
if a < b:
print("a < b")
elif a > b:
print("a > b")
elif a == b:
print("a == b") | N, S = int(input()), input()
print("Yes" if N%2 == 0 and S[:(N//2)] == S[(N//2):] else "No") | 0 | null | 73,721,479,908,900 | 38 | 279 |
def gcd(a,b):
while b:
a,b = b,a%b
return abs(a)
K=int(input())
#余裕でTLE?
ans=0
for a in range(1, K+1):
for b in range(1, K+1):
for c in range(1, K+1):
temp=a
temp=gcd(temp, b)
temp=gcd(temp, c)
ans+=temp
print(ans) | def main():
N = int(input())
A = (
1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889,
13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857,
71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836,
194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709,
397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712,
709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467,
1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570,
1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104,
2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249,
3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949,
4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008,
5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016,
6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897,
8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813,
10493367, 10611772, 10813692)
print(A[N - 1])
if __name__ == '__main__':
main() | 1 | 35,448,976,628,298 | null | 174 | 174 |
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while a >= b:
cnt += 1
b *= 2
while b >= c:
cnt += 1
c *= 2
if cnt <= k: print("Yes")
else: print("No") | import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
xy = []
for i in range(n):
xy.append(abs(x[i] - y[i]))
D = [0, 0, 0, 0]
D[0] = sum(xy)
D2 = 0
for xyi in xy:
D2 += xyi ** 2
D[1] = math.sqrt(D2)
D3 = 0
for xyi in xy:
D3 += xyi ** 3
D[2] = math.pow(D3, 1.0/3.0)
D[3] = max(xy)
for d in D:
print(d)
| 0 | null | 3,590,619,427,820 | 101 | 32 |
N, M = map(int, input().split())
pena= 0
ac = [0]*(10**5)
for _ in range(M):
tmp = input().split()
if ac[int(tmp[0])-1] < 1:
if tmp[1] == "AC":
pena -= ac[int(tmp[0])-1]
ac[int(tmp[0])-1] = 1
else: ac[int(tmp[0])-1] -= 1 #penalty
print(ac.count(1), pena) | import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N =I()
N,M= LI()
if M==0:
print(0,0)
exit()
pS = [LS() for _ in range(M)]
# print(pS)
_p,S = zip(*pS)
p = list(map(int,_p))
WA = np.zeros(N+1)
AC = np.full(N+1,False, dtype=bool)
penalty = 0
for i in range(M):
if AC[p[i]]:
continue
if S[i]=='WA':
WA[p[i]] += + 1
else:
AC[p[i]]=True
penalty += WA[p[i]]
AC_count = np.count_nonzero(AC)
# space output
print(AC_count,int(penalty))
#Ap = np.array(A)
# if ans:
# print('Yes')
# else:
# print('No') | 1 | 93,328,114,783,232 | null | 240 | 240 |
import sys
n,m,l=map(int,input().split())
e=[list(map(int,e.split()))for e in sys.stdin]
for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])
| import sys
lines = [list(map(int,line.split())) for line in sys.stdin]
n,m,l = lines[0]
A = lines[1:n+1]
B = [i for i in zip(*lines[n+1:])]
for a in A:
row = []
for b in B:
row.append(sum([i*j for i,j in zip(a,b)]))
print (" ".join(map(str,row))) | 1 | 1,409,737,899,192 | null | 60 | 60 |
def main():
N = int(input())
X = input()
def popcount(x):
'''xの立っているビット数をカウントする関数
(xは64bit整数)'''
# 2bitごとの組に分け、立っているビット数を2bitで表現する
x = x - ((x >> 1) & 0x5555555555555555)
# 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
x = x + (x >> 8) # 16bitごと
x = x + (x >> 16) # 32bitごと
x = x + (x >> 32) # 64bitごと = 全部の合計
return x & 0x0000007f
ans = []
f = [0] * N
# preprocess 1
for i in range(1, N):
pc = popcount(i)
j = i % pc
f[i] = f[j] + 1
# preprocess 2
X_COUNT = X.count("1")
X = tuple(map(int, tuple(X)))
rem_plus = [0] * N
rem_minus = [0] * N
two_factor = 1
for i in range(N):
rem_plus[i] = two_factor
two_factor *= 2
two_factor %= (X_COUNT+1)
if X_COUNT > 1:
two_factor = 1
for i in range(N):
rem_minus[i] = two_factor
two_factor *= 2
two_factor %= (X_COUNT-1)
X_rem_plus = 0
X_rem_minus = 0
two_factor = 1
for c in X[::-1]:
X_rem_plus += two_factor*c
X_rem_plus %= (X_COUNT+1)
two_factor *= 2
two_factor %= (X_COUNT+1)
if X_COUNT > 1:
two_factor = 1
for c in X[::-1]:
X_rem_minus += two_factor*c
X_rem_minus %= (X_COUNT-1)
two_factor *= 2
two_factor %= (X_COUNT-1)
for i, c in enumerate(X):
if c:
if X_COUNT > 1:
rem = X_rem_minus - rem_minus[N-1-i]
rem %= (X_COUNT-1)
ans.append(f[rem]+1)
elif X_COUNT == 1:
ans.append(0)
else:
ans.append(0)
else:
rem = X_rem_plus + rem_plus[N-1-i]
rem %= (X_COUNT+1)
ans.append(f[rem]+1)
print(*ans, sep="\n")
if __name__ == "__main__":
main() | n,k=map(int,input().split())
lst_ans=[]
for i in range(k):
s=int(input())
lst_n=list(map(int,input().split()))
for j in lst_n:
lst_ans.append(j)
print(n-len(set(lst_ans))) | 0 | null | 16,491,171,618,172 | 107 | 154 |
cards = list()
pattern = ["S", "H", "C","D"]
n = int(input())
for i in range(n) :
s, r = input().split() #文字列として読み込み
r = int(r) #sは文字列、rは数値
if(s == "S") :
cards.append(0 + r)
elif(s == "H") :
cards.append(13 + r)
elif(s == "C") :
cards.append(26 + r)
else :
cards.append(39 + r)
for i in range(1, 53) :
if not(i in cards) :
print(pattern[(i - 1) // 13], (i - 1) % 13 + 1)
| from itertools import product
(lambda *_: None)(
*(lambda full, hand: map(print,
filter(lambda c: c not in hand, full)))(
map(' '.join, product('SHCD', map(str, range(1, 14)))),
set(map(lambda _: input(), range(int(input())))))) | 1 | 1,044,384,029,570 | null | 54 | 54 |
d = list(map(int, input().split()))
order = input()
class Dice():
def __init__(self, d):
self.dice = d
def InsSN(self, one, two, five, six):
self.dice[0] = one
self.dice[1] = two
self.dice[4] = five
self.dice[5] = six
def InsWE(self, one, three, four, six):
self.dice[0] = one
self.dice[2] = three
self.dice[3] = four
self.dice[5] = six
def S(self):
one = self.dice[4]
two = self.dice[0]
five = self.dice[5]
six = self.dice[1]
self.InsSN(one, two, five, six)
def N(self):
one = self.dice[1]
two = self.dice[5]
five = self.dice[0]
six = self.dice[4]
self.InsSN(one, two, five, six)
def W(self):
one = self.dice[2]
three = self.dice[5]
four = self.dice[0]
six = self.dice[3]
self.InsWE(one, three, four, six)
def E(self):
one = self.dice[3]
three = self.dice[0]
four = self.dice[5]
six = self.dice[2]
self.InsWE(one, three, four, six)
def roll(self, order):
if order == 'S':
self.S()
elif order == 'N':
self.N()
elif order == 'E':
self.E()
elif order == 'W':
self.W()
d = Dice(d)
for o in order:
d.roll(o)
print(d.dice[0]) | #!/usr/bin/python3
n = int(input())
if(n%1000==0):
print("0")
else:
ans = n%1000
print(1000-ans) | 0 | null | 4,318,196,791,850 | 33 | 108 |
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while a >= b:
cnt += 1
b *= 2
while b >= c:
cnt += 1
c *= 2
if cnt <= k: print("Yes")
else: print("No") | n = int(input())
full_set=set([x for x in range(1,14)])
cards={"S":[],"H":[],"C":[],"D":[]}
for i in range(n):
suit,num = input().split()
cards[suit].append(int(num))
for suit in ["S","H","C","D"]:
suit_set = set(cards[suit])
for num in sorted(list(full_set - suit_set)): print(suit,num) | 0 | null | 4,013,922,855,360 | 101 | 54 |
n = int(input())
anums = list(map(int, input().split()))
result = 'APPROVED'
for anum in anums:
if (anum % 2 == 0) and not ((anum % 3 == 0) or (anum % 5 == 0)):
result = 'DENIED'
break
print(result) | import sys
n=int(input())
data=list(map(int,input().split()))
for i in data:
if i%2==1:
continue
if i%3!=0 and i%5!=0:
print("DENIED")
sys.exit()
print("APPROVED") | 1 | 68,662,637,681,540 | null | 217 | 217 |
N=int(input())
M=1000
if N%M==0:
print(0)
else:
print(M-N%M) | d,t,s = [int(x) for x in input().split()]
if d/s <= t:
print("Yes")
else:
print("No") | 0 | null | 6,044,149,614,272 | 108 | 81 |
n, k = map(int, input().split(" "))
MOD = (10**9) + 7
def dSum(s, e):
s -= 1
_s = s * (s + 1) // 2
_e = e * (e + 1) // 2
return _e - _s
ans = 0
for i in range(k, n + 1):
# _sum = dSum(n - i - 1, n) - dSum(0, i - 1) + 1
ans += dSum(i, n) - dSum(0, n - i) + 1
print((ans + 1) % MOD)
| import sys
import copy
from collections import deque
stdin = sys.stdin
mod = 10**9+7
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
n,k = na()
if n==k-1:
print(1)
exit(0)
prev_min = sum([i for i in range(k)])
prev_max = sum([i for i in range(n, n-k, -1)])
prev_num_min = k-1
prev_num_max = n-k+1
cnt = 0
for i in range(n-k+2):
# print("{} {}".format(prev_min, prev_max))
cnt += prev_max-prev_min+1
cnt %= mod
prev_num_min += 1
prev_num_max -= 1
prev_min += prev_num_min
prev_max += prev_num_max
print(cnt)
| 1 | 33,248,760,641,572 | null | 170 | 170 |
N,K = map(int,input().split())
MOD = pow(10,9)+7
ans = 0
for i in range(K,N+2): #KからN+1
MAX = i*(2*N-i+1)//2
MIN = i*(i-1)//2
#print(i,MIN,MAX)
ans += (MAX-MIN+1)%MOD
print(ans%MOD) | a,b = input().split()
a = int(a)
b = int(b)
if a >= 10 or b >=10:
print ('-1')
else:
print (a * b) | 0 | null | 95,776,543,004,930 | 170 | 286 |
def II(): return int(input())
def LI(): return list(map(int, input().split()))
N=II()
a=LI()
A=0
for elem in a:
A^=elem
ans=[elem^A for elem in a]
print(*ans) | n = int(input())
a = list(map(int, input().split()))
def nim(x):
bx = [format(i,'030b') for i in x]
bz = ''.join([str( sum([int(bx[xi][i]) for xi in range(len(x))]) % 2) for i in range(30)])
return int(bz, 2)
nima = nim(a)
ans = [ str(nim([nima,aa])) for aa in a ]
print(' '.join(ans) ) | 1 | 12,514,010,017,732 | null | 123 | 123 |
def solve():
N = int(input())
return N*N
print(solve()) | S = input()
T = input()
a = len(T)
for i in range(len(S)-len(T)+1):
c = 0
for j, t in enumerate(T):
if S[i+j] != t:
c += 1
a = min(a, c)
print(a) | 0 | null | 74,229,611,283,908 | 278 | 82 |
from math import *
def az9():
r = float(input())
print "%5f"%(pi*r*r), "%5f"%(2*pi*r)
az9() | n, m, l = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for y in range(n)]
b = [[int(x) for x in input().split()] for y in range(m)]
c = [[0 for x in range(l)] for y in range(n)]
for i in range(n):
for j in range(l):
c[i][j] = sum([a[i][x] * b[x][j] for x in range(m)])
for i in c:
print(*i) | 0 | null | 1,024,090,656,750 | 46 | 60 |
def factorization(n):
arr = []
tmp = n
for i in range(2, int(-(-n**0.5//1))+1):
if tmp % i == 0:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
arr.append([i, cnt])
if tmp != 1:
arr.append([tmp, 1])
if arr == [] and n != 1:
arr.append([n, 1])
return arr
n = int(input())
c = factorization(n)
ans = 0
for k, v in c:
cnt = 1
while v >= cnt:
v -= cnt
cnt += 1
ans += (cnt - 1)
print(ans)
| operand = ["+", "-", "*"]
src = [x if x in operand else int(x) for x in input().split(" ")]
stack = []
for s in src:
if isinstance(s, int):
stack.append(s)
elif s == "+":
b, a = stack.pop(), stack.pop()
stack.append(a+b)
elif s == "-":
b, a = stack.pop(), stack.pop()
stack.append(a-b)
elif s == "*":
b, a = stack.pop(), stack.pop()
stack.append(a*b)
print(stack[0]) | 0 | null | 8,426,161,343,140 | 136 | 18 |
N = int(input())
As = []
Bs = []
for _ in range(N):
c = 0
m = 0
for s in input():
if s == '(':
c += 1
elif s == ')':
c -= 1
m = min(m, c)
if c >= 0:
As.append((-m, c - m))
else:
Bs.append((-m, c - m))
As.sort(key=lambda x: x[0])
Bs.sort(key=lambda x: x[1], reverse=True)
f = True
c = 0
for (l, r) in As:
if c < l:
f = False
break
c += r - l
if f:
for (l, r) in Bs:
if c < l:
f = False
break
c += r - l
f = f and (c == 0)
if f:
print('Yes')
else:
print('No') | from sys import exit
from itertools import accumulate,chain
n,*s=open(0).read().split()
t=[2*i.count("(")-len(i) for i in s]
if sum(t)!=0:
print("No");exit()
st=[[min(accumulate(s_,lambda a,b: a+(1 if b=="(" else -1),initial=0)),t_] for s_,t_ in zip(s,t)]
now=0
for c in chain(sorted([x for x in st if x[1]>=0])[::-1],sorted([x for x in st if x[1]<0],key=lambda z:z[1]-z[0])[::-1]):
if now+c[0]<0:
print("No");exit()
now+=c[1]
print("Yes") | 1 | 23,466,912,209,448 | null | 152 | 152 |
x, n = map(int, input().split())
p = [int(s) for s in input().split()]
min_val = 101
for i in range(102):
if i not in p:
if abs(i - x) < min_val:
min_val = abs(i - x)
ans = i
print(ans) | def inp():
return input()
def iinp():
return int(input())
def inps():
return input().split()
def miinps():
return map(int,input().split())
def linps():
return list(input().split())
def lmiinps():
return list(map(int,input().split()))
def lmiinpsf(n):
return [list(map(int,input().split()))for _ in range(n)]
n = iinp()
l = lmiinps()
ans = 0
if n < 3:
print(0)
exit()
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if l[i] == l[j] or l[j] == l[k] or l[i] == l[k]:
continue
if l[i]+l[j] > l[k] and l[j]+l[k] > l[i] and l[k]+l[i] > l[j]:
ans += 1
print(ans) | 0 | null | 9,549,305,835,770 | 128 | 91 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans += k
k = 0
else:
ans += a
k -= a
if b >= k:
k = 0
else:
k -= b
if c >= k:
ans -= k
print(ans) | N=int(input())
a=list(map(int, input().split()))
a=sorted(a)[::-1]
ans =a[0]
if len(a)%2 !=0:
for i in range(1,int((len(a))/2)+1):
for j in range(2):
ans +=a[i]
print(ans-a[int((len(a))/2)])
else:
for i in range(1,(len(a))//2):
for j in range(2):
ans +=a[i]
print(ans) | 0 | null | 15,518,375,358,652 | 148 | 111 |
a, b = map(int, raw_input().split())
d = a // b
r = a % b
f = round(float(a)/float(b), 6)
print d,r,f | a,b = map(float, raw_input().split())
if b > 10**6:
f = 0.0
else:
f = a/b
d = int(a/b)
r = int(a%b)
print d, r, f | 1 | 608,021,263,720 | null | 45 | 45 |
n=int(input())
a=list(map(int,input().split()))
ans=0
plus=[0]*1000000
minus=[0]*1000000
for i in range(n):
ene=i+1
pin=a[i]
pl,mi=ene+pin,ene-pin
if 0<=pl<1000000:
plus[pl]+=1
if 0<=mi<1000000:
minus[mi]+=1
for i in range(1000000):
ans+=plus[i]*minus[i]
print(ans) | import collections
N = int(input())
A = list(map(int , input().split()))
# N = 32
# A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5]
# N = 6
# A = [2, 3, 3, 1, 3, 1]
i = [k for k in range(1,N+1)]
j = [k for k in range(1,N+1)]
Li = [i[k]+A[k] for k in range(N)]
Rj = [j[k]-A[k] for k in range(N)]
Li = collections.Counter(Li)
counter = 0
for r in Rj:
counter += Li[r]
print(counter) | 1 | 26,211,783,034,020 | null | 157 | 157 |
a, b, c =map(int, input().split())
d=(a-1)//c
e=b//c
ans=e-d
print(ans) | l,r,d = map(int,input().split())
#print(l,r,d)
ans = 0
for i in range(101):
if d * i > r:
break
elif d * i >= l:
ans += 1
continue
else:
continue
print(ans) | 1 | 7,518,628,050,546 | null | 104 | 104 |
N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N):
tmp = list(map(int, input().split()))
if tmp[1] == 0:
continue
E[tmp[0]] = tmp[2:]
cnt = [0 for _ in range(N+1)]
q = [1]
while q:
cp = q.pop(0)
for np in E[cp]:
if cnt[np] != 0:
continue
cnt[np] = cnt[cp] + 1
q.append(np)
for ind, cost in enumerate(cnt):
if ind == 0:
continue
if ind == 1:
print(ind, 0)
else:
if cost == 0:
print(ind, -1)
else:
print(ind, cost)
| import sys
n = int(input())
G = [None]*n
for i in range(n):
u, k, *vs = map(int, input().split())
G[u-1] = [e-1 for e in vs]
from collections import deque
dist = [-1]*n
que = deque([0])
dist[0] = 0
while que:
v = que.popleft()
d = dist[v]
for w in G[v]:
if dist[w] > -1: #already visited
continue
dist[w] = d + 1
que.append(w)
for i in range(n):
print(i+1, dist[i])
| 1 | 4,431,594,740 | null | 9 | 9 |
import sys
from collections import deque
read = sys.stdin.read
N, *ab = map(int, read().split())
graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
graph[a].append(b)
color = [0] * (N + 1)
queue = deque([1])
while queue:
V = queue.popleft()
number = 1
for v in graph[V]:
if number == color[V]:
number += 1
color[v] = number
queue.append(v)
number += 1
print(max(color))
for a, b in zip(*[iter(ab)] * 2):
print(color[b])
| N = int(input())
ans = [0] * (N-1)
to = [[] for i in range(N-1)]
used = [0] * N
for i in range(N-1):
a, b = map(int, input().split())
to[a-1].append([b-1, i])
for i in range(N-1):
unable = used[i]
c = 1
for j, id in to[i]:
if c == unable:
c += 1
ans[id] = c
used[j] = c
c += 1
print(max(used))
for i in range(N-1):
print(ans[i]) | 1 | 135,850,028,014,710 | null | 272 | 272 |
n,k=map(int,input().split())
P=list(map(int,input().split()))
for i in range(n):
P[i]-=1
C=list(map(int,input().split()))
PP=[0]*n
A=[0]*n
V=[0]*n
for i in range(n):
if V[i]==1:
continue
B=[i]
c=1
j=i
p=C[i]
while P[j]!=i:
j=P[j]
B.append(j)
c=c+1
p=p+C[j]
for j in B:
A[j]=c
PP[j]=p
ans=-10**10
for i in range(n):
if PP[i]<0:
aans=0
f=0
else:
if k//A[i]-1>0:
aans=(k//A[i]-1)*PP[i]
f=1
else:
aans=0
f=2
l=i
aaans=-10**10
if f==0:
for j in range(min(k,A[i])):
aans=aans+C[P[l]]
l=P[l]
if aans>aaans:
aaans=aans
elif f==1:
for j in range(k%A[i]+A[i]):
aans=aans+C[P[l]]
l=P[l]
if aans>aaans:
aaans=aans
else:
for j in range(min(k,2*A[i])):
aans=aans+C[P[l]]
l=P[l]
if aans>aaans:
aaans=aans
if aaans>ans:
ans=aaans
print(ans) | import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N,K = MI()
A = [0] + LI()
for i in range(K+1,N+1):
print('Yes' if A[i] > A[i-K] else 'No')
| 0 | null | 6,326,198,007,470 | 93 | 102 |