code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
a = input()
ar = [0 for i in range(len(a)+1)]
for i in range(len(a)):
if a[i] == '<':
ar[i+1] = max(ar[i] + 1,ar[i+1])
for i in range(len(a)-1,-1,-1):
if a[i] == '>':
ar[i] = max(ar[i+1] + 1,ar[i])
print(sum(ar))
|
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()
INF = float('inf')
s = S()
n = len(s)
ans = 0
cnt = 0
before_cnt = 0
now = s[0]
for x in s:
if now == x: # 同じ不等号が連続しているとき
cnt += 1
else: # 不等号が変わるとき
ans += cnt * (cnt + 1) // 2
if now == '>': # > から < に変わるとき
if before_cnt < cnt:
ans -= before_cnt
else:
ans -= cnt
before_cnt = cnt
cnt = 1
now = x
ans += cnt * (cnt + 1) // 2
if now == '>':
if before_cnt < cnt:
ans -= before_cnt
else:
ans -= cnt
print(ans)
| 1 | 156,586,032,659,040 | null | 285 | 285 |
n, k, s = map(int, input().split())
for i in range(n):
if k == 0:
if s-1 > 0:
print(s-1, end=' ')
else:
print(s+1, end=' ')
else:
print(s, end=' ')
k -= 1
print()
|
N,K,S = [int(hoge) for hoge in input().split()]
import math
#累積和数列であって、Ar-Al=Sを満たすものが丁度K個ある
if S==10**9:
print(*([S]*K + [27]*(N-K)))
elif S:
print(*([S]*K + [S+1]*(N-K)))
else:
ans = []
while 1:
if K==2:
ans +=[0,1,0]
break
for R in range(N):
if (R+1)*(R+2)//2 > K:break
print(K)
if K==0:break
ans += [0]*R+[1]
K = K - R*(R+1)//2
print(ans + [1]*(N-len(ans)))
| 1 | 91,010,059,587,420 | null | 238 | 238 |
# ABC149
# B Greesy Takahashi
# takはA枚、aokiはB枚、TAKはK回
a, b, k = map(int, input().split())
if k > a:
if k - a > b:
print(0,0)
else:
print(0,b - (k - a))
else:
print(a-k,b)
|
s = input()
t = input()
x = len(s)
num = 0
for i in range(0, x):
if s[i] != t[i]:
num += 1
print(num)
| 0 | null | 57,690,948,014,748 | 249 | 116 |
def main():
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
x, y = (a1-b1)*t1, (a2-b2)*t2
if x//abs(x) == y//abs(y):
print(0)
else:
if abs(x) == abs(y):
print("infinity")
else:
x, y = abs(x), abs(y)
if y < x:
print(0)
else:
if x%(y-x) != 0:
print((x+(y-x)-1)//(y-x)*2-1)
else:
print(x//(y-x)*2)
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
T = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = (a[0] - b[0]) * T[0]
q = (a[1] - b[1]) * T[1]
if p > 0:
p *= -1
q *= -1
if p + q < 0:
print(0)
elif p + q > 0:
print(-p // (p + q) * 2 + ((-p % (p + q)) > 0))
else:
print("infinity")
| 1 | 131,506,792,982,292 | null | 269 | 269 |
n={i:0 for i in range(int(input()))}
for i in list(map(int,input().split())):
n[i-1]+=1
[print(i) for i in n.values()]
|
n = int(input())
ss = [input() for _ in range(n)]
cnt = {}
ans =0
for s in ss:
if s not in cnt:
cnt[s]=0
ans += 1
print(ans)
| 0 | null | 31,294,522,941,220 | 169 | 165 |
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()
|
import sys
A, B, C, K = list(map(int, input().split()))
ans = 0
if A > K:
print(K)
sys.exit()
ans += A
K -= A
if B > K:
print(ans)
sys.exit()
K -= B
if C > K:
print(ans - K)
sys.exit()
else:
print(ans - C)
| 0 | null | 13,691,807,068,188 | 94 | 148 |
N=int(input())
A=0
W=0
T=0
R=0
for i in range(N):
st=input()
if st=="AC":
A+=1
elif st=="WA":
W+=1
elif st=="TLE":
T+=1
else:
R+=1
print("AC x "+str(A))
print("WA x "+str(W))
print("TLE x "+str(T))
print("RE x "+str(R))
|
import math
from functools import reduce
n = int(input())
ans = 0
def gcd(*numbers):
return reduce(math.gcd, numbers)
for x in range(n):
for k in range(n):
for l in range(n):
ans += gcd(x+1,k+1,l+1)
print(ans)
| 0 | null | 22,261,690,434,320 | 109 | 174 |
n=int(input())
l=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
a=int(input())
for j in range(a):
x,y = map(int,input().split())
l[i][x-1]=y
ans=0
for i in range(2**n):
d=[0 for x in range(n)]
for j in range(n):
if i>>j & 1:
d[j]=1
flag=1
for j in range(n):
for s in range(n):
if d[j]==1:
if l[j][s]==-1:
continue
if l[j][s]!=d[s]:
flag=0
break
if flag:
ans=max(ans,sum(d))
print(ans)
|
n=int(input())
A=[]
for i in range(n):
for _ in range(int(input())):
x,y=map(int,input().split())
A+=[(i,x-1,y)]
a=0
for i in range(2**n):
if all(i>>j&1<1 or i>>x&1==y for j,x,y in A):
a=max(a,sum(map(int,bin(i)[2:])))
print(a)
| 1 | 120,943,428,435,230 | null | 262 | 262 |
x = raw_input().split()
m = map(int,x)
a = x[0]
b = x[1]
c = x[2]
if a < b and b< c:
print "Yes"
else:
print"No"
|
num = input()
L = []
house = []
for i in range(int(num)):
k = input().split()
k[0] = int(k[0])
k[1] = int(k[1])
k[2] = int(k[2])
k[3] = int(k[3])
L.append(k)
for i in range(3):
a = ["","0","0","0","0","0","0","0","0","0","0"]
b = ["","0","0","0","0","0","0","0","0","0","0"]
c = ["","0","0","0","0","0","0","0","0","0","0"]
d = ["#"*20]
house.append([a,b,c,d])
a = ["","0","0","0","0","0","0","0","0","0","0"]
b = ["","0","0","0","0","0","0","0","0","0","0"]
c = ["","0","0","0","0","0","0","0","0","0","0"]
house.append([a,b,c])
for i in L:
house[i[0]-1][i[1]-1][i[2]] = str(int(house[i[0]-1][i[1]-1][i[2]])+i[3])
for i in house:
for j in i:
k = " ".join(j)
print(k)
| 0 | null | 736,509,856,972 | 39 | 55 |
# coding:UTF-8
import sys
from math import factorial
MOD = 10 ** 9 + 7
INF = 10000000000
def main():
# ------ 入力 ------#
# 1行入力
a = input() # 文字列
# ------ 出力 ------#
if a[-1] == "s":
print("{}".format(a + "es"))
else:
print("{}".format(a + "s"))
if __name__ == '__main__':
main()
|
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
S = input()
if S[-1] == 's':
S += 'es'
else:
S += 's'
print(S)
resolve()
| 1 | 2,391,192,936,004 | null | 71 | 71 |
# ITP1_10_B
import math
a, b, c = map(float, input().split())
s = a * b * math.sin(math.radians(c)) / 2
l = a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(c)))
h = b * math.sin(math.radians(c))
print(s)
print(l)
print(h)
|
import sys
def GcdLCM():
for line in sys.stdin:
x,y=map(int,line.split())
if x==None:
break
gcd = Gcd(x,y)
lcm = int(x*y/gcd)
print("{} {}".format(gcd,lcm))
def Gcd(x,y):
while x!=0:
x,y=y%x,x
return y
GcdLCM()
| 0 | null | 89,279,926,620 | 30 | 5 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8,i8,i8[:],i8[:]), cache=True)
def main(H,N,A,B):
INF = 1<<30
dp = np.full(H+1,INF,np.int64)
dp[0] = 0
for i in range(N):
for h in range(A[i],H):
dp[h] = min(dp[h],dp[h-A[i]]+B[i])
dp[H] = min(dp[H],min(dp[H-A[i]:H]+B[i]))
ans = dp[-1]
return ans
H, N = map(int, input().split())
A = np.zeros(N,np.int64)
B = np.zeros(N,np.int64)
for i in range(N):
A[i],B[i] = map(int, input().split())
print(main(H,N,A,B))
|
N = int(input())
eList = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
n = N
mod = N
numList = []
while n > 0:
n, mod = divmod(n,26)
if mod != 0:
numList.insert(0, mod - 1)
else:
numList.insert(0, 25)
n -= 1
ans =''
for num in numList:
ans += eList[num]
print(ans)
| 0 | null | 46,289,322,485,418 | 229 | 121 |
import math
def main():
A, B = map(int, input().split())
a_min = int(math.ceil(A / 0.08))
a_max = int(math.floor((A+1) / 0.08)) - 1
b_min = 10 * B
b_max = 10 * (B+1) - 1
if a_max < b_min or b_max < a_min:
print(-1)
else:
print(max([a_min, b_min]))
if __name__ == '__main__':
main()
|
a, b = map(int, input().split())
tmp_a = int((a / 0.08) // 1)
tmp_b = int((b / 0.10) // 1)
check = True
# print(tmp_a, tmp_b)
for i in range(min(tmp_a,tmp_b), max(tmp_a + 1, tmp_b + 1) + 1):
if int((i * 0.08)//1) == a and int((i * 0.10)//1) == b:
print(i)
check = False
break
if check:
print(-1)
| 1 | 56,658,919,092,690 | null | 203 | 203 |
a = int(input())
result = a + a**2 + a**3
print(result)
|
# https://atcoder.jp/contests/abc172/tasks/abc172_a
def calc(a):
return a + (a ** 2) + (a ** 3)
a = int(input())
print(calc(a))
| 1 | 10,250,751,754,760 | null | 115 | 115 |
a,b,c,d=map(int,input().split())
X=[a,b]
Y=[c,d]
ans=-10**30
for x in X:
for y in Y:
if ans<x*y:
ans=x*y
print(ans)
|
a,b,c,d=map(int,input().split())
ans=-10**20
if ans<a*c:
ans=a*c
if ans<a*d:
ans=a*d
if ans<b*c:
ans=b*c
if ans<b*d:
ans=b*d
print(ans)
| 1 | 3,070,430,527,360 | null | 77 | 77 |
from collections import deque
N = int(input())
L = deque()
for i in range(N):
C= input().split()
if C[0] == "insert":
L.appendleft(C[1])
elif C[0] == "delete":
try:
L.remove(C[1])
except ValueError:
pass
elif C[0] == "deleteFirst":
L.popleft()
elif C[0] == "deleteLast":
L.pop()
print(" ".join(L))
|
from collections import deque
n = int(input())
dll = deque([])
for _ in range(n):
p = input().split()
if p[0] == "insert":
dll.appendleft(p[1])
elif p[0] == "delete":
try:
dll.remove(p[1])
except:
pass
elif p[0] == "deleteFirst":
dll.popleft()
else:
dll.pop()
print(" ".join(dll))
| 1 | 52,246,953,318 | null | 20 | 20 |
N,A,B = map(int,input().split())
if A%2 != 0 and B%2 == 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
elif A%2 == 0 and B%2 != 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
else:
ans = (B-A)//2
print(ans)
|
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,u,v = MI()
Graph = [[] for _ in range(N+1)]
for i in range(N-1):
a,b = MI()
Graph[a].append(b)
Graph[b].append(a)
dist_T = [-1]*(N+1) # uからの最短距離
dist_A = [-1]*(N+1) # vからの最短距離
dist_T[u] = 0
dist_A[v] = 0
from collections import deque
q1 = deque([u])
q2 = deque([v])
while q1:
n = q1.pop()
for d in Graph[n]:
if dist_T[d] == -1:
dist_T[d] = dist_T[n] + 1
q1.appendleft(d)
while q2:
n = q2.pop()
for d in Graph[n]:
if dist_A[d] == -1:
dist_A[d] = dist_A[n] + 1
q2.appendleft(d)
ans = 0
for i in range(1,N+1):
if dist_T[i] < dist_A[i]:
ans = max(ans,dist_A[i]-1)
print(ans)
| 0 | null | 113,244,374,561,710 | 253 | 259 |
r, c = map(int, input().split())
array = []
for a in range(r):
row = list(map(int, input().split()))
array.append(row)
coltotal = [0 for i in range(c + 1)]
for a in range(r):
array[a].append(sum(array[a]))
for x in range(c + 1):
coltotal[x] += array[a][x]
array.append(coltotal)
for a in range(r + 1):
print(*array[a])
|
l = input().split()
r = int(l[0])
c = int(l[1])
a = []
for i in range(r):
a.append(list(map(int, input().split())))
for i in range(len(a)):
a[i].insert(c, sum(a[i]))
b = []
a.append(b)
for i in range(c): #4
s = 0
for j in range(r): #5
s += a[j][i]
a[-1].append(s)
a[-1].append(sum(a[-1]))
for i in range(len(a)):
print(*a[i])
| 1 | 1,370,934,557,148 | null | 59 | 59 |
n, m, l = map(int, input().split())
matrix_a = [list(map(int, input().split())) for i in range(n)]
matrix_b = [list(map(int, input().split())) for i in range(m)]
mul_matrix_a_b = [[sum([matrix_a[i][k] * matrix_b[k][j] for k in range(m)]) for j in range(l)] for i in range(n)]
for result in mul_matrix_a_b:
print(*result)
|
from itertools import combinations_with_replacement
def main():
N, M, Q = map(int, input().split())
qs = [list(map(int,input().split())) for _ in range(Q)]
seq = [i for i in range(1,M+1)]
C = combinations_with_replacement(seq, N)
max_score = 0
for A in C:
A = sorted(A)
score = 0
for q in qs:
if A[q[1]-1] - A[q[0]-1] == q[2]:
score += q[3]
max_score = max(score, max_score)
print(max_score)
if __name__ == '__main__':
main()
| 0 | null | 14,592,004,510,622 | 60 | 160 |
import itertools
import math
#print(3 & (1 << 0))
def main():
N = int(input())
items = [i+1 for i in range(N)]
locations=[]
for i in range(N):
locations.append(list(map(int, input().split())))
paths =list(itertools.permutations(items))
sum = 0
for path in paths: # path = [1,2,3,4,5]
for i in range(len(path)-1):
from_idx = path[i] -1
to_idx = path[i+1] -1
xdiff= locations[from_idx][0] - locations[to_idx][0]
ydiff= locations[from_idx][1] - locations[to_idx][1]
sum = sum + math.sqrt(xdiff**2 + ydiff**2)
print( sum / len(paths))
main()
|
# -*- coding: utf-8 -*-
def main():
from itertools import permutations
from math import sqrt
n = int(input())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
xi, yi = map(int, input().split())
x[i] = xi
y[i] = yi
path = list(permutations(range(n)))
path_count = len(path)
length = 0
for p in path:
for i, j in zip(p, p[1:]):
length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
print(length / path_count)
if __name__ == '__main__':
main()
| 1 | 148,578,830,758,112 | null | 280 | 280 |
import sys
from sys import stdin
input = stdin.readline
n,k = (int(x) for x in input().split())
w = [int(input()) for i in range(n)]
# 最大積載Pのトラックで何個の荷物を積めるか
def check(P):
i = 0
for j in range(k):
s = 0
while s + w[i] <= P:
s += w[i]
i += 1
if i == n:
return n
return i
def solve():
left = 0
right = 100000 * 10000 #荷物の個数 * 1個当たりの最大重量
while right - left > 1 :
mid = (right + left)//2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
return right
print(solve())
|
import time
n, k = map(int, input().split())
w = [0] * n
for i in range(n):
w[i] = int(input())
def check(p):
remain_track = k - 1
remain_p = p
for a in range(n):
if w[a] > p:
return False
if remain_p >= w[a]:
remain_p -= w[a]
else:
if remain_track == 0:
return False
else:
remain_track -= 1
remain_p = p - w[a]
# print(a, w[a], remain_p, remain_track)
return True
next = 10 ** 9
prev = next
for i in range(200):
if check(next):
prev = next
next = next // 2
else:
next = (next + prev) // 2
print(prev)
| 1 | 86,378,269,792 | null | 24 | 24 |
n,k = map(int,input().split())
P = 10**9+7
ans = 1
nCl = 1
n1Cl = 1
for l in range(1,min(k+1,n)):
nCl = nCl*(n+1-l)*pow(l,P-2,P)%P
n1Cl = n1Cl*(n-l)*pow(l,P-2,P)%P
ans = (ans+nCl*n1Cl)%P
print(ans)
|
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
if n < r:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
def main():
n, k = map(int,input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 6)
ans = 0
if n - 1 <= k:
ans = comb(n + n - 1, n)
else:
ans = 1
for i in range(1,k+1):
ans += comb(n,i) * comb(n - 1, i)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| 1 | 66,959,363,853,580 | null | 215 | 215 |
class Dice():
def __init__(self, *n):
self.rolls = n
def spin(self, order):
if order == "N":
self.rolls = [
self.rolls[1],
self.rolls[5],
self.rolls[2],
self.rolls[3],
self.rolls[0],
self.rolls[4]
]
if order == "E":
self.rolls = [
self.rolls[3],
self.rolls[1],
self.rolls[0],
self.rolls[5],
self.rolls[4],
self.rolls[2]
]
if order == "S":
self.rolls = [
self.rolls[4],
self.rolls[0],
self.rolls[2],
self.rolls[3],
self.rolls[5],
self.rolls[1]
]
if order == "W":
self.rolls = [
self.rolls[2],
self.rolls[1],
self.rolls[5],
self.rolls[0],
self.rolls[4],
self.rolls[3]
]
return self.rolls[0]
d = Dice(*[int(i) for i in input().split()])
for order in list(input()):
l = d.spin(order)
print(l)
|
class dice:
men = [0] * 7
def __init__(self, li):
self.men = [0] + li
def move(self, h):
if h == "N":
t = self.men[1]
self.men[1] = self.men[2]
self.men[2] = self.men[6]
self.men[6] = self.men[5]
self.men[5] = t
elif h == "S":
t = self.men[1]
self.men[1] = self.men[5]
self.men[5] = self.men[6]
self.men[6] = self.men[2]
self.men[2] = t
elif h == "W":
t = self.men[1]
self.men[1] = self.men[3]
self.men[3] = self.men[6]
self.men[6] = self.men[4]
self.men[4] = t
elif h == "E":
t = self.men[1]
self.men[1] = self.men[4]
self.men[4] = self.men[6]
self.men[6] = self.men[3]
self.men[3] = t
saikoro = dice(list(map(int, input().split())))
for s in input():
saikoro.move(s)
print(saikoro.men[1])
| 1 | 228,592,392,548 | null | 33 | 33 |
x,y=map(int,input().split())
ans=0
if x==1:
ans=ans+300000
if y==1:
ans=ans+300000
if x==2:
ans=ans+200000
if y==2:
ans=ans+200000
if x==3:
ans=ans+100000
if y==3:
ans=ans+100000
if x==1 and y==1:
ans=ans+400000
print(ans)
|
K=int(input())
i=0
if K%2==0 or K%5==0:
print('-1')
else:
for d in range(K):
i=(10*i+7)%K
if i==0:
print(d+1)
break
| 0 | null | 73,216,859,175,710 | 275 | 97 |
n=int(input())
s,t=input().split()
ans=""
for i,j in zip(list(s),list(t)):ans+=i+j
print(ans)
|
k = 2 *10**5
mod = 10**9+7
n, a, b = map(int,input().split())
modinv_table = [-1]*(k+1)
for i in range(1,k+1):
modinv_table[i] = pow(i,-1,mod)
def binomial_coefficients(n,k):
ans = 1
for i in range(k):
ans *= n-i
ans *= modinv_table[i+1]
ans %= mod
return ans
print((pow(2,n,mod)-binomial_coefficients(n,a)-binomial_coefficients(n,b)-1)%mod)
| 0 | null | 88,839,217,441,312 | 255 | 214 |
import itertools
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
N = [i for i in range(1,n+1)]
N_dict = {v:(i+1) for i,v in enumerate(itertools.permutations(N, n))}
#print(N_dict)
print(abs(N_dict[P] - N_dict[Q]))
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, *a = map(int, read().split())
allxor = a[0]
for ae in a[1:]:
allxor = allxor ^ ae
for ae in a:
print(allxor ^ ae, end = ' ')
if __name__ == '__main__':
main()
| 0 | null | 56,654,680,093,132 | 246 | 123 |
# coding: utf-8
# 標準入力 <int>
K = int(input())
k = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
kl = k.split(", ")
print(kl[K-1])
|
MOD = 10**9 + 7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2,200010):
fac[k] = (fac[k-1]*k)%MOD
inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
finv[k] = (finv[k - 1] * inv[k]) % MOD;
def nCr(n,r):
return (fac[n]*finv[r]*finv[n-r])%MOD
N, K = map(int,input().split())
A = sorted(list(map(int,input().split())))
m = 0
for k in range(N-K+1):
m += A[k]*nCr(N-k-1,K-1)
m %= MOD
A = A[::-1]
M = 0
for k in range(N-K+1):
M += A[k]*nCr(N-k-1,K-1)
M %= MOD
print(M-m if M>=m else M-m+MOD)
| 0 | null | 72,541,674,641,392 | 195 | 242 |
A = int(input())
B = int(input())
print(*(set([1,2,3])-set([A,B])))
|
print(*set([input(),input()])^set([*'123']))
| 1 | 110,447,646,624,644 | null | 254 | 254 |
N = int(input())
ct = []
for i in range(N):
ct.append([int(i) for i in input().split()])
dist = 0
for a in ct:
for b in ct:
dist += (abs(a[0] - b[0])**2 +abs(a[1] - b[1])**2)**0.5
print(dist/N)
|
import itertools
n = int(input())
lis = []
for i in range(n):
x, y = map(int, input().split())
lis.append((x, y))
LIS = [i for i in range(n)]
big_lis = list(itertools.permutations(LIS))
L = len(big_lis)
def sai(i, j):
return (lis[A[i + 1]][j] - lis[A[i]][j]) ** 2
keep = 0
ANS = 0
for i in range(L):
A = list(big_lis[i])
keep = 0
for j in range(n - 1):
keep += (sai(j, 0) + sai(j, 1)) ** (1 / 2)
ANS += keep
print(ANS / L)
| 1 | 148,611,130,878,074 | null | 280 | 280 |
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
sum = 0
for i in range(n):
for j in range(i+1,n):
sum += ((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
print(2*sum/n)
|
print("Yes" if len(set(map(int,input().split())))==1 else "No")
| 0 | null | 116,301,908,199,008 | 280 | 231 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
from fractions import gcd
n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
cnt = [0] * n
for i, elem in enumerate(a):
x = elem
c = 0
while x % 2 == 0:
x //= 2
c += 1
cnt[i] = c
ans = 0
if len(set(cnt)) == 1:
lcm = a[0]
for elem in a[1:]:
lcm = (lcm * elem) // gcd(lcm, elem)
ans = (m + (lcm // 2)) // lcm
print(ans)
if __name__ == '__main__':
main()
|
import math
n,m=map(int,input().split())
a=list(map(int,input().split()))
half_a=[ai//2 for ai in a]
# print(half_a)
lcm=half_a[0]
for i in range(n-1):
a,b=lcm,half_a[i+1]
lcm=a*b//math.gcd(a,b)
# print(lcm)
pow_cnt=0
tmp=half_a[0]
while tmp%2==0:
pow_cnt+=1
tmp=tmp//2
flag=True
for ai in half_a[1:]:
if ai%(2**pow_cnt)!=0:
flag=False
break
elif ai%(2**(pow_cnt+1))==0:
flag=False
break
if flag:
print(math.ceil(m//lcm/2))
else:
print(0)
| 1 | 102,245,306,417,716 | null | 247 | 247 |
A, B =map(float,input().split())
A = int(A)
B = int(B*100+0.5)
ans = A*B//100
print(ans)
|
N,K,S = map(int,input().split())
if S != 10**9:
for _ in range(K):
print(S,end = ' ')
for _ in range(N - K):
print(10**9,end = ' ')
else:
for _ in range(K):
print(10**9,end = ' ')
for _ in range(N - K):
print(1,end = ' ')
print()
| 0 | null | 53,834,448,212,450 | 135 | 238 |
#coding:utf-8
#1_1_B
def gcd(x, y):
while x%y != 0:
x, y = y, x%y
return y
x, y = map(int, input().split())
print(gcd(x, y))
|
n = list(input())
tmp = 0
for i in n:
tmp += int(i) % 9
ans = "Yes" if tmp % 9 == 0 else "No"
print(ans)
| 0 | null | 2,228,108,701,428 | 11 | 87 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
for i in range(n):
self.parents[i] = i
# 要素xが所属するグループの根を返す
def root(self, x) -> int:
if self.parents[x] == x:
return x
else:
self.parents[x] = self.root(self.parents[x])
return self.parents[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
elif x > y:
u.parents[x] = y
elif x < y:
u.parents[y] = x
def same(self, x, y) -> bool:
return self.root(x) == self.root(y)
n, m = map(int, input().split())
cnt = n
u = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
if u.same(a-1, b-1):
continue
else:
u.unite(a-1, b-1)
cnt -= 1
if cnt > 0:
print(cnt-1)
else:
print(cnt)
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
a.sort()
if n == 1:
print(0)
exit()
fac = [1] * (n + 1)
inv = [1] * (n + 1)
def COMinit():
for j in range(1, n + 1):
fac[j] = fac[j - 1] * j % mod
inv[n] = pow(fac[n], mod - 2, mod)
for j in range(n - 1, -1, -1):
inv[j] = inv[j + 1] * (j + 1) % mod
def comb2(n, r):
if r > n or n < 0 or r < 0:
return 0
return fac[n] * inv[n - r] * inv[r] % mod
COMinit()
ans = 0
for i in range(n):
if k != 1:
x = comb2(n-1-i, k-1)
ans = (ans - a[i]*x % mod) % mod
ans = (ans + a[-1-i]*x % mod) % mod
print(ans%mod)
| 0 | null | 49,270,658,621,180 | 70 | 242 |
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
x = 1<< i
l = len([1 for j in a if j & x])
ans += x * l * (n-l) % mod
ans %= mod
print(ans)
|
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
cnt0 = 0
cnt1 = 0
for a in A:
if (a>>i) & 1 == 0:
cnt0 += 1
else:
cnt1 += 1
ans += cnt0 * cnt1 * (2 ** i)
ans %= mod
print(ans)
| 1 | 122,386,524,895,152 | null | 263 | 263 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
numbers = input().split(' ')
height = int(numbers[0])
width = int(numbers[1])
print(height * width ,height * 2 + width * 2)
return
if __name__ == '__main__':
main()
|
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):
for j in range(n):
if T[i] == S[j]:
count += 1
break
print(count)
| 0 | null | 191,690,560,582 | 36 | 22 |
str0 = raw_input()
q = int(raw_input())
for i in xrange(q):
# print "###########################"
# print "str0 = " + str0
line = raw_input().split(" ")
temp = str0[int(line[1]):int(line[2])+1]
if line[0] == "print":
print temp
elif line[0] == "reverse":
temp2 = []
# print "temp = " + temp
for j in xrange(len(temp)):
temp2.append(temp[len(temp) - j - 1])
str0 = str0[:int(line[1])] + "".join(temp2) + str0[int(line[2]) + 1:]
# print "str0 = " + str0
elif line[0] == "replace":
str0 = str0[:int(line[1])] + line[3] + str0[int(line[2]) + 1:]
# print "str0 = " + str0
|
text = input()
q = int(input())
for _ in range(q):
ops = input().split()
if len(ops) == 3:
op, a, b = ops
else:
op, a, b, p = ops
a = int(a)
b = int(b)
if op == 'print':
print(text[a:b+1])
elif op == 'reverse':
text = text[:a] + ''.join(reversed(text[a:b+1])) + text[b + 1:]
else:
text = text[:a] + p + text[b + 1:]
| 1 | 2,071,995,195,760 | null | 68 | 68 |
import math
n = int(input())
answer = (n - math.floor(n / 2)) / n
print(answer)
# nums = list(range(1, n + 1))
#
# odds = [x for x in nums if x % 2 == 1]
#
# if len(nums) % 2 == 0:
# print(0.5)
# else:
# print(len(odds) / len(nums))
|
#142-A
N = int(input())
D = []
for i in range(1,N+1):
D.append(i)
#print(D)
cnt = 0
for j in D:
if j % 2 != 0:
cnt += 1
#print(cnt)
print(cnt / len(D))
| 1 | 177,600,471,228,640 | null | 297 | 297 |
s = list(input())
k = int(input())
n = len(s)
ans = 0
# すべて同じ文字の場合
if s == [s[0]] * n:
print((n*k)//2)
exit(0)
# 先頭と末尾が異なる場合
i = 1
while i < n:
if s[i-1] == s[i]:
t = 2
i+=1
while i < n and s[i-1] == s[i]:
t+=1
i+=1
ans += (t//2)*k
i+=1
if s[0] != s[-1]:
print(ans)
exit(0)
# 先頭と末尾が一致する場合
# まず不一致の場合と同様に数えて、左右端の連続長さを数える
# 連結したとき、左右の1ブロックのみはそのまま数えられる
# 残りのk-1ブロックは、左右がつながった形で数えられる
i = 1
left = 1
right = 1
for i in range(n):
if s[i] == s[i+1]:
left += 1
else:
break
for i in range(n-1, -1, -1):
if s[i] == s[i-1]:
right += 1
else:
break
if s[0] == s[-1]:
ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2)
print(ans)
|
S=input()
N=len(S)
K=int(input())
s="".join((S,S))
cnt1=0
cnt2=0
buf=0
piv=""
if len(set(S))!=1:
for i in range(N):
if S[i]==piv:
buf=buf+1
else:
piv=S[i]
cnt1=cnt1+(buf+1)//2
buf=0
cnt1=cnt1+(buf+1)//2
buf=0
piv=""
for i in range(2*N):
if s[i]==piv:
buf=buf+1
else:
piv=s[i]
cnt2=cnt2+(buf+1)//2
buf=0
#print(buf)
cnt2 = cnt2 + (buf + 1) // 2
x = cnt2 - cnt1
print(cnt1 + (K - 1) * x)
else:
print((len(S)*K)//2)
| 1 | 175,761,492,554,638 | null | 296 | 296 |
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def dfs(H,W,L):
d=0
c=True
if L[0][0]==False:
d=1
c=False
q=deque([(d*10000,c)])
dxs=((0,1),(1,0))
visited=[False]*10000
while len(q):
#print(q)
dxy,c=q.popleft()#ここをpopleftにすると幅優先探索BFSになる
d,xy=divmod(dxy,10000)
x,y=divmod(xy,100)
if visited[xy]: continue
visited[xy]=True
if x==H-1 and y==W-1:
return d
for dx in dxs:
nx=x+dx[0]
ny=y+dx[1]
if nx>=H or ny>=W:
continue
if visited[nx*100+ny]:continue
if L[nx][ny] or c==False:
q.appendleft((d*10000+nx*100+ny,L[nx][ny]))
else:
q.append(((d+1)*10000+nx*100+ny,False))
def main():
mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
H,W = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
L = list(list(input()) for i in range(H)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
#Lt=[[True]*H for _ in range(W)]
for i in range (H):
for j in range(W):
if L[i][j]=='#':
L[i][j]=False
else:
L[i][j]=True
ans=dfs(H,W,L)
print(ans)
if __name__ == "__main__":
main()
|
n=int(input())
if n%2==0:
print('0.5000000000')
elif n==1:
print('1.000000000')
else:
print((n//2 + 1)/n)
| 0 | null | 113,175,988,504,738 | 194 | 297 |
def main():
a, b = map(int, input().split())
maxv = int((101 / 0.1) - 1)
for i in range(maxv+1):
if (i*8//100 == a) and (i*10//100 == b):
print(i)
exit()
print(-1)
if __name__ == '__main__':
main()
|
r = list(map(float, input().split()))
print('{0:f}'.format(((r[2] - r[0]) ** 2 + (r[3] - r[1]) ** 2) ** 0.5))
| 0 | null | 28,126,053,233,060 | 203 | 29 |
n=int(input())
p=10**9+7
A=list(map(int,input().split()))
binA=[]
for i in range(n):
binA.append(format(A[i],"060b"))
lis=[0 for i in range(60)]
for binAi in binA:
for j in range(60):
lis[j]+=int(binAi[j])
binary=[0 for i in range(60)]
for i in range(n):
for j in range(60):
if binA[i][j]=="0":
binary[j]+=lis[j]
else:
binary[j]+=n-lis[j]
binary[58]+=binary[59]//2
binary[59]=0
explis=[1]
for i in range(60):
explis.append((explis[i]*2)%p)
ans=0
for i in range(59):
ans=(ans+binary[i]*explis[58-i])%p
print(ans)
|
import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int,readline().split()))
DIV = 10 ** 9 + 7
# 各桁の1と0の数を数えて、((1の数) * (0の数)) * (2 ** i桁目(1桁目を0とする))を数える
K = max(A) # 最も大きい数が0になるまでループ
ans = 0
j = 0
while K:
one = 0
for i in range(len(A)):
if (A[i] >> j) & 1:
one += 1
ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV)
ans %= DIV
j += 1
K >>= 1
print(ans)
| 1 | 122,960,584,783,608 | null | 263 | 263 |
class Dice:
def __init__(self):
self.up = 1
self.under = 6
self.N = 5
self.W = 4
self.E = 3
self.S = 2
def roll(self, d):#d => direction
if d == "N":
tmp = self.up
self.up = self.S
self.S = self.under
self.under = self.N
self.N = tmp
elif d == "W":
tmp = self.up
self.up = self.E
self.E = self.under
self.under = self.W
self.W = tmp
elif d == "E":
tmp = self.up
self.up = self.W
self.W = self.under
self.under = self.E
self.E = tmp
elif d == "S":
tmp = self.up
self.up = self.N
self.N = self.under
self.under = self.S
self.S = tmp
def getUpward(self):
return self.up
def setRoll(self,up,under,N,W,E,S):
self.up = up
self.under = under
self.N = N
self.W = W
self.E = E
self.S = S
def rotate(self):#crockwise
tmp = self.S
self.S = self.E
self.E = self.N
self.N = self.W
self.W = tmp
def getE(self, up, S):
'''
:param up:num
:param S: num
:return: num
'''
count = 0
while True:
if self.up == up:
break
if count != 3:
self.roll("N")
count += 1
else:
self.roll("E")
while True:
if self.S == S:
break
self.rotate()
return self.E
myd = Dice()
myd.up, myd.S, myd.E, myd.W, myd.N, myd.under = map(int,input().split())
n = int(input())
for i in range(n):
up, S = map(int,input().split())
print(myd.getE(up,S))
|
#ITP1_11-B Dice 2
rep=[
[1,2,4,3,1],
[2,0,3,5,2],
[0,1,5,4,0],
[0,4,5,1,0],
[0,2,5,3,0],
[1,3,4,2,1]
]
d = input().split(" ")
q = int(input())
dic={}
for i in range(6):
dic.update({d[i]:i})
for i in range(q):
a,b = input().split(" ")
for j in range(4):
top=dic[a]
front = dic[b]
if(d[rep[top][j]]==d[front]):
print(d[rep[top][j+1]])
| 1 | 255,611,611,452 | null | 34 | 34 |
n,m,x=map(int,input().split())
money=[]
skill=[]
for i in range(n):
a=list(map(int,input().split()))
money+=[a[0]]
skill+=[a[1:m+1]]
ans=-1
for i in range(2**n):
total=0
learn=[0]*m
for j in range(n):
if (i>>j)&1:
total+=money[j]
for a in range(m):
learn[a]+=skill[j][a]
if len([i for i in learn if i>=x])==m:
if ans==-1:
ans=total
elif ans>total:
ans=total
print(ans)
|
"""
AtCoder :: Beginner Contest 175 :: C - Walking Takahashi
https://atcoder.jp/contests/abc175/tasks/abc175_c
"""
import sys
def solve(X, K, D):
"""Solve puzzle."""
# print('solve X', X, 'K', K, 'D', D)
if D == 0:
return X
X = abs(X)
soln = abs(X - (K * D))
steps_to_zero = abs(X) // D
# print('steps to zero', steps_to_zero, K - steps_to_zero)
# print('to zero', abs(X - (steps_to_zero * D)))
# Undershoot or get directly on to zero.
if steps_to_zero <= K and ((K - steps_to_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_to_zero * D)))
# Overshoot by one step
steps_past_zero = steps_to_zero + 1
# print('steps past zero', steps_past_zero, K - steps_past_zero)
# print('past zero', abs(X - (steps_past_zero * D)))
if steps_past_zero <= K and ((K - steps_past_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_past_zero * D)))
# Overshoot and return by one
steps_back_zero = steps_past_zero + 1
# print('steps back zero', steps_back_zero, K - steps_back_zero)
# print('back zero', abs(X - (steps_back_zero * D)))
if steps_back_zero <= K and ((K - steps_back_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_back_zero * D)))
return soln
def main():
"""Main program."""
X, K, D = (int(i) for i in sys.stdin.readline().split())
print(solve(X, K, D))
if __name__ == '__main__':
main()
| 0 | null | 13,753,673,377,990 | 149 | 92 |
s = input()
d = [[0]*2 for _ in range(len(s)+1)]
count_r = 0
count_l = 0
ans = 0
for i in range(len(s)):
if s[i] == "<":
d[i+1][0] = d[i][0]+1
else:
d[i+1][0] = 0
for i in range(len(s)-1, -1, -1):
if s[i] == ">":
d[i][1] = d[i+1][1]+1
else:
d[i][1] = 0
for i in range(len(s)+1):
ans += max(d[i])
print(ans)
|
import collections
s = str(input())
k = int(input())
ans = 0
#if s[0] == s[-1]:
# ans += k
tmp = ''
tmp_num = 0
check = ''
check_num = 0
if len(collections.Counter(s).keys()) == 1:
ans = len(s)*k//2
else:
for i, w in enumerate(s):
if i == 0:
tmp += w
tmp_num += 1
continue
if tmp[-1] == w:
tmp += w
tmp_num += 1
elif tmp[-1] != w:
if check_num == 0:
check = tmp
check_num = 1
ans += (tmp_num // 2) * k
#print('ans', ans)
tmp = w
tmp_num = 1
if i == len(s)-1:
if len(tmp) == 1:
if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
ans += k-1
else:
#print(check, tmp)
if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
ans += k-1
ans += (tmp_num // 2) * k
#print('last', ans)
print(ans)
| 0 | null | 165,942,106,750,948 | 285 | 296 |
N, M = map(int, input().split())
S = list(reversed(input()))
ans = []
cur = 0
while cur < N:
for m in range(M, 0, -1):
ncur = cur + m
if ncur <= N and S[ncur] == '0':
ans.append(m)
cur = ncur
break
else:
print(-1)
exit()
print(*reversed(ans))
|
s = input()
a = int((len(s)-1)/2)
b = int((len(s)+3)/2)
r = ''.join(reversed(s[b-1:]))
if s[:a]== s[:a:-1] and s[b-1:]== r:
print('Yes')
else:
print('No')
| 0 | null | 92,843,360,466,910 | 274 | 190 |
def has_three(a):
while a != 0:
if a % 10 == 3:
return True
else:
a /= 10
return False
result = list()
n = int(raw_input())
for i in range(1, n + 1):
if i % 3 == 0:
result.append(i)
elif has_three(i):
result.append(i)
print(" " + " ".join(str(i) for i in result))
|
def solve():
ans = 10**12
for i in range(1, int(N**0.5)+1):
if N % i == 0:
ans = min(ans, i + (N//i) -2)
if N == 2:
print(1)
elif N == 3:
print(2)
else:
print(ans)
if __name__ == "__main__":
N = int(input())
solve()
| 0 | null | 81,181,007,951,680 | 52 | 288 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
a, b = input().split()
a = int(a)
b = int(b[0]+b[2:4])
print(a*b//100)
if __name__=='__main__':
main()
|
import sys
inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())
n = inint()
A = inintl()
cnt = 1
ans = 0
for a in A:
if a != cnt:
ans += 1
continue
else:
cnt += 1
if cnt == 1:
if ans == 0:
print(ans)
else:
print(-1)
else:
print(ans)
| 0 | null | 65,363,011,745,528 | 135 | 257 |
user_input = input()
ascci_value = ord(user_input)
if ascci_value in range(97, 123):
print('a')
else:
print('A')
|
n=input()
if n==n.upper():
print("A")
else:
print("a")
| 1 | 11,280,685,517,088 | null | 119 | 119 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
ok=10**15
ng=-1
while ok-ng>1:
check=(ok+ng)//2
cnt=0
for i in range(n):
cnt+=(max(0,a[i]-check//f[i]))
if cnt > k:ng = (ok+ng)//2
else: ok = (ok+ng)//2
print(ok)
|
import sys
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
h,l=max(a[i]*f[i] for i in range(n))+1,0
if sum(a)<=k: print(0);sys.exit()
while h-l>1:
m=(h+l)//2
practice=sum(max(0,a[i]-m//f[i]) for i in range(n))
if practice<=k: h=m
else: l=m
print(h)
| 1 | 165,109,334,878,460 | null | 290 | 290 |
from collections import defaultdict
from math import gcd
mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zero_zero += 1
elif a == 0:
zero += 1
elif b == 0:
inf += 1
else:
div = gcd(a, b)
a //= div
b //= div
if b < 0:
a *= -1
b *= -1
key = (a, b)
fishes[key] += 1
def get_bad_pair(fish):
a, b = fish
if a < 0:
a *= -1
b *= -1
return (-b, a)
ans = 1
counted_key = set()
for fish_key, count in fishes.items():
if fish_key in counted_key:
continue
bad_pair = get_bad_pair(fish_key)
if bad_pair in fishes:
pair_count = fishes[bad_pair]
pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
counted_key.add(bad_pair)
else:
pattern = pow(2, count, mod)
ans = ans * pattern % mod
ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
ans += zero_zero
ans -= 1
print(ans % mod)
|
# -*- coding: utf-8 -*-
from fractions import Fraction
from collections import Counter
import math
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class Mod:
def __init__(self, m):
self.m = m
def add(self, a, b):
return (a + b) % self.m
def sub(self, a, b):
return (a - b) % self.m
def mul(self, a, b):
return ((a % self.m) * (b % self.m)) % self.m
def div(self, a, b):
return self.mul(a, pow(b, self.m-2, self.m))
def pow(self, a, b):
return pow(a, b, self.m)
def fract(a, b):
if a == 0 and b == 0:
return (0, 0)
if b == 0:
return (1, 0)
f = Fraction(a, b)
return f.numerator, f.denominator
@mt
def slv(N, AB):
adb = Counter()
for a, b in AB:
k = fract(a, b)
adb[k] += 1
M = Mod(1000000007)
ans = 1
done = {(0, 0)}
for k, v in adb.items():
if k in done:
continue
a, b = k
kk = fract(-b, a)
done.add(k)
done.add(kk)
n = adb[kk]
t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
ans = M.mul(ans, t)
ans = M.add(ans, adb[(0, 0)])
return M.sub(ans, 1)
def main():
N = read_int()
AB = [read_int_n() for _ in range(N)]
print(slv(N, AB))
if __name__ == '__main__':
main()
| 1 | 20,929,582,731,930 | null | 146 | 146 |
S, T = [input() for _ in range(2)]
count = 0
for i, j in zip(S, T):
count += i != j
print(count)
|
# -*- coding: utf-8 -*-
char = input()
print(char.swapcase())
| 0 | null | 5,987,898,261,048 | 116 | 61 |
def resolve():
S = input()
print("Yes" if S[2]==S[3] and S[4] == S[5] else "No")
if '__main__' == __name__:
resolve()
|
S = input()
if (S[2] == S[3]) and (S[4] == S[5]):
print('Yes')
else:
print('No')
| 1 | 42,369,903,547,360 | null | 184 | 184 |
n = int(input())
for i in range(1,n+1):
if i % 3 == 0 or i % 10 == 3:
print(" {}".format(i), end='')
else:
x = i
while True:
x = x // 10
if x == 0:
break
elif x % 10 == 3:
print(" {}".format(i), end='')
break
print("")
|
import sys
input = sys.stdin.readline
from collections import *
N = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i+1, N):
ans += d[i]*d[j]
print(ans)
| 0 | null | 85,044,349,482,870 | 52 | 292 |
N = int(input())
G = [[0] * N for _ in range(N)]
time = 0
times = [{'s': 0, 'f': 0} for _ in range(N)]
for _ in range(N):
u, n, *K = map(int, input().split())
for k in K:
G[u - 1][k - 1] = 1
def dfs(u):
global time
time += 1
times[u]['s'] = time
for i in range(N):
if G[u][i] == 1 and times[i]['s'] == 0:
dfs(i)
else:
time += 1
times[u]['f'] = time
for i in range(N):
if times[i]['s'] == 0:
dfs(i)
for i, time in enumerate(times):
print(i + 1, *time.values())
|
N = int(input())
edge = [[] for _ in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
for i in range(N):
t = list(map(int, input().split()))
for j in range(t[1]):
edge[t[0]].append(t[j+2])
#print(1)
def dfs(v, t):
if d[v] == 0:
d[v] = t
t += 1
else:
return t
for nv in edge[v]:
t = dfs(nv, t)
if f[v] == 0:
f[v] = t
t += 1
return t
t = 1
for i in range(1,1+N):
if d[i] == 0:
t = dfs(i, t)
for i in range(1,1+N):
print(i, d[i], f[i])
| 1 | 3,307,040,990 | null | 8 | 8 |
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def main(): #startline-------------------------------------------
n, k, c = map(int, input().split())
def sub(s):
n = len(s)
cur = 0
last = -(c + 1)
res = [0] * (n + 1)
for i in range(n):
if (i - last > c and s[i] == "o"):
cur += 1
last = i
res[i + 1] = cur
return res
s = input()
left = sub(s)
t = s
t = t[::-1]
right = sub(t)
for i in range(n):
if s[i] == "x": continue
if left[i] + right[n - i - 1] < k:
print(i+1)
if __name__ == "__main__":
main() #endline===============================================
|
s = input()
t = input()
flag = True
for i in range(len(s)):
if s[i] != t[i]:
flag = False
if flag == True:
print("Yes")
else:
print("No")
| 0 | null | 31,062,612,103,360 | 182 | 147 |
n, q = map(int , input().split())
queue = []
for _ in range(n):
line = input().split()
queue.append([line[0], int(line[1])])
class my_queue:
def __init__(self, queue):
self.queue = queue
def enqueue(self, item):
self.queue = self.queue + [item]
self.queue.append(item)
def dequeue(self):
if len(self.queue) != 0:
item = self.queue[0]
self.queue = self.queue[1:]
else :
item = None
return item
time = 0
finish_task = []
while(len(queue) != 0):
item = queue.pop(0)
if item == None:
break
elif item[1] <= q:
time += item[1]
finish_task.append([item[0], time])
else :
time += q
queue.append([item[0], item[1] - q])
for item in finish_task:
print(item[0], item[1])
|
a,b,c,k=map(int,open(0).read().split())
for i in' '*k:
if a>=b:b*=2
elif b>=c:c*=2
print('NYoe s'[a<b<c::2])
| 0 | null | 3,439,166,878,368 | 19 | 101 |
while True:
H, W = map(int, input().split())
if H == W == 0:
break
for i in range(H):
for j in range(W):
if (i + j) % 2 == 0:
print('#', end = '')
else:
print('.', end = '')
print()
print()
|
import sys
input = sys.stdin.buffer.readline
def gcd(a: int, b: int) -> int:
"""a, bの最大公約数(greatest common divisor: GCD)を求める
計算量: O(log(min(a, b)))
"""
while b:
a, b = b, a % b
return a
def multi_gcd(array: list) -> int:
"""arrayのGCDを求める"""
n = len(array)
ans = array[0]
for i in range(1, n):
ans = gcd(ans, array[i])
return ans
def make_mindiv_table(n):
mindiv = [i for i in range(n + 1)]
for i in range(2, int(n ** 0.5) + 1):
if mindiv[i] != i:
continue
for j in range(2 * i, n + 1, i):
mindiv[j] = min(mindiv[j], i)
return mindiv
def get_prime_factors(num):
res = []
while mindiv[num] != 1:
res.append(mindiv[num])
num //= mindiv[num]
return res
n = int(input())
a = list(map(int, input().split()))
mindiv = make_mindiv_table(10 ** 6)
set_primes = set()
flag = True
for val in a:
set_ = set(get_prime_factors(val))
for v in set_:
if v in set_primes:
flag = False
set_primes.add(v)
if not flag:
break
else:
print("pairwise coprime")
exit()
gcd_ = multi_gcd(a)
if gcd_ == 1:
print("setwise coprime")
exit()
print("not coprime")
| 0 | null | 2,480,631,257,250 | 51 | 85 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
now = a[0]
for i in range(1,n):
now ^= a[i]
for i in range(n):
print(now ^ a[i])
|
K = int(input())
def make(i):
if int(i) > 3234566667: return
lun.append(int(i))
if i[-1] == "0":
temp = i + "0"
make(temp)
temp = i + "1"
make(temp)
elif i[-1] == "9":
temp = i + "8"
make(temp)
temp = i + "9"
make(temp)
else:
temp = i + str(int(i[-1]) - 1)
make(temp)
temp = i + i[-1]
make(temp)
temp = i + str(int(i[-1]) + 1)
make(temp)
lun = []
for i in range(1, 10):
make(str(i))
lun = sorted(lun)
ans = lun[K - 1]
print(ans)
| 0 | null | 26,223,971,174,190 | 123 | 181 |
import sys
n=int(input())
for i in range(n):
list=input().split()
list=[int(j) for j in list]
list.sort()
if list[0]*list[0]+list[1]*list[1]==list[2]*list[2]:
print("YES")
else:print("NO")
|
a, b, c = map(int, input().split())
k = int(input())
n = 0
while a >= b:
b = b*2
n += 1
while b >= c:
c = c*2
n += 1
if a < b < c and n <= k:
print('Yes')
else:
print('No')
| 0 | null | 3,402,925,406,400 | 4 | 101 |
n,k=map(int,input().split())
h=list(map(int,input().split()))
sum=0
h.sort()
h=h[:n-k]
if n <= k:
print(0)
exit()
else:
for i in h:
sum += i
print(sum)
|
n, k = map(int, input().split())
h = sorted(list(map(int, input().split())))
if k==0: print(sum(h))
else: print(sum(h[:-k]))
| 1 | 79,045,868,374,918 | null | 227 | 227 |
n , m , x = map(int, input().split())
a = list(list(map(int, input().split())) for _ in range(n))
c = []
for i in range(n):
c.append(a[i][0])
a[i].pop(0)
ans = 1000000000
# bit全探索
for i in range(1 << n):
score = [0] * m
tmp = 0
for j in range(n):
if (i >> j) % 2 == 1:
tmp += c[j]
for k in range(m):
score[k] += a[j][k]
if min(score) >= x:
ans = min(ans , tmp)
if(ans == 1000000000):
print(-1)
else:
print(ans)
|
n, m, x = map(int, input().split())
C = []
A = []
for i in range(n):
temp = list(map(int, input().split()))
c = temp[0]
a = temp[1:]
A.append(a)
C.append(c)
ans = 10**18
for i in range(2**n):
s = [0]*m
temp = 0
for j in range(n):
if (i >> j) & 1:
temp += C[j]
for k in range(m):
s[k] += A[j][k]
flag = True
for l in range(m):
if s[l] < x:
flag = False
if flag:
ans = min(ans, temp)
if ans == 10**18:
print(-1)
else:
print(ans)
| 1 | 22,387,187,474,172 | null | 149 | 149 |
a = int(input())
sum = a + (a*a) + (a*a*a)
print(sum)
|
n = int(input())
print(n + n**2 + n**3)
| 1 | 10,237,657,234,112 | null | 115 | 115 |
N,X,Y=map(int,input().split())
d=[0]*N
for i in range(N):
for j in range(i+1,N):d[min(j-i,abs(X-1-i)+abs(Y-1-j)+1)]+=1
for i in d[1:]:print(i)
|
print('Yes') if len(set(input().split()))==1 else print('No')
| 0 | null | 63,451,903,599,602 | 187 | 231 |
n = int(input())
odd = 0
for i in range(1,n+1):
odd += i%2 != 0
print(odd/n)
|
s = list(input())
num = 0
n = len(s)
l = 0
i = 0
while i < n:
if s[i] == '<':
l+=num
num+=1
i+=1
if i==n:
l+=num
else:
cur = 0
while i < n and s[i]=='>':
i+=1
cur+=1
if cur <= num:
l+=num
cur-=1
l+=(cur*(cur+1))//2
num = 0
print(l)
| 0 | null | 166,493,879,415,010 | 297 | 285 |
S = input()
T = input()
n = 0
for s, t in zip(S, T):
if s != t:
n += 1
print(n)
exit()
|
import itertools
n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
cnt=0
num=0
for v in itertools.permutations(xy):
num+=1
for i in range(n-1):
a=(v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2
b=a**0.5
cnt+=b
print(cnt/num)
| 0 | null | 79,680,579,778,220 | 116 | 280 |
n = input()[-1]
if n in '24579':
print('hon')
elif n in '0168':
print('pon')
else:
print('bon')
|
mod = 10**9 + 7
K = int(input())
S = input()
n = len(S)
tmp = pow(26, K, mod)
waru = pow(26, -1, mod)
ans = tmp
for i in range(1, K+1):
tmp = (tmp * 25 * waru)%mod
tmp = (tmp * (i + n -1) * pow(i, -1, mod))%mod
ans = (ans+tmp)%mod
print(ans%mod)
| 0 | null | 16,117,006,141,532 | 142 | 124 |
class Acc2D:
def __init__(self, a):
h, w = len(a), len(a[0])
self.acc2D = self._build(h, w, a)
def _build(self, h, w, a):
ret = [[0] * (w + 1) for _ in range(h + 1)]
for r in range(h):
for c in range(w):
ret[r + 1][c + 1] = ret[r][c + 1] + ret[r + 1][c] - ret[r][c] + (1 if a[r][c] == '#' else 0)
# 末項は必要に応じて改変すること
return ret
def get(self, r1, r2, c1, c2):
# [r1,r2), [c1,c2) : 0-indexed
acc2D = self.acc2D
return acc2D[r2][c2] - acc2D[r1][c2] - acc2D[r2][c1] + acc2D[r1][c1]
def main():
import sys
sys.setrecursionlimit(10 ** 7)
def fill_cake(r1, r2, c1, c2) -> None:
"""ケーキに番号を振る"""
nonlocal piece_number
for r in range(r1, r2):
for c in range(c1, c2):
ret[r][c] = piece_number
piece_number += 1
def cut_cake(r1, r2, c1, c2, rest) -> None:
"""[r1,r2),[c1,c2)の範囲にrest個ケーキがある状態からのカット"""
if rest == 1:
fill_cake(r1=r1, r2=r2, c1=c1, c2=c2)
return # これ以上カットする必要がないので、番号を振る
for r in range(r1 + 1, r2):
piece_count = acc2D.get(r1=r1, r2=r, c1=c1, c2=c2)
if 0 < piece_count < rest: # restが減ることを保証する
cut_cake(r1=r1, r2=r, c1=c1, c2=c2, rest=piece_count)
cut_cake(r1=r, r2=r2, c1=c1, c2=c2, rest=rest - piece_count)
return # ケーキを一つ以上含むように水平カットする
for c in range(c1 + 1, c2):
piece_count = acc2D.get(r1=r1, r2=r2, c1=c1, c2=c)
if 0 < piece_count < rest: # restが減ることを保証する
cut_cake(r1=r1, r2=r2, c1=c1, c2=c, rest=piece_count)
cut_cake(r1=r1, r2=r2, c1=c, c2=c2, rest=rest - piece_count)
return # ケーキを一つ以上含むように垂直カットする
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
acc2D = Acc2D(s)
# usage: acc2D.get(r1,r2,c1,c2)
# ケーキ個数の二次元累積和
ret = [[-1] * w for _ in range(h)]
piece_number = 1
cut_cake(r1=0, r2=h, c1=0, c2=w, rest=k)
for row in ret:
print(*row)
if __name__ == '__main__':
main()
|
N = int(input())
A = list(map(int, input().split()))
humidai = [0]*N
s = A[0]
for i in range(1, N):
if A[i]<s:
humidai[i]=s-A[i]
else:
s = A[i]
print(sum(humidai))
| 0 | null | 73,905,727,378,672 | 277 | 88 |
n = int(input())
a, b = input().split()
s = ""
for i, j in zip(a, b):
s += i + j
print(s)
|
N=int(input())
S,T=map(str,input().split())
def ans148(N:int, S:str, T:str):
newstr=""
for i in range(0,N):
newstr=newstr+S[i]+T[i]
return newstr
print(ans148(N,S,T))
| 1 | 112,082,573,093,400 | null | 255 | 255 |
S=input()
P=input()
I=S*2
if P in I:
print('Yes')
else:
print('No')
|
word = list(map(int,input().split()))
hyoko = list(map(int,input().split()))
road = [0]*word[1]
for i in range(word[1]):
road[i] = list(map(int,input().split()))
tenbo = [1]*word[0]
for j in range(word[1]):
if hyoko[road[j][0]-1] > hyoko[road[j][1]-1]:
tenbo[road[j][0]-1] *= 1
tenbo[road[j][1]-1] = 0
elif hyoko[road[j][0]-1] < hyoko[road[j][1]-1]:
tenbo[road[j][0]-1] = 0
tenbo[road[j][1]-1] *= 1
else:
tenbo[road[j][0]-1] = 0
tenbo[road[j][1]-1] = 0
answer = word[0] - tenbo.count(0)
print(answer)
| 0 | null | 13,290,591,952,192 | 64 | 155 |
x = not(int(input()))
print(int(x))
|
X, Y, A, B, C = map(int, input().split())
tmp = sorted(map(int, input().split()), key=lambda x: -x)[:X] \
+ sorted(map(int, input().split()), key=lambda x: -x)[:Y] \
+ sorted(map(int, input().split()), key=lambda x: -x)
print(sum(sorted(tmp, key=lambda x: -x)[:X + Y]))
| 0 | null | 23,933,784,616,000 | 76 | 188 |
class book:
def __init__(self, C, A):
self.C = C
self.A = A
N, M, X = [int(i) for i in input().split()]
P = []
for i in range(N):
tmp = [int(i) for i in input().split()]
C = tmp.pop(0)
P.append(book(C, tmp))
learn = [0 for i in range(M)]
minc = 10**7
flag = 0
for i in range(2 ** N):
csum = 0
for j in range(M):
learn[j] = 0
for j in range(N):
if ((i >> j) & 1):
csum += P[j].C
for k in range(M):
learn[k] += P[j].A[k]
if min(learn) >= X:
flag = 1
if minc > csum:
minc = csum
if flag == 1:
print(minc)
else:
print(-1)
|
n,m,x=map(int,input().split())
money=[]
skill=[]
for i in range(n):
a=list(map(int,input().split()))
money+=[a[0]]
skill+=[a[1:m+1]]
ans=-1
for i in range(2**n):
total=0
learn=[0]*m
for j in range(n):
if (i>>j)&1:
total+=money[j]
for a in range(m):
learn[a]+=skill[j][a]
if len([i for i in learn if i>=x])==m:
if ans==-1:
ans=total
elif ans>total:
ans=total
print(ans)
| 1 | 22,298,762,728,040 | null | 149 | 149 |
while True:
h, w = map(int, raw_input().split())
if (h == 0) & (w == 0):
break
line0 = ""
line1 = "."
for i in range(w):
if i % 2 == 0:
line0 += "#"
else:
line0 += "."
line1 += line0[:-1]
for j in range(h):
if j % 2 == 0:
print line0
else:
print line1
print ""
|
while True:
(H, W) = [int(x) for x in input().split()]
if H == W == 0:
break
for row in range(H):
if row % 2 == 0:
for w in range(W):
if w % 2 == 0:
print("#", end="")
else:
print(".", end="")
else:
print()
else:
for w in range(W):
if w % 2 == 0:
print(".",end="")
else:
print("#",end="")
print()
print()
| 1 | 873,482,888,430 | null | 51 | 51 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 +7
N, K = map(int, readline().split())
# s = [0] * (N+1)
# g = [0] * (N+1)
# g[0] = N % mod
# for i in range(1,N+1):
# s[i] += (s[i-1] + i ) % mod
# g[i] += (g[i-1] + N - i) % mod
# ans = (sum(g[K-1:]) % mod - sum(s[K-1:]) % mod + N-K+2) % mod
# print(ans)
k = np.arange(K,N+2,dtype = np.int64)
low = k*(k-1)//2
high = k*(2*N - k + 1) //2
cnt = high-low+1
print(sum(cnt)%mod)
|
tmp = int(input())
if tmp>=30:
print("Yes")
else:
print("No")
| 0 | null | 19,491,847,835,130 | 170 | 95 |
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve():
N = int(input())
d = defaultdict(int)
maxi = 0
for _ in range(N):
S = input()
d[S] += 1
maxi = max(maxi, d[S])
ans = []
for k, v in d.items():
if v == maxi:
ans.append(k)
for a in sorted(ans):
print(a)
def main():
solve()
if __name__ == '__main__':
main()
|
S = input()
if S[2] == S[3] and S[4] == S[5]:
print('Yes')
else:
print('No')
| 0 | null | 55,650,967,920,200 | 218 | 184 |
a = input()
b = a.split(' ')
c = int(b[0])
d = int(b[1])
if c < d:
print('a < b')
elif c > d:
print('a > b')
else:
print('a == b')
|
a,b = map(int,input().split())
if a>b:
str = 'a > b'
elif a<b:
str = 'a < b'
else:
str = 'a == b'
print(str)
| 1 | 346,083,389,130 | null | 38 | 38 |
N = int(input())
flag = False
for i in range(1, 10):
if N//i <= 9 and N%i == 0:
flag = True
if flag:
print("Yes")
else:
print("No")
|
n=int(input())
for i in range(1,10):
if n%i==0 and 1<=n//i<=9:
print("Yes")
break
else:
print("No")
| 1 | 159,986,701,803,150 | null | 287 | 287 |
n,m = map(int,input().split())
tbl=[[] for i in range(n)]
for i in range(n):
tbl[i] = list(map(int,input().split()))
tbl2=[[]*1 for i in range(m)]
for i in range(m):
tbl2[i] = int(input())
for k in range(n):
x=0
for l in range(m):
x +=tbl[k][l]*tbl2[l]
print("%d"%(x))
|
l=input().split()
r=int(l[0])
c=int(l[1])
# for yoko
i=0
b=[]
while i<r:
a=input().split()
q=0
su=0
while q<c:
b.append(int(a[q]))
su+=int(a[q])
q=q+1
b.append(su)
i=i+1
# for tate
#x=0
#d=b[0]+b[c+1]+b[2*(c+1)]+b[3*(c+1)]
#x<c+1
x=0
while x<c+1:
d=0
z=0
while z<r:
d+=b[x+z*(c+1)]
z+=1
b.append(d)
x=x+1
# for output
# C=[]
# y=0 (for gyou)
# z=0 (for yoko)
C=[]
y=0
while y<r+1:
z=0
Ans=str(b[y*(c+1)+z])
while z<c:
z+=1
Ans=Ans+" "+str(b[y*(c+1)+z])
C.append(Ans)
y+=1
for k in C:
print(k)
| 0 | null | 1,268,448,399,828 | 56 | 59 |
A, B = input().split(" ")
A = int(A.strip())
B = int(B.strip().replace(".", ""))
print(A * B // 100)
|
from decimal import *
import math
A, B = input().split()
a = Decimal(A)
b = Decimal(B)
ib = Decimal(100*b)
print(math.floor((a*ib)/Decimal(100)))
| 1 | 16,653,119,041,118 | null | 135 | 135 |
c=input()
o=ord(c)
o+=1
ans=chr(o)
print(ans)
|
from collections import defaultdict
N, K = map(int,input().split())
A = list(map(int,input().split()))
a = [0]
for i in A:
a.append((a[-1]+i-1)%K)
d = defaultdict(int)
ans = 0
for i in range(N+1):
if i >= K:
d[a[i-K]] -= 1
ans += d[a[i]]
d[a[i]] += 1
print(ans)
| 0 | null | 114,465,816,199,640 | 239 | 273 |
import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
class Combination:
def __init__(self, n: int, mod: int):
self.mod = mod
self.fact = [0] * (n + 1)
self.factinv = [0] * (n + 1)
self.inv = [0] * (n + 1)
self.fact[0] = self.fact[1] = 1
self.factinv[0] = self.factinv[1] = 1
self.inv[1] = 1
for i in range(2, n + 1):
self.fact[i] = (self.fact[i - 1] * i) % mod
self.inv[i] = (-self.inv[mod % i] * (mod // i)) % mod
self.factinv[i] = (self.factinv[i - 1] * self.inv[i]) % mod
def ncr(self, n: int, r: int):
if r < 0 or n < r:
return 0
r = min(r, n - r)
return self.fact[n] * self.factinv[r] % self.mod * self.factinv[n - r] % self.mod
def nhr(self, n: int, r: int):
return self.ncr(n + r - 1, r)
def npr(self, n: int, r: int):
if r < 0 or n < r:
return 0
return self.fact[n] * self.factinv[n - r] % self.mod
def solve():
N, K = map(int, rl().split())
A = list(map(int, rl().split()))
MOD = 10 ** 9 + 7
A.sort()
com = Combination(N, MOD)
ans = 0
for i in range(N):
ans += com.ncr(i, K - 1) * A[i] % MOD
ans -= com.ncr(N - i - 1, K - 1) * A[i] % MOD
ans %= MOD
print(ans)
if __name__ == '__main__':
solve()
|
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def score(A):
res = 0
for a, b, c, d in abcd:
if A[b - 1] - A[a - 1] == c:
res += d
return res
def main(n, m, abcd):
p = itertools.combinations_with_replacement(range(1, m+1), n)
L = list(p)
ans = 0
for A in L:
ans = max(ans, score(list(A)))
return ans
n, m, q = map(int, readline().split())
abcd = [list(map(int, readline().split())) for _ in range(q)]
print(main(n, m, abcd))
| 0 | null | 61,640,201,318,192 | 242 | 160 |
while 1 :
a, op, b= raw_input().split()
c = int(a)
d = int(b)
if op == '?': break
elif op == '+': print c + d
elif op == '-': print c - d
elif op == '*': print c * d
elif op == '/': print c / d
|
while True:
exp = input()
if '?' in exp: break
print('%d' % (int(eval(exp))))
| 1 | 698,151,157,674 | null | 47 | 47 |
from collections import Counter
S = input()
L = len(list(S))
dp = [0] * L
dp[0] = 1
T = [0] * L
T[0] = int(S[-1])
for i in range(1, L):
dp[i] = dp[i - 1] * 10
dp[i] %= 2019
T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1]
T[i] %= 2019
ans = 0
for k, v in Counter(T).items():
if k == 0:
ans += v
ans += v * (v - 1) // 2
else:
ans += v * (v - 1) // 2
print(ans)
|
from collections import Counter
MOD = 2019
S = input()[::-1]
X = [0]
for i in range(len(S)):
X.append((X[-1]+int(S[i])*pow(10, i, MOD))%MOD)
C = Counter(X)
ans = 0
for v in C.values():
ans += v*(v-1)//2
print(ans)
| 1 | 30,986,393,257,960 | null | 166 | 166 |
a,b=[int(x) for x in input().split()]
op = '>' if a>b else '<' if a<b else '=='
print('a',op,'b')
|
num = input()
num_list = []
num_list = num.split()
if int(num_list[0]) == int(num_list[1]):
print('a','b',sep=' == ')
elif int(num_list[0]) > int(num_list[1]):
print('a','b',sep=' > ')
else:
print('a','b',sep=' < ')
| 1 | 354,277,598,688 | null | 38 | 38 |
n = int(raw_input())
i = 0
s = []
h = []
c = []
d = []
def order_list(list):
l = len(list)
for i in xrange(l):
j = i + 1
while j < l:
if list[i] > list[j]:
temp = list[i]
list[i] = list[j]
list[j] = temp
j += 1
return list
def not_enough_cards(mark, list):
list = order_list(list)
# line = "########################################"
# print line
# print mark + ":"
# print list
# print line
i = 0
for x in xrange(1, 14):
# print "x = " + str(x) + ", i = " + str(i)
if i >= len(list):
print mark + " " + str(x)
elif x != list[i]:
print mark + " " + str(x)
else:
i += 1
while i < n:
line = raw_input().split(" ")
line[1] = int(line[1])
if line[0] == "S":
s.append(line[1])
elif line[0] == "H":
h.append(line[1])
elif line[0] == "C":
c.append(line[1])
elif line[0] == "D":
d.append(line[1])
i += 1
not_enough_cards("S", s)
not_enough_cards("H", h)
not_enough_cards("C", c)
not_enough_cards("D", d)
|
n=int(input())
cards = [[s+" "+str(n) for n in range(1,14)] for s in ["S","H","C","D"]]
for _ in range(n):
suit,num =input().split()
if suit=="S":
cards[0][int(num)-1]=0
elif suit=="H":
cards[1][int(num)-1]=0
elif suit=="C":
cards[2][int(num)-1]=0
elif suit=="D":
cards[3][int(num)-1]=0
for s in cards:
for n in s:
if n!=0:
print(n)
| 1 | 1,037,329,634,990 | null | 54 | 54 |
a = input()
b = a.split(' ')
c = int(b[0])
d = int(b[1])
e = str(c*d)
f = str(c*2 + d*2)
print(e+' '+f)
|
[a,b] = raw_input().split(' ')
print int(a)*int(b), (int(a) + int(b)) * 2
| 1 | 309,574,789,706 | null | 36 | 36 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
K = int(readline())
vec = list(range(1, 10))
for i in range(K):
tail = vec[i] % 10
if tail == 0:
vec.append(vec[i] * 10 + tail)
vec.append(vec[i] * 10 + tail + 1)
elif tail == 9:
vec.append(vec[i] * 10 + tail - 1)
vec.append(vec[i] * 10 + tail)
else:
vec.append(vec[i] * 10 + tail - 1)
vec.append(vec[i] * 10 + tail)
vec.append(vec[i] * 10 + tail + 1)
if len(vec) == K:
break
print(vec[K - 1])
return
if __name__ == '__main__':
main()
|
k = int(input())
ans = 1
def next(n):
nStr = list(map(int, list(str(n))))
r = len(nStr)-1
while r > 0:
if nStr[r] <= nStr[r-1] and not (nStr[r-1] == 9 and nStr[r] == 9):
break
r -= 1
if r == 0 and nStr[0] == 9:
nStr = [1] + [0] * len(nStr)
else:
extra = len(nStr)-1-r
nStr = nStr[:r] + [nStr[r]+1]
for _ in range(extra):
nStr.append(max(0, nStr[-1]-1))
return int("".join(map(str, nStr)))
for i in range(k-1):
ans = next(ans)
print(ans)
| 1 | 39,778,612,556,572 | null | 181 | 181 |
#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
Q.append(input().split())
t=0
res=[]
while Q!=[]:
if int(Q[0][1])<=q:
res.append([Q[0][0],int(Q[0][1])+t])
t+=int(Q[0][1])
else:
Q.append([Q[0][0],int(Q[0][1])-q])
t+=q
del Q[0]
for i in res:
print(i[0]+" "+str(i[1]))
|
MOD = 10**9 + 7
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
return (
ModInt(self.x + other.x) if isinstance(other, ModInt) else
ModInt(self.x + other)
)
def __sub__(self, other):
return (
ModInt(self.x - other.x) if isinstance(other, ModInt) else
ModInt(self.x - other)
)
def __mul__(self, other):
return (
ModInt(self.x * other.x) if isinstance(other, ModInt) else
ModInt(self.x * other)
)
def __truediv__(self, other):
return (
ModInt(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
ModInt(other.x - self.x) if isinstance(other, ModInt) else
ModInt(other - self.x)
)
__rmul__ = __mul__
def __rtruediv__(self, other):
return (
ModInt(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(other, self.x, MOD))
)
def solve(N, A):
ret = ModInt(1)
count = [3 if not i else 0 for i in range(N + 1)]
for a in A:
ret *= count[a]
if not ret:
break
count[a] -= 1
count[a + 1] += 1
return ret
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
print(solve(N, A))
| 0 | null | 65,278,293,980,198 | 19 | 268 |
a,b,c = map(int,input().split())
K = int(input())
judge = False
for i in range(K+1):
for j in range(K+1):
for k in range(K+1):
x = a*2**i
y = b*2**j
z = c*2**k
if i+j+k <= K and x < y and y < z:
judge = True
if judge:
print("Yes")
else:
print("No")
|
A,B,C=map(int,input().split())
K=int(input())
D=[]
for i in range(K):
for j in range(K-i):
if A*(2**i)<B*(2**j) and B*(2**j)<C*(2**(K-i-j)):
D.append('Yes')
else:
D.append('No')
if ('Yes' in D)==True:
print('Yes')
else:
print('No')
| 1 | 6,971,784,942,800 | null | 101 | 101 |
def main():
# データ入力
n, q = input().split()
n = int( n )
q = int( q )
name = []
time = []
for i in range(n):
tmp_n, tmp_t = input().split()
name.append( tmp_n )
time.append( int( tmp_t ) )
# 処理
count = 0
while n > 0:
if time[0] > q:
time[0] -= q
count += q
time.append( time[0] )
time.pop( 0 )
name.append( name[0] )
name.pop( 0 )
else :
count += time[0]
print( name[0], end=" " )
print( str( count ) )
time.pop( 0 )
name.pop( 0 )
n -= 1
if __name__ == '__main__':
main()
|
a = float(input())
print("{:.12f}".format((a/3)**3))
| 0 | null | 23,666,007,506,972 | 19 | 191 |
N, M = map(int,input().split())
A=sorted(list(map(int, input().split())),reverse=True)
if A[M-1]>=sum(A)/(4*M):
print('Yes')
else:
print('No')
|
n,m = map(int, input().split())
A = list(map(int,input().split()))
min_limit = sum(A)*(1 / (4*m))
select_ok = 0
for i in A:
if i >= min_limit:
select_ok += 1
if select_ok >= m:
print("Yes")
else:
print("No")
| 1 | 38,651,501,156,018 | null | 179 | 179 |
S = input()
T = input()
num = 0
length = len(S)
for i in range(length):
if S[i] != T[i]:
num += 1
print(num)
|
S=str(input())
T=str(input())
c=len(S)
for i in range(len(S)):
if S[i]==T[i]: c=c-1
print(c)
| 1 | 10,403,172,694,416 | null | 116 | 116 |
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in a:
if i>=sum(a)*(1/(4*m)):
c+=1
if c>=m:
print('Yes')
else:
print('No')
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
sumA = sum(A)
for a in A:
if a >= sumA / 4 / M:
cnt += 1
if cnt >= M:
print('Yes')
else:
print('No')
| 1 | 38,620,657,574,110 | null | 179 | 179 |
def main():
N=int(input())
A=[int(_) for _ in input().split()]
left=0
right=sum(A)
ans=right
for i in range(N):
left+=A[i]
right-=A[i]
ans = min(ans, abs(left-right))
print(ans)
main()
|
l=list(map(int,input().split()))
if sum(l)%9==0:
print('Yes')
else:
print('No')
| 0 | null | 73,116,123,743,420 | 276 | 87 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
h,w,k=map(int,input().split())
S=[input() for _ in range(h)]
final_ans=10**10
for row_lis in range(1<<(h-1)):
lst=[0]*h
q,ans=0,0
for r in range(h-1):
if (row_lis>>r)&1==0:
lst[r+1]=q
else:
q+=1
lst[r+1]=q
ans+=1
data=[0]*h
for j in range(w):
for i in range(h):
data[lst[i]]+=int(S[i][j])
if data[lst[i]]>k:
ans+=1
break
else:
continue
data=[0]*h
for i in range(h):
data[lst[i]]+=int(S[i][j])
if data[lst[i]]>k:
break
else:
continue
break
else:
final_ans=min(final_ans,ans)
print(final_ans)
if __name__=='__main__':
main()
|
n = int(input())
s = list(input())
a = []
for i in s:
num = ord(i)+n
if num > 90:
num -= 26
a.append(chr(num))
print(''.join(a))
| 0 | null | 91,791,443,158,290 | 193 | 271 |
while 1:
string = raw_input()
if string == "-":
break
l = len(string)
for i in xrange(int(input())):
h = int(input())
lower = string[0:h]
upper = string[h:l]
string = upper + lower
print string
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug
import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect
class Part:
def __init__(self, string):
self.slope, self.floor = self.calc_slope_floor(string)
def __repr__(self):
return "s{} f{}".format(self.slope, self.floor)
def __lt__(self, other):
if self.floor > other.floor:
return True
if self.slope > self.slope:
return True
return False
@staticmethod
def calc_slope_floor(string):
slope = 0
floor = 0
for c in string:
if c == '(':
slope += 1
else:
slope -= 1
floor = min(floor, slope)
return slope, floor
def flip(self):
self.slope *= -1
self.floor += self.slope
def catenate(self, other):
assert(self.slope >= 0)
if self.slope < abs(other.floor):
return False
self.slope += other.slope
# self.floor is not needed
def sum_slope(parts):
s = 0
for p in parts:
s += p.slope
return s
def calc_flat_floor(flat):
floor = 0
for f in flat:
floor = min(floor, f.floor)
return floor
def enable(parts):
parts = sorted(parts)
#print('parts') # debug
#print(parts) # debug
chain = Part("")
for p in parts:
flg = chain.catenate(p)
if flg == False:
return False
return True
def solve(up, down, flat):
up_slope = sum_slope(up)
down_slope = sum_slope(down)
if up_slope != down_slope:
return False
flat_floor = calc_flat_floor(flat)
#print('up_slope') # debug
#print(up_slope) # debug
#print('flat_floor') # debug
#print(flat_floor) # debug
if up_slope < abs(flat_floor):
return False
if not enable(up):
return False
if not enable(down):
return False
return True
if __name__ == '__main__':
n = int(input())
up = []
down = []
flat = []
for _ in range(n):
s = input()
p = Part(s)
if p.slope > 0:
up.append(p)
elif p.slope < 0:
p.flip()
down.append(p)
else:
flat.append(p)
ans = solve(up, down, flat)
if ans:
print("Yes")
else:
print("No")
#print('\33[32m' + 'end' + '\033[0m') # debug
| 0 | null | 12,698,262,219,360 | 66 | 152 |
import numpy as np
N,K = map(int,input().split())
import math
A = list(map(int,input().split()))
flag = 0
if 0 in A:
flag = 1
A.sort()
plus = list(filter(lambda x:x>0, A))[::-1]
plus = list(map(lambda x:np.longdouble(math.log(x,10000000)),plus))
from itertools import accumulate
acc_plu = [0] + list(accumulate(plus))
minu = filter(lambda x:x<0, A)
minu = list(map(lambda x:np.longdouble(math.log(-x,10000000)),minu))
acc_min = [0] + list(accumulate(minu))
if K % 2 == 0 : num = K // 2 + 1
else: num = (K + 1) // 2
cand = []
x = K
y = 0
MOD = 10**9 +7
for i in range(num):
try:
cand.append((acc_plu[x] + acc_min[y],x ,y ))
except: pass
x -= 2
y += 2
ans = 1
if cand == []:
if flag:
print(0)
exit()
cnt = 0
#マイナス確定
abss = sorted(list(map(lambda x :abs(x),A)))
for x in abss:
if cnt == K:break
ans *= x
ans %= MOD
cnt += 1
ans *= -1
ans %= MOD
print(ans)
else:
cand = sorted(cand)[::-1]
plus = list(filter(lambda x:x>0, A))[::-1]
minu = list(filter(lambda x:x<0, A))
c = cand[0]
ans = 1
for i in range(c[1]):
ans *= plus[i]
ans %= MOD
for i in range(c[2]):
ans *= minu[i]
ans %= MOD
print(ans)
|
house = [[[0 for col in range(10)]for row in range(3)]for layer in range(4)]
n = int(raw_input())
for i in range(n):
input_line = raw_input().split()
house[int(input_line[0])-1][int(input_line[1])-1][int(input_line[2])-1] += int(input_line[3])
for i in range(0,4):
if i != 0:
print "#"*20
for j in range(0,3):
buf = ""
for k in range(0,10):
buf += " " + str(house[i][j][k])
print buf
| 0 | null | 5,226,736,227,508 | 112 | 55 |
K=int(input())
res=1
x=0
for i in range(K):
x+=7*res
x%=K
if x%K==0:
print(i+1)
break
res*=10
res%=K
else:
print(-1)
|
k = int(input())
if k % 2 == 0 or k % 5 == 0:
print(-1)
else:
ans = 7
cnt = 1
while 1:
if ans % k == 0:
break
else:
cnt += 1
ans *= 10
ans += 7
ans %= k
print(cnt)
| 1 | 6,090,582,290,508 | null | 97 | 97 |
def calc(stack, s):
a = stack.pop()
b = stack.pop()
if s=='+':
stack.append(b+a)
elif s=='-':
stack.append(b-a)
elif s=='*':
stack.append(b*a)
S = list(input().split())
stack = []
for s in S:
if s in ['+', '-', '*']:
calc(stack, s)
else:
stack.append(int(s))
print(stack[0])
|
#!/usr/bin/env python
# encoding: utf-8
class Solution:
@staticmethod
def stack_polish_calc():
# write your code here
# array_length = int(input())
calc_func = ('+', '-', '*')
array = [str(x) for x in input().split()]
# print(array)
result = []
for i in range(len(array)):
if array[i] not in calc_func:
result.append(str(array[i]))
else:
calc = array[i]
arg_2 = result.pop()
arg_1 = result.pop()
result.append(str(eval(''.join((str(arg_1), calc, str(arg_2))))))
print(*result)
if __name__ == '__main__':
solution = Solution()
solution.stack_polish_calc()
| 1 | 34,721,710,716 | null | 18 | 18 |
import math
x1,y1,x2,y2 = map(float,input().split())
x = (x1-x2)**2
y = (y1-y2)**2
print('{:.8f}'.format(math.sqrt(x+y)))
|
a=int(input())
b=int(input())
c=[1,2,3]
c.remove(a)
c.remove(b)
if c==[1]:
print(1)
elif c==[2]:
print(2)
else:
print(3)
| 0 | null | 55,491,041,545,290 | 29 | 254 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.