code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import sys
x = int( sys.stdin.readline() )
h = x//3600
m = ( x%3600 )//60
s = ( x%3600 )%60
print( "{}:{}:{}".format( h, m, s) ) | n=int(input())
a,b=map(str,input().split())
s=''
for i in range(n):
s+=a[i]
s+=b[i]
print(s) | 0 | null | 56,158,073,200,880 | 37 | 255 |
def solve(n, k):
ans = 0
mod = int(1e9 + 7)
for i in range(k, n + 2):
lb = (i - 1) * i // 2
ub = (n + n - i + 1) * i // 2
ans += ub - lb + 1
ans %= mod
# print(ub-lb+1, ub, lb, i)
return ans
def main():
# print(solve(3, 2))
# print(solve(200000, 200001))
# print(solve(141421, 35623))
print(solve(*[int(v) for v in input().split()]))
if __name__ == '__main__':
main()
| N, K = map(int, input().split())
def sub_sum(l, r):
return (l + r) * (r - l + 1) / 2
ans = 0
for i in range(K, N+2):
l = sub_sum(0, i-1)
r = sub_sum(N-i+1, N)
ans += r - l + 1
ans = ans % (10**9+7)
print(int(ans))
| 1 | 33,040,441,935,960 | null | 170 | 170 |
import numpy as np
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
S1 = (A1 - B1) * T1
S2 = (A2 - B2) * T2
if (S1 + S2) == 0:
print('infinity')
elif np.sign(S1) == np.sign(S2):
print(0)
elif abs(S1) > abs(S2):
print(0)
else:
z = 1 + ((abs(S1)) // abs(S1 + S2)) * 2
if (abs(S1)) % abs(S1 + S2) == 0:
z = z -1
print(z)
| from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
x = int(stdin.readline().rstrip())
for i in range(-150,150):
for j in range(-150,150):
if i**5-j**5 == x: print(i,j); sys.exit()
| 0 | null | 78,786,164,220,950 | 269 | 156 |
for i in range(1,10):
for k in range(1,10):
print("{0}x{1}={2}".format(i,k,i*k)) | for i in range(9):
for j in range(9):
print(i+1,end='')
print('x',end='')
print(j+1,end='')
print('=',end='')
print((i+1)*(j+1))
| 1 | 1,808 | null | 1 | 1 |
number = int(input())
score = list(map(int,input().split()))
score.sort()
cancel = 0
for i in range(number-1):
if score[i] == score[i+1]:
cancel = 1
break
if cancel == 1:
print('NO')
else:
print('YES') | N=int(input())
a,b,c,d=0,0,0,0
for i in range(N):
A=input()
if A=="AC":
a+=1
elif A=="WA":
b+=1
elif A=="TLE":
c+=1
else:
d+=1
print("AC x",a)
print("WA x",b)
print("TLE x",c)
print("RE x",d) | 0 | null | 41,101,976,824,260 | 222 | 109 |
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 #
#############
N, U, V = getNM()
U -= 1
V -= 1
# 高橋君はできるだけ遅くゲームが終了するように移動し、青木君はできるだけ早くゲームが終了するように移動します。
# 高橋君は逃げ、青木君は追いかける
dist = [[] for i in range(N)]
for i in range(N - 1):
a, b = getNM()
dist[a - 1].append(b - 1)
dist[b - 1].append(a - 1)
taka_d = [-1] * N
aoki_d = [-1] * N
taka_d[U] = 0
pos = deque([[U, taka_d[U]]])
while len(pos) > 0:
u, dis = pos.popleft()
for i in dist[u]:
if taka_d[i] == -1:
taka_d[i] = dis + 1
pos.append([i, taka_d[i]])
aoki_d[V] = 0
pos = deque([[V, aoki_d[V]]])
while len(pos) > 0:
u, dis = pos.popleft()
for i in dist[u]:
if aoki_d[i] == -1:
aoki_d[i] = dis + 1
pos.append([i, aoki_d[i]])
ans = 0
for a, b in zip(taka_d, aoki_d):
if a < b:
ans = max(ans, b - 1)
print(ans)
| N = int(input())
A = list(map(int,input().split()))
P = {}
Q = {}
X = {}
for i in range(N):
p = i+1+A[i]
q = i+1-A[i]
if str(p) in P:
P[str(p)] += 1
else:
P[str(p)] = 1
if str(q) in Q:
Q[str(q)] += 1
else:
Q[str(q)] = 1
X.setdefault(str(p),i+1+A[i])
X.setdefault(str(q),i+1-A[i])
#J[a]とI[b]が等しいのが条件
#とりうる値 < 10**9を全て試す
ans = 0
for key in X.keys():
if (key in P) and (key in Q):
ans += P[key] * Q[key]
print(ans)
| 0 | null | 71,416,465,277,410 | 259 | 157 |
class Dice:
"""????????????????????????"""
def __init__(self, s):
self.s1 = s[0]
self.s2 = s[1]
self.s3 = s[2]
self.s4 = s[3]
self.s5 = s[4]
self.s6 = s[5]
def roll(self, direction): # ???????????????????§??????¢????????¢
temp = self.s1
if direction == "E":
self.s1 = self.s4
self.s4 = self.s6
self.s6 = self.s3
self.s3 = temp
elif direction == "N":
self.s1 = self.s2
self.s2 = self.s6
self.s6 = self.s5
self.s5 = temp
elif direction == "S":
self.s1 = self.s5
self.s5 = self.s6
self.s6 = self.s2
self.s2 = temp
elif direction == "W":
self.s1 = self.s3
self.s3 = self.s6
self.s6 = self.s4
self.s4 = temp
s = list(map(int, input().split()))
dice1 = Dice(s)
command = input()
for i in range(len(command)):
dice1.roll(command[i])
print(dice1.s1) | class Dice:
def __init__(self,faces):
self.faces = tuple(faces)
def N(self):
self.faces = (self.faces[1], self.faces[5], self.faces[2],
self.faces[3], self.faces[0], self.faces[4])
def S(self):
self.faces = (self.faces[4], self.faces[0], self.faces[2],
self.faces[3], self.faces[5], self.faces[1])
def W(self):
self.faces = (self.faces[2], self.faces[1], self.faces[5],
self.faces[0], self.faces[4], self.faces[3])
def E(self):
self.faces = (self.faces[3], self.faces[1], self.faces[0],
self.faces[5], self.faces[4], self.faces[2])
def number(self, face_id):
return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
x=input()
for i in x:
if i == "N":
dice.N()
elif i == "S":
dice.S()
elif i == "W":
dice.W()
elif i == "E":
dice.E()
print(dice.number(1)) | 1 | 243,458,662,944 | null | 33 | 33 |
import sys
read = sys.stdin.read
INF = 1 << 60
def main():
H, N, *AB = map(int, read().split())
dp = [INF] * (H + 1)
dp[0] = 0
for a, b in zip(*[iter(AB)] * 2):
for i in range(H + 1):
if i >= a:
if dp[i] > dp[i - a] + b:
dp[i] = dp[i - a] + b
else:
if dp[i] > dp[0] + b:
dp[i] = dp[0] + b
print(dp[H])
return
if __name__ == '__main__':
main()
| n = int(input())
taro = 0
hanako = 0
for i in range(n):
t,h =input().split()
if t > h:
taro+=3
elif t<h:
hanako += 3
else:
taro += 1
hanako += 1
print("%d %d" % (taro,hanako)) | 0 | null | 41,515,479,058,938 | 229 | 67 |
mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
zero = defaultdict(int)
one = defaultdict(int)
for a in A:
for i in range(61):
if a &(1<<i):
one[i] += 1
else:
zero[i] += 1
ans = 0
for i in range(61):
ans += pow(2,i,mod)*zero[i]*one[i]
ans %=mod
print(ans%mod) | N,M = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
if a[M-1]<sum(a)/(4*M):
print("No")
else:
print("Yes")
| 0 | null | 80,888,135,713,010 | 263 | 179 |
n = int(input())
s = [ i for i in input().split()]
flag = True
cnt = 0
while flag:
flag = False
for i in range(n-1):
if int(s[i]) > int(s[i+1]):
s[i],s[i+1] = s[i+1],s[i]
flag = True
cnt += 1
print(' '.join(s))
print(cnt)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
if __file__=="test.py":
f = open("./in_out/input.txt", "r", encoding="utf-8")
read = f.read
readline = f.readline
def main():
R, C, K = map(int, readline().split())
L_INF = int(1e17)
dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K):
x, y, c = map(int, readline().split())
cell[x-1][y-1] = c
dp[0][0][1] = dp[0][1][0] = 0
for i in range(1, R + 1):
for j in range(1, C + 1):
for k in range(4):
if k > 0:
dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
if k > 0:
dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + cell[i-1][j-1])
if k == 1:
dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
print(dp[3][R][C])
if __name__ == "__main__":
main()
| 0 | null | 2,802,034,716,928 | 14 | 94 |
h, n = list(map(int, input().split()))
a = list(map(int, input().split()))
print("Yes" if sum(a) >= h else "No") | N,R = map(int,input().split())
print((R,R +100*(10-N))[N<=10]) | 0 | null | 70,462,994,462,994 | 226 | 211 |
import sys
input = sys.stdin.readline
def main():
N = int(input())
print(N//2+1) if N % 2 else print(N//2)
if __name__ == '__main__':
main()
| """
keyword: ラジアン, 度
最大限傾けたとき、水と接している面は横から見ると台形ないし三角形となる
水と接している面の面積 x/a が a*b/2 より大きい場合は台形となり、それ以下の場合は三角形となる
・台形の場合
最大限傾けたとき、水と接している台形の上辺の長さをhとすると
(h+b)*a/2 = x/a
h = 2*x/(a**2) - b
求める角度をthetaとすると
tan(theta) = (b-h)/a
theta = arctan((b-h)/a)
・三角形の場合
最大限傾けたとき、水と接している三角形の底辺の長さをhとすると
h*b/2 = x/a
h = 2*x/(a*b)
求める角度をthetaとすると
tan(theta) = b/h
theta = arctan(b/h)
"""
import sys
sys.setrecursionlimit(10**6)
a,b,x = map(int, input().split())
import numpy as np
if x/a > a*b/2:
h = 2*x/(a**2) - b
theta = np.arctan2(b-h, a) # radian表記なので戻り値の範囲は[-pi/2, pi/2]
theta = np.rad2deg(theta)
else:
h = 2*x/(a*b)
theta = np.arctan2(b, h)
theta = np.rad2deg(theta)
print(theta) | 0 | null | 111,329,723,309,112 | 206 | 289 |
N=int(input())
S=[]
T=[]
for i in range(N):
x,y=map(str,input().split())
S.append(x)
T.append(int(y))
X=str(input())
p=S.index(X)
print(sum(T[p+1:])) | n=int(input())
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
print("No") | 0 | null | 66,046,718,085,068 | 243 | 172 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N, X, T = map(int, readline().split())
p = (N//X)*T
if N%X == 0:
print(p)
else:
print(p+T)
if __name__ == '__main__':
main()
| # coding: utf-8
# Your code here!
N=int(input())
count=-1
for i in range(N//2+1):
count+=1
if N%2==0:
print(count-1)
else:
print(count) | 0 | null | 78,593,685,836,962 | 86 | 283 |
import math
a, b, x = [int(n) for n in input().split()]
v = a**2 * b /2
#print(v, x)
if v == x:
theta = math.atan(b/a)
elif v > x:
theta = math.atan(a*(b**2)/(2*x))
elif v < x:
theta = math.atan(2/a*(b-x/a**2))
print(math.degrees(theta))
| import math
a, b, x = map(int, input().split())
x = x / a
if x >= a*b/2:
K = (a*b - x)/a*2
L = K/math.sqrt(K**2+a**2)
ans = math.degrees(math.asin(L))
print(ans)
else:
K = 2*x/b
L = b/math.sqrt(K**2+b**2)
ans = math.degrees(math.asin(L))
print(ans) | 1 | 163,103,432,018,858 | null | 289 | 289 |
m1,d1 = (int(x) for x in input().split())
m2,d2 = (int(x) for x in input().split())
if d2==1:
print(1)
else:
print(0) | M1,D1 = [int(i) for i in input().split()]
M2,D2 = [int(i) for i in input().split()]
if M1 != M2:
print(1)
else:
print(0)
| 1 | 124,598,592,247,190 | null | 264 | 264 |
dice_init = input().split()
dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'}
num = int(input())
def dicing(x):
global dice
dice = [dice[int(c)] for c in dicry[x]]
for _ in range(num):
dice = dice_init
top, front = map(int, input().split())
while True:
if int(dice[0]) == top and int(dice[1]) == front:
break
elif int(dice[0]) == top:
dicing('hittop')
elif int(dice[1]) == front:
dicing('hitfront')
else:
dicing('search')
print(dice[2])
| N=int(input())
*A,=map(int,input().split())
M=max(A)
B=[1]*(M+1)
B[0]=B[1]=1
i=2
while i<=M:
if B[i]:
j=2
while i*j<=M:
B[i*j]=0
j+=1
i+=1
C=[0]*(M+1)
for a in A:
C[a]=1
from math import*
now=A[0]
for a in A:
now=gcd(now,a)
if now==1:
ans='pairwise coprime'
i=2
while i<=M:
if B[i]:
count=0
j=1
while i*j<=M:
count+=C[i*j]
j+=1
if count>1:
ans='setwise coprime'
i+=1
print(ans)
else:
print('not coprime') | 0 | null | 2,161,927,907,172 | 34 | 85 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
bunshi=1
bunbo=1
for i in range(r):
bunbo = bunbo*(i+1)%mod
bunshi = bunshi*(n-i)%mod
return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと!
def maze_solve(S_1,S_2,maze_list):
d = deque()
d.append([S_1,S_2])
dx = [0,0,1,-1]
dy = [1,-1,0,0]
while d:
v = d.popleft()
x = v[0]
y = v[1]
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx < 0 or nx >= h or ny < 0 or ny >= w:
continue
if dist[nx][ny] == -1:
dist[nx][ny] = dist[x][y] + 1
d.append([nx,ny])
return max(list(map(lambda x: max(x), dist)))
h,w = MI()
if h==1 and w == 2:
print(1)
elif h == 2 and w == 1:
print(1)
else:
ans = 0
maze = [list(input()) for _ in range(h)]
dist = [[-1]*w for _ in range(h)]
start_list = []
for i in range(h):
for j in range(w):
if maze[i][j] == "#":
dist[i][j] = 0
else:
start_list.append([i,j])
dist_copy = deepcopy(dist)
for k in start_list:
dist = deepcopy(dist_copy)
ans = max(ans,maze_solve(k[0],k[1],maze))
print(ans+1) | from collections import defaultdict, deque
h, w = map(int, input().split())
tizu = [input() for _ in range(h)]
ans = 0
directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(h):
for j in range(w):
if tizu[i][j] == "#":
continue
check = [[False for _ in range(w)] for _ in range(h)]
check[i][j] = True
queue = deque()
queue.append([i, j])
queue.append(0)
while queue:
pos = queue.popleft()
ans_sub = queue.popleft()
for dh, dw in directions:
nh = pos[0] + dh
nw = pos[1] + dw
if nh == -1 or nh == h or nw == -1 or nw == w:
continue
if tizu[nh][nw] == "#":
continue
if check[nh][nw]:
continue
check[nh][nw] = True
queue.append([nh, nw])
queue.append(ans_sub + 1)
ans = max(ans, ans_sub)
print(ans) | 1 | 95,084,375,173,482 | null | 241 | 241 |
n, k = (int(x) for x in input().split())
# すぬけ君は全員お菓子を持っていないと仮定する
list_snuke = [str(i) for i in range(1, n + 1)]
# お菓子をもっているすぬけ君の番号を削除
# appendではなくリスト内包表記で書きたい
for i in range(0, k):
d = int(input())
a = [s for s in input().split()]
for j in range(0, d):
if a[j] in list_snuke:
list_snuke.remove(a[j])
# お菓子をもっていないすぬけ君の人数を出力
print(len(list_snuke)) | import sys
N,K = map(int,input().split())
array = [ a for a in range(1,N+1) ]
for I in range(K):
_ = input()
sweets = list(map(int,input().split()))
for K in sweets:
if K in array:
array.remove(K)
print(len(array)) | 1 | 24,490,008,221,562 | null | 154 | 154 |
def main():
data_count = int(input())
data = [list(map(int, input().split())) for i in range(data_count)]
for item in data:
item.sort()
print('YES') if item[0]**2 + item[1]**2 == item[2]**2 else print('NO')
main() | n,m=map(int,raw_input().split())
c=map(int,raw_input().split())
dp=[i for i in range(n+1)]
c.remove(1)
c.sort()
for coin in c:
for x in range(1,n+1):
if x-coin>=0:
dp[x]=min(dp[x],dp[x-coin]+1)
print dp[n]
| 0 | null | 73,582,801,428 | 4 | 28 |
import numpy as np
X = int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
div = make_divisors(X)
for i in range(len(div)):
x = div[i]
z = x**4 - X/x
if z%5 == 0:
s = z / 5
if x**4 - 4*s >=0:
y1 =( -x**2 + np.sqrt(x**4 - 4 * s)) / 2
y2 =( -x**2 - np.sqrt(x**4 - 4 * s)) / 2
B1 = (-x + np.sqrt(x**2 + 4*y1))/2
if B1.is_integer():
B = B1
A = B + x
break
B12 = (-x + np.sqrt(x**2 + 4*y2))/2
if B12.is_integer():
B = B12
A = B + x
break
B2 = (-x - np.sqrt(x**2 + 4*y1))/2
if B2.is_integer():
B = B2
A = B + x
break
B21 = (-x - np.sqrt(x**2 + 4*y2))/2
if B21.is_integer():
B = B21
A = B + x
break
print(int(A),int(B))
| import sys
X = int(input())
for a in range(-200,200):
for b in range(-200,200):
if a ** 5 - b ** 5 == X:
print(a,b)
sys.exit() | 1 | 25,801,977,852,574 | null | 156 | 156 |
def main():
r = int(input())
print(r**2)
if __name__ == "__main__":
main()
| m1,_ = input().split()
m2,_ = input().split()
ans = 0
if m1 != m2:
ans = 1
print(ans) | 0 | null | 134,668,719,423,140 | 278 | 264 |
n, m = map(int, input().split())
a = list()
for i in range(n):
a.append(list(map(int, input().split())))
b = list()
for i in range(m):
b.append(int(input()))
for i in range(n):
ans = 0
for j in range(m):
ans += a[i][j] * b[j]
print(ans)
| A = []
b = []
row = 0
col = 0
row, col = map(int, raw_input().split())
A = [[0 for i in range(col)] for j in range(row)]
for i in range(row):
r = map(int, raw_input().split())
for index, j in enumerate(r):
A[i][index] = j
for i in range(col):
b.append(int(raw_input()))
for i in A:
ret = 0
for j,k in zip(i,b):
ret += j*k
print ret | 1 | 1,154,597,619,630 | null | 56 | 56 |
a,b,c,k = map(int,input().split())
if k <= a:
print(k)
elif a < k <= (a+b):
print(a)
else:
print(a-(k-a-b)) | import sys
input = sys.stdin.readline
class Combination: # 計算量は O(n_max + log(mod))
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1): # 階乗(= n_max !)の逆元を生成
f = f * i % mod # 動的計画法による階乗の高速計算
fac.append(f) # fac は階乗のリスト
f = pow(f, mod-2, mod) # 階乗から階乗の逆元を計算。フェルマーの小定理より、 a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime
# python の pow 関数は自動的に mod の下での高速累乗を行ってくれる
self.facinv = facinv = [f]
for i in range(n_max, 0, -1): # 上記の階乗の逆元から階乗の逆元のリストを生成(= facinv )
f = f * i % mod
facinv.append(f)
facinv.reverse()
def __call__(self, n, r): # self.C と同じ
if not 0 <= r <= n: return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def H(self, n, r): # (箱区別:〇 ボール区別:× 空箱:〇) 重複組み合わせ nHm
if (n == 0 and r > 0) or r < 0: return 0
return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod
n, k = map(int, input().split())
MOD = 10**9 + 7
C = Combination(n)
k = min(k,n-1)
res = 0
for l in range(k+1):
res += C(n,l)*C.H(n-l,l)
print(res%MOD)
| 0 | null | 44,489,477,876,220 | 148 | 215 |
def insertionSort(A, n, g):
cnti = 0
for i in range(g, n):
v = A[i]
j = i-g
while (j >= 0 and A[j] > v):
A[j + g] = A[j]
j -= g
cnti += 1
A[j+g] = v
return cnti
def shellSort(A,n):
cnt = 0
G = [1]
h = 1
for k in range(int(n**0.33333333)+1):
h = 3*h + 1
if (h <= n and len(G) < 100):
G.append(h)
elif(len(G) == 100):
break
G.reverse()
m = len(G)
for i in range(m):
cnt += insertionSort(A, n, G[i])
print(m)
for i in range(m):
if (i == m-1):
print('{}'.format(G[i]), end = '')
else:
print('{}'.format(G[i]), end = ' ')
return cnt
n = int(input())
nlist = []
for i in range(n):
x = int(input())
nlist.append(x)
c = shellSort(nlist,n)
print()
print(c)
for i in nlist:
print(i)
| def insertion_sort(A):
for i in range(1, len(A)):
print(A)
v = A[i]
j = i - 1
while (j >= 0) and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
return A
def bubble_sort(A):
cnt = 0
flag = True
while flag:
flag = False
for i in sorted(range(1, len(A)), reverse=True):
if A[i] < A[i - 1]:
cnt += 1
tmp = A[i]
A[i] = A[i - 1]
A[i - 1] = tmp
flag = True
return A, cnt
def selection_sort(A):
for i in range(len(A)):
minj = i
for j in range(i, len(A)):
if A[j] < A[minj]:
minj = j
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
return A
def insertion_sort_for_shell(A, g):
cnt = 0
for i in range(g, len(A)):
v = A[i]
j = i - g
while (j >= 0) and (A[j] > v):
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = v
return A, cnt
def shell_sort(A):
cnt = 0
G = []
g = 1
while True:
G.append(g)
g = g *3 + 1
if g > len(A):
break
G = sorted(G, reverse=True)
for g in G:
A, c = insertion_sort_for_shell(A, g)
cnt += c
return A, G, cnt
def print_shell_sort_result(A, G, cnt):
print(len(G))
print(' '.join(map(str, G)))
print(cnt)
[print(a) for a in A]
if __name__ == '__main__':
N = int(input())
A = [0] * N
for i in range(N):
A[i] = int(input())
print_shell_sort_result(*shell_sort(A)) | 1 | 31,301,025,404 | null | 17 | 17 |
N, *XL = map(int, open(0).read().split())
XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))
curr = -float("inf")
ans = 0
for right, left in XL:
if left >= curr:
curr = right
ans += 1
print(ans)
| N=int(input())
XL=[]
for _ in range(N):
a=list(map(int,input().split()))
XL.append(a)
XL = sorted(XL, key=lambda x:x[0]+x[1])
#前から順に取っていく
#DP[i]:i番目までのロボットで残せるロボットの最大数
#i番目のロボットがどこまでをカバーしているかを格納する必要がある
DP=[[0,0] for i in range(N)]
DP[0][0]=1#個数
DP[0][1]=XL[0][0]+XL[0][1]#カバーしている距離
for i in range(1,N):
if XL[i][0]-XL[i][1]>=DP[i-1][1]:
DP[i][0]=DP[i-1][0]+1
DP[i][1]=XL[i][0]+XL[i][1]
else:
DP[i][0]=DP[i-1][0]
DP[i][1]=DP[i-1][1]
print(DP[-1][0]) | 1 | 89,784,525,901,912 | null | 237 | 237 |
import math
a, b, x = [int(n) for n in input().split()]
v = a**2 * b /2
#print(v, x)
if v == x:
theta = math.atan(b/a)
elif v > x:
theta = math.atan(a*(b**2)/(2*x))
elif v < x:
theta = math.atan(2/a*(b-x/a**2))
print(math.degrees(theta))
| class UnionFind:
par = None
def __init__(self, n):
self.par = [0] * n
def root(self, x):
if(self.par[x] == 0):
return x
else:
self.par[x] = self.root(self.par[x])
return self.root(self.par[x])
def unite(self, x, y):
if(self.root(x) != self.root(y)):
self.par[self.root(x)] = self.root(y)
def same(self, x, y):
return self.root(x) == self.root(y)
N, M = list(map(int, input().split()))
UF = UnionFind(N)
for i in range(M):
A, B = list(map(int, input().split()))
UF.unite(A - 1, B - 1)
ans = 0
for i in range(N):
if(UF.par[i] == 0):
ans += 1
print(ans - 1)
| 0 | null | 82,656,866,436,498 | 289 | 70 |
import math
N = int(input())
ans = math.ceil(N / 2.0)
print(ans)
| n = int(input())
s = list(input())
alp = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in range(len(s)):
for j in range(26):
if s[i] == alp[j]:
s[i] = alp[j+n]
break
print(''.join(s)) | 0 | null | 96,312,069,392,260 | 206 | 271 |
n=int(input())
R=[int(input()) for i in range(n)]
mini=10**10
maxi=-10**10
for r in R:
maxi=max([maxi,r-mini])
mini=min([mini,r])
print(maxi)
| k = int(input())
s = list(input())
an_lis = []
if len(s) <= k:
ans = "".join(s)
print(ans)
else:
for i in range(k):
an_lis.append(s[i])
an_lis.append("...")
ans = "".join(an_lis)
print(ans)
| 0 | null | 9,805,689,378,588 | 13 | 143 |
n = input()
for i in range(len(n)):
if(n[i] == '7'):
print("Yes")
exit()
print("No")
| l=[0]*120
s="#"*20
for i in range(input()):b,f,r,v=map(int,raw_input().split());l[b*30+f*10+r-41]+=v
print "",
for i in range(120):
print l[i],;j=i+1
if j==120:break
if j%30==0:print;print s,
if j%10==0:print;print "", | 0 | null | 17,829,316,574,468 | 172 | 55 |
N = int(input())
A = list(map(int, input().split()))
if N%2==0:
dp = [[0]*2 for _ in range(N)]
dp[0][0] = A[0]
dp[1][1] = A[1]
for i in range(2, N):
if i==2:
dp[i][0] = dp[i-2][0]+A[i]
else:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-3][0]+A[i], dp[i-2][1]+A[i])
print(max(dp[N-2][0], dp[N-1][1]))
else:
dp = [[0]*3 for _ in range(N)]
dp[0][0] = A[0]
dp[1][1] = A[1]
dp[2][2] = A[2]
for i in range(2, N):
if i==2:
dp[i][0] = dp[i-2][0]+A[i]
elif i==3:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-2][1]+A[i], dp[i-3][0]+A[i])
else:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-3][0]+A[i], dp[i-2][1]+A[i])
dp[i][2] = max(dp[i-4][0]+A[i], dp[i-3][1]+A[i], dp[i-2][2]+A[i])
print(max(dp[N-3][0], dp[N-2][1], dp[N-1][2])) | n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
ans, cnt = 0, 0
for i in range(n):
if i % 2 == 1:
ans += a[i]
cnt += a[i]
for i in range(n):
if i % 2 == 0:
cnt += a[i]
else:
cnt -= a[i]
ans = max(cnt, ans)
else:
a.insert(0, 0)
dp = [[0] * (n + 1) for _ in range(3)]
for i in range(3):
for j in range(1 + i, n + i - 1, 2):
if i == 0:
if j == 1:
dp[i][j] = a[j]
else:
dp[i][j] = dp[i][j - 2] + a[j]
else:
dp[i][j] = max(dp[i - 1][j - 1], dp[i][j - 2] + a[j])
ans = dp[2][n]
print(ans) | 1 | 37,337,388,565,760 | null | 177 | 177 |
m,n=[int(x) for x in input().split()]
if m==n:
print("Yes")
else:
print("No") | N,K = list(map(int,input().split()))
MOD = 10**9+7
arr = [pow(K//i, N, MOD) for i in range(1,K+1)]
for i in range(K//2,0,-1):
arr[i-1] -= sum(arr[2*i-1:K:i]) % MOD
arr[i-1] %= MOD
arr = [(i+1)*j%MOD for i,j in enumerate(arr)]
print(sum(arr)%MOD) | 0 | null | 60,434,192,290,652 | 231 | 176 |
import pdb
n = int(raw_input())
count = 0
for x in xrange(n):
target = int(raw_input())
# pdb.set_trace()
if target == 2:
count += 1
elif target < 3 or not target & 1:
continue
else:
if pow(2, target - 1, target) == 1:
count += 1
print count | import sys
import math
prime_numbers = [2, 3, 5, 7]
def prime_numbers_under(num):
global prime_numbers
prime_number_max = max(prime_numbers)
if prime_number_max > num:
return prime_numbers
for i in range(prime_number_max + 1, num + 1):
check_max = math.floor(math.sqrt(i))
for j in prime_numbers:
if j <= check_max:
if i % j == 0:
break
else:
prime_numbers.append(i)
return prime_numbers
def main():
amount = 0
length = int(input())
for _ in range(0, length):
i = int(input())
check_max = math.floor(math.sqrt(i))
for j in prime_numbers_under(check_max):
if j <= check_max:
if i % j == 0:
break
else:
amount += 1
print(amount)
return 0
if __name__ == '__main__':
main() | 1 | 10,950,109,350 | null | 12 | 12 |
import sys
l = []
for line in sys.stdin:
l.append(line)
for i in range(len(l)):
numl = l[i].split(' ')
a = int(numl[0])
b = int(numl[1])
sum = a + b
digitstr = "{0}".format(sum)
print(len(digitstr)) | while True:
try:
s = input()
a, b = [int(i) for i in s.split()]
print(len(str(a + b)))
except:
break
| 1 | 116,146,628 | null | 3 | 3 |
N = int(input())
S = [input() for _ in range(N)]
S.sort()
check = [True]*N
item = ""
item_ = ""
dict_item = {}
cnt = 0
for i in range(N):
item_ = S[i]
if item_ != item:
item = item_
cnt += 1
print(cnt) | import numpy as np
N = int(input())
data_list = []
for i in range(N):
si = input()
data_list.append(si)
data_list = np.array(data_list)
print(len(np.unique(data_list)))
| 1 | 30,309,316,811,776 | null | 165 | 165 |
N = input()
if N.find('7') > -1:
print('Yes')
else:
print('No') | N = input()
if '7' in N:
print('Yes')
exit()
else:
print('No') | 1 | 34,074,195,852,206 | null | 172 | 172 |
def main():
n = int(input())
_list = list(range(1,n+1))
for x in _list:
if x % 3 == 0 or any(list(map(lambda x: x == 3, list(map(int,list(str(x))))))):
print(' %d' % x, end = '')
print()
main() | # -*- coding:utf-8 -*-
n = int(input())
for i in range(2,n+1):
a = i // 10
a = a % 10
b = i // 100
b = b % 10
if i % 3 == 0:
print(' ',i,sep='',end='')
elif i % 10 == 3:
print(' ',i,sep='',end='')
elif a == 3:
print(' ',i,sep='',end='')
elif i // 100 == 3:
print(' ',i,sep='',end='')
elif i // 1000 == 3:
print(' ',i,sep='',end='')
elif i // 10000 == 3:
print(' ',i,sep='',end='')
elif b == 3:
print(' ',i,sep='',end='')
print('') | 1 | 923,436,403,612 | null | 52 | 52 |
import sys
N, K = map(int, sys.stdin.readline().split())
P = list(map(int, sys.stdin.readline().split()))
P.sort()
print(sum(P[0:K])) | def solve(n):
ret = []
while n > 26:
if n % 26 == 0:
ret = [26] + ret
n = (n - 26) // 26
else:
ret = [n % 26] + ret
n = n // 26
ret = [n] + ret
return ret
n = int(input())
ans = ''.join([chr(ord('a') + i - 1) for i in solve(n)])
print(ans) | 0 | null | 11,787,318,513,250 | 120 | 121 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for i in range(H):
print('#' * W)
print() | c = []
def listcreate():
global c
c = []
for y in range(a[0]):
b = []
for x in range(a[1]):
b.append("#")
c.append(b)
return
def listdraw():
global c
for y in range(len(c)):
for x in range(len(c[0])):
print(c[y][x], end='')
print()
return
for i in range(10000):
a = list(map(int,input().split()))
if sum(a)==0:
break
listcreate()
listdraw()
print()
| 1 | 776,455,711,910 | null | 49 | 49 |
K =int(input())
A,B = map(int,input().split())
q, mod = divmod(A, K)
if mod == 0:
print("OK")
elif K*(q+1) <= B:
print("OK")
else:
print("NG") | k = int(input())
a,b = map(int,input().split())
flag = False
for i in range(a,b + 1):
if i % k == 0:
flag = True
break
if flag:
print('OK')
else:
print('NG') | 1 | 26,519,814,314,492 | null | 158 | 158 |
N = int(input())
t = N//2
la, lb = [], []
for _ in range(N):
A, B = map(int, input().split())
la.append(A)
lb.append(B)
la.sort()
lb.sort()
print(lb[t]-la[t]+1 if N%2 else lb[t-1]-la[t]+lb[t]-la[t-1]+1)
| N = int(input())
As = []
Bs = []
for i in range(N):
A, B = map(int, input().split())
As.append(A)
Bs.append(B)
As.sort()
Bs.sort()
if N%2 == 1:
A = As[N//2]
B = Bs[N//2]
r = B-A+1
else:
A = As[(N-1)//2]+As[N//2]
B = Bs[(N-1)//2]+Bs[N//2]
r = B-A+1
print(r)
| 1 | 17,368,144,780,938 | null | 137 | 137 |
# ??¬????????±
room = [[[0 for a in range(10)] for b in range(3)] for c in range(4)]
n = int(input())
for cnt0 in range(n):
# ?????°??????????????????
a,b,c,d = map(int,input().split())
room[a-1][b-1][c-1]+=d
# ???????????±??????
for cnt1 in range(4):
for cnt2 in range(3):
for cnt3 in range(10):
# OutputPrit
print(" "+str(room[cnt1][cnt2][cnt3]),end="")
# ??????
print ()
if cnt1<3:
# ????£???????####################(20??????#)?????????
print("#"*20) | from bisect import bisect_left
X, N = list(map(int, input().split()))
P = list(map(int, input().split()))
P.sort()
S = set(P)
if N == 0:
print(X)
exit()
def bisectsearch_left(L, a):
i = bisect_left(L, a)
return(i)
k = bisectsearch_left(P, X)
if X != P[k]:
print(X)
else:
ct = 0
while True:
ct += 1
if X-ct not in S:
print(X-ct)
break
elif X+ct not in S:
print(X+ct)
break | 0 | null | 7,663,397,050,430 | 55 | 128 |
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
s = input()
if s == "AC":
ac += 1
elif s == "WA":
wa += 1
elif s == "TLE":
tle += 1
else:
re += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)
| N = int(input())
S, T = input().split()
ans = ""
for p in range(N):
ans += S[p]
ans += T[p]
print(ans) | 0 | null | 60,237,875,614,730 | 109 | 255 |
'''
問題:
高橋君と青木君がモンスターを闘わせます。
高橋君のモンスターは体力が A で攻撃力が B です。
青木君のモンスターは体力が C で攻撃力が D です。
高橋君→青木君→高橋君→青木君→... の順に攻撃を行います。
攻撃とは、相手のモンスターの体力の値を自分のモンスターの攻撃力のぶんだけ減らすことをいいます。
このことをどちらかのモンスターの体力が 0 以下になるまで続けたとき、
先に自分のモンスターの体力が 0 以下になった方の負け、そうでない方の勝ちです。
高橋君が勝つなら Yes、負けるなら No を出力してください。
'''
'''
制約:
1 ≦ A, B, C, D ≦ 100
入力は全て整数である
'''
class Monster:
def __init__(self, hp, power):
self.hp = hp
self.power = power
def fight(self, power) -> int:
self.hp -= power
return self.hp
def is_loser(self) -> bool:
return self.hp <= 0
# 標準入力から A, B, C, D を取得する
a, b, c, d = map(int, input().split())
takahashi_monster = Monster(a, b) # 高橋モンスター
aoki_monster = Monster(c, d) # 青木モンスター
result = "ret"
while True:
aoki_monster.fight(b) # 高橋の攻撃
if aoki_monster.is_loser():
result = "Yes"
break
takahashi_monster.fight(d) # 青木の攻撃
if takahashi_monster.is_loser():
result = "No"
break
print(result)
| X = int(input())
A = X // 500
B = X % 500
C = B // 5
ans = A * 1000 + C * 5
print(ans) | 0 | null | 36,157,974,455,730 | 164 | 185 |
import sys
input = sys.stdin.readline
h,w,m = map(int,input().split())
h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
hi,wi = map( lambda x : int(x) - 1 , input().split() )
h_array[hi] += 1
w_array[wi] += 1
ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i , wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h,_w) in ps:
continue
print(ans)
exit()
print(ans-1) | from collections import defaultdict
H, W, M = map(int, input().split())
row_bom_cnt = defaultdict(int)
col_bom_cnt = defaultdict(int)
row_max = 0
col_max = 0
boms = [list(map(int, input().split())) for _ in range(M)]
for rm, cm in boms:
row_bom_cnt[rm] += 1
col_bom_cnt[cm] += 1
row_max = max(row_max, row_bom_cnt[rm])
col_max = max(col_max, col_bom_cnt[cm])
target_row = set()
for r, val in row_bom_cnt.items():
if val == row_max:
target_row.add(r)
target_col = set()
for c, val in col_bom_cnt.items():
if val == col_max:
target_col.add(c)
cnt = 0
for rm, cm in boms:
if rm in target_row and cm in target_col:
cnt += 1
if len(target_row) * len(target_col) == cnt:
print(row_max + col_max - 1)
else:
print(row_max + col_max)
| 1 | 4,695,927,793,924 | null | 89 | 89 |
n=input()
s,t=input().split()
pt = (p + t for p, t in zip(s, t))
print(''.join(pt)) | N = int(input())
S,T = input().split()
for s,t in zip(S,T):
print(s+t,end="") | 1 | 112,126,879,476,380 | null | 255 | 255 |
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
len1 = T1 * A1 + T2 * A2
len2 = T1 * B1 + T2 * B2
if len1 == len2:
print("infinity")
quit()
ans = 0
subs = 0
sub1 = T1 * (A1 - B1)
sub2 = T2 * (A2 - B2)
if sub1 > 0:
if len1 - len2 > 0:
ans = 0
else:
S = (-1 * sub1) // (sub1 + sub2)
T = (-1 * sub1) % (sub1 + sub2)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
else:
if len1 - len2 < 0:
ans = 0
else:
S = (-1 * sub1) // (sub1 + sub2)
T = (-1 * sub1) % (sub1 + sub2)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
print(ans) | import sys
def log(s):
# print("| " + str(s), file=sys.stderr)
pass
def output(x):
print(x, flush=True)
def input_ints():
return list(map(int, input().split()))
def main():
f = input_ints()
print(f[0] * f[1])
main()
| 0 | null | 74,135,424,506,494 | 269 | 133 |
X, Y = map(int, input().split())
n = (2 * X - Y) // 3
m = (-X + 2 * Y) // 3
if n < 0 or m < 0 or (2 * X - Y) % 3 != 0 or (-X + 2 * Y) % 3 != 0:
print(0)
else:
# (n+m)Cn 通り
fac = [1, 1]
finv = [1, 1]
inv = [1, 1]
MOD = 10 ** 9 + 7
for i in range(2, n + m + 1):
fac.append(fac[i - 1] * i % MOD)
inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)
finv.append(finv[i - 1] * inv[i] % MOD)
print(fac[n+m] * (finv[n] * finv[m] % MOD) % MOD) | N = int(input())
A = list(map(int, input().split()))
b = [0] * N
for a in A:
b[a-1] += 1
for i in b:
print(i) | 0 | null | 91,250,946,564,452 | 281 | 169 |
s = input()
if s == "RRR":
print(3)
elif s == "RRS" or s == "SRR":
print(2)
elif s == "RSS" or s == "RSR" or s == "SRS" or s == "SSR":
print(1)
else:
print(0)
| s = input()
ans = 0
for i in range(3):
if s[i] == 'R':
ans += 1
else:
if ans == 1:
break
print(ans) | 1 | 4,902,927,547,908 | null | 90 | 90 |
import sys
import collections
X = int(input())
Angle = 360
for i in range(1,10**9):
if Angle < (X*i):
Angle = Angle + 360
if (Angle / (X*i)) == 1:
print(i)
sys.exit() | from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
def gcd(a, b):
if a % b == 0:
return b
else:
return gcd(b, a % b)
def main():
X = ri()
K = 360 // gcd(360, X)
print(K)
if __name__ == '__main__':
main()
| 1 | 13,018,747,215,682 | null | 125 | 125 |
MOD = 998244353
N,K = map(int,input().split())
l = []
dp = [0]*N
sdp = [0]*(N+1)
for i in range(K):
L,R = map(int,input().split())
l.append([L,R])
dp[0] = 1
sdp[1] = 1
for i in range(1,N):
for L, R in l:
dp[i] += sdp[max(0,i - L+1)] - sdp[max(0,i - R)]
dp[i] %= MOD
sdp[i+1] = sdp[i] + dp[i]
sdp[i+1] %= MOD
print(dp[N-1]) | #もらうDP + 累積和
n, k = map(int, input().split())
mod = 998244353
li = []
for _ in range(k):
l, r = map(int, input().split())
li.append((l, r))
li.sort()
dp = [0]*(2*n+1)
s = [0] * (2*n+1)
dp[1] = 1
s[1] = 1
for i in range(2, n+1):
for t in li:
l, r = t
dp[i] += s[max(i-l, 0)]
dp[i] -= s[max(i-r-1, 0)]
dp[i] %= mod
s[i] = s[i-1] + dp[i]
s[i] %= mod
print(dp[i]%mod) | 1 | 2,688,224,035,160 | null | 74 | 74 |
a,b=map(int,input().split());print(a*b) | A=list(map(int,input().split()))
print(A[0]*A[1]) | 1 | 15,812,338,572,252 | null | 133 | 133 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
sum_A = sum(A)
A.sort(reverse=True)
for a in A:
if a >= sum_A / (4 * M):
cnt += 1
else:
break
if cnt >= M:
print('Yes')
else:
print('No') | def main():
input_name = input()
print(input_name[0:3])
if __name__=='__main__':
main()
| 0 | null | 26,645,524,959,968 | 179 | 130 |
w,c = map(int,input().split())
res = w - (2*c)
if res < 0:
res =0
print(res) | A, B = map(int, input().split())
C = A - (B*2)
C = 0 if C < 0 else C
print(C) | 1 | 166,878,264,014,770 | null | 291 | 291 |
from math import ceil
N,X,T = list(map(int,input().split(' ')))
print(ceil(N/X)*T) | def popcount(x):
x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555)
x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333)
x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f)
x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff)
x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff)
x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff)
return x
n = int(input())
testimonies = [[] * n for _ in range(n)]
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
testimonies[i].append((x-1, y))
ans = 0
for bits in range(1, 1<<n):
possible = True
for i in range(n):
if not bits >> i & 1:
continue
for x, y in testimonies[i]:
if bits >> x & 1 != y:
possible = False
break
if not possible:
break
if possible:
ans = max(ans, popcount(bits))
print(ans) | 0 | null | 62,881,322,508,632 | 86 | 262 |
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
d={'r':p,'s':r,'p':s}
d_={'r':'p','s':'r','p':'s'}
s=0
for i in range(k):
a=0
z='0'
t_=t[i::k]
for a in range(len(t_)):
if a==0:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
else:
if z==d_[t_[a]]:
z='0'
a+=1
else:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
print(s)
| N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
cnt=[0 for _ in range(N)]
score={'r':P,'s':R,'p':S}
for i in range(N):
if i<K:
cnt[i]=score[T[i]]
else:
if T[i-K]!=T[i]:
cnt[i]=score[T[i]]
else:
if cnt[i-K]==0:
cnt[i]=score[T[i]]
print(sum(cnt))
| 1 | 107,161,022,676,228 | null | 251 | 251 |
import collections
zzz = 1
nn = int(input())
ans = 0
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
for i in range(1,nn):
zzz = 1
cc = collections.Counter(prime_factorize(i))
hoge = cc.values()
for aaa in hoge:
zzz *= aaa + 1
ans += zzz
print(ans) | from collections import Counter
n = int(input())
if n == 1:
print(0)
else:
lis = [i for i in range(n+1)]
for i in range(2, int(n**0.5) + 1):
if lis[i] == i:
lis[i] = i
for j in range(i**2, n+1, i):
if lis[j] == j:
lis[j] = i
#print(lis)
def bunkai(m):
ans = []
now = lis[m]
cnt = 1
for i in range(m):
m = m//lis[m]
if now == lis[m]:
cnt += 1
else:
ans.append(cnt)
cnt = 1
now = lis[m]
if m == 1:
break
return ans
ans = 1
for i in range(2,n):
tmp = 1
yaku = bunkai(i)
for i in yaku:
tmp *= (i +1)
ans += tmp
print(ans)
| 1 | 2,576,612,748,060 | null | 73 | 73 |
a,b,c,d = map(float,input().split())
print(abs(complex(c-a,d-b))) | a,b,c,d=map(float,input().split())
x=abs(a-c)
y=abs(b-d)
z=x**2+y**2
print(pow(z,0.5))
| 1 | 157,413,117,522 | null | 29 | 29 |
input()
*l,=map(int,input().split())
ans=0
for i in l:
for j in l:
ans+=i*j
print((ans-sum([pow(x,2) for x in l]))//2) | from itertools import combinations
N = int(input())
d = list(map(int, input().split()))
info = list(combinations(d, 2))
ans = 0
for x, y in info:
ans += x*y
print(ans)
| 1 | 168,384,450,302,430 | null | 292 | 292 |
from collections import Counter
def main():
H, W, M = list(map(int, input().split()))
bombs = [list(map(int, input().split())) for _ in range(M)]
counter_row = Counter([h for h, _ in bombs])
val_max_row, max_rows = 0, []
for h, v in counter_row.items():
if val_max_row < v:
val_max_row = v
max_rows = [h]
elif val_max_row == v:
max_rows.append(h)
counter_col = Counter([w for _, w in bombs])
val_max_col, max_cols = 0, []
for w, v in counter_col.items():
if val_max_col < v:
val_max_col = v
max_cols = [w]
elif val_max_col == v:
max_cols.append(w)
# 基本的には val_max_row + val_max_col が答え。
# 行・列で重複カウントになるケースだった場合はここから1引かないといけない。
max_rows = Counter(max_rows)
max_cols = Counter(max_cols)
n_max_cells = len(max_rows.keys()) * len(max_cols.keys())
n_cells = 0
for h, w in bombs:
if max_rows[h] > 0 and max_cols[w] > 0:
n_cells += 1
ans = val_max_row + val_max_col
if n_cells >= n_max_cells:
ans -= 1
print(ans)
if __name__ == '__main__':
main() | #from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
# # # # unionfind.py # # # #
# usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b)
class Unionfind:
def __init__(s,n):
s.sz = [1] * n
s.ances = [i for i in range(n)]
def root(s,x):
a = []
y = x
while s.ances[y] != y:
a.append(y)
y = s.ances[y]
for z in a:
s.ances[z] = y
return y
def conn(s,x,y):
i = s.root(x)
j = s.root(y)
if i==j:
return
#k = [i,j].min
k = j if (s.sz[i]<s.sz[j]) else i
if k==j:
s.ances[i] = j
else:
s.ances[j] = i
s.sz[k] = s.sz[i] + s.sz[j]
# # # # end unionfind.py # # # #
n,m = inm()
uf = Unionfind(n)
for i in range(m):
a,b = inm()
uf.conn(a-1,b-1)
h = {}
x = 0
for i in range(n):
r = uf.root(i)
if r not in h:
h[r] = 1
else:
h[r] += 1
x = max(x,h[r])
print(x)
| 0 | null | 4,347,326,567,108 | 89 | 84 |
from collections import deque
def main():
n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
adj[a - 1].append(b - 1)
adj[b - 1].append(a - 1)
ans = 0
visited = [False] * n
for i in range(n):
if visited[i]:
continue
q = deque()
q.append(i)
cnt = 1
visited[i] = True
while q:
u = q.popleft()
for v in adj[u]:
if not visited[v]:
q.append(v)
cnt += 1
visited[v] = True
ans = max(ans, cnt)
print(ans)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
while(True):
try:
a,b=map(int, input().split())
except EOFError:
break
#euclidian algorithm
r=a%b
x,y=a,b
while(r>0):
x=y
y=r
r=x%y
gcd=y
lcm=int(a*b/gcd)
print("{0} {1}".format(gcd, lcm)) | 0 | null | 2,010,250,996,698 | 84 | 5 |
import sys
import math
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
R, C, K = NMI()
grid = make_grid_int(R, C, 0)
for i in range(K):
r, c, v = NMI()
grid[r-1][c-1] = v
dp = [[[0 for _ in range(C+2)] for _ in range(R+2)] for _ in range(4)]
for r in range(R+1):
for c in range(C+1):
for i in range(4):
now = dp[i][r][c]
try:
val = grid[r][c]
except:
val = 0
if i == 3:
# 取らずに下
dp[0][r + 1][c] = max(now, dp[0][r + 1][c])
continue
# 取って下
dp[0][r+1][c] = max(now + val, dp[0][r+1][c])
# 取らずに下
dp[0][r+1][c] = max(now, dp[0][r+1][c])
# 取って横
dp[i+1][r][c+1] = max(now + val, dp[i+1][r][c+1])
# 取らずに横
dp[i][r][c+1] = max(now, dp[i][r][c+1])
print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
if __name__ == "__main__":
main()
| n = input()
s = list(map(int, input().split()))
nn = input()
t = list(map(int, input().split()))
t_and_s = len(set(s) & set(t))
print(t_and_s) | 0 | null | 2,825,606,059,592 | 94 | 22 |
import numpy as np
H, W = map(int,input().split())
if H == 1 or W == 1:
print(1)
else:
print(int(np.ceil((H * W) / 2))) | w,h = map(int, input().split())
x = w*h
if h !=1 and w != 1:
print((h*w+1)//2)
else:
print(1) | 1 | 51,120,561,333,258 | null | 196 | 196 |
def main():
N=int(input())
A=list(map(int,input().split()))
L={}
R={}
for i in range(N):
l=(i+1)+A[i]
r=(i+1)-A[i]
if (l in L.keys()):
L[l]+=1
else:
L[l]=1
if r in R.keys():
R[r]+=1
else:
R[r]=1
res=0
for key in L.keys():
if key in R.keys():
res+=R[key]*L[key]
print(res)
if __name__=="__main__":
main()
| n, k = map(int, input().split())
count = 0
for i in range(k, n + 2):
if i == k:
tot_min = 0
tot_max = 0
for j in range(i):
tot_min += j
tot_max += n - j
else:
tot_min += i - 1
tot_max += n - i + 1
count += tot_max - tot_min + 1
count %= 10 ** 9 + 7
print(count) | 0 | null | 29,647,207,318,838 | 157 | 170 |
#coding:utf-8
#1_3_B
from collections import deque
n, quantum = map(int, input().split())
q = deque()
total_time = 0
for i in range(n):
name, time = input().split()
q.append([name, int(time)])
while q:
ps_name, ps_time = q.popleft()
if ps_time <= quantum:
total_time += ps_time
print(ps_name, total_time)
else:
total_time += quantum
ps_time -= quantum
q.append([ps_name, ps_time]) | X = int(input())
x500 = X//500
amari = X - x500 * 500
x5 = amari // 5
print(x500*1000+x5*5) | 0 | null | 21,396,138,042,718 | 19 | 185 |
import sys
readline = sys.stdin.readline
def main():
A, B, M = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
ans = min(a) + min(b)
for _ in range(M):
x, y, c = map(int, readline().split())
ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)
if __name__ == "__main__":
main()
| a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = []
ans.append(min(A)+min(B))
for i in range(m):
M = list(map(int,input().split()))
tmp = A[M[0]-1] + B[M[1]-1] -M[2]
ans.append(tmp)
print(min(ans))
| 1 | 53,819,418,904,042 | null | 200 | 200 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8, i8, i8, i8[:,:]), cache=True)
def solve(R,C,K,item):
dp = np.zeros((C+1,5), dtype=np.int64)
for i in range(1,R+1):
new_dp = np.zeros((C+1,5), dtype=np.int64)
#上からアイテムを取らずに移動
new_dp[:,0] = dp[:,-1]
#上からアイテムを取って移動
new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1])
for j in range(1,C+1):
#横からアイテムを取らずに移動
new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
#横からアイテムを取って移動
for k in range(1,4):
new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
for k in range(4):
new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
dp = new_dp
ans = dp[-1,-1]
return ans
R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
r,c,v = map(int, input().split())
item[r-1,c-1] = v
print(solve(R,C,K,item)) | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def solve():
dp0 = [0] * (w + 1)
dp1 = [0] * (w + 1)
dp2 = [0] * (w + 1)
dp3 = [0] * (w + 1)
for i in range(h):
for j in range(w):
v = vv[i * w + j]
if v:
dp3[j] = max(dp3[j], dp2[j] + v)
dp2[j] = max(dp2[j], dp1[j] + v)
dp1[j] = max(dp1[j], dp0[j] + v)
dp3[j + 1] = max(dp3[j + 1], dp3[j])
dp2[j + 1] = max(dp2[j + 1], dp2[j])
dp1[j + 1] = max(dp1[j + 1], dp1[j])
dp0[j] = max(dp1[j], dp2[j], dp3[j])
print(dp0[-2])
h, w, k = MI()
vv = [0] * h * w
for _ in range(k):
i, j, v = MI()
i, j = i - 1, j - 1
vv[i * w + j] = v
solve()
| 1 | 5,573,432,787,248 | null | 94 | 94 |
S = input()
if(S.endswith('s')):
print(S+'es')
else:
print(S+'s') |
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
S=input()
if S[-1]=="s":
S+="es"
else:
S+="s"
print(S)
main()
| 1 | 2,357,521,366,160 | null | 71 | 71 |
W,H,x,y,r = map(int, raw_input().split())
if (r <= x <= (W - r)) and (r <= y <= (H - r)):
print "Yes"
else:
print "No" | from itertools import product
H, W, K = map(int, input().split())
G = [list(map(int, list(input()))) for _ in range(H)]
ans = float("inf")
for pattern in product([0, 1], repeat = H - 1):
div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H]
rows = []
for i in range(len(div) - 1):
row = []
for j in range(W):
tmp = 0
for k in range(div[i], div[i + 1]):
tmp += G[k][j]
row.append(tmp)
rows.append(row)
flag = True
for row in rows:
if [r for r in row if r > K]:
flag = False
break
if not flag:
continue
tmp_ans = 0
cnt = [0] * len(rows)
w = 0
while w < W:
for r in range(len(rows)):
cnt[r] += rows[r][w]
if [c for c in cnt if c > K]:
cnt = [0] * len(rows)
tmp_ans += 1
w -= 1
w += 1
tmp_ans += pattern.count(1)
ans = min(ans, tmp_ans)
print(ans) | 0 | null | 24,555,329,452,862 | 41 | 193 |
K = int(input())
string = "ACL"
print(string * K) | for _ in range(int(input())):
print("ACL", end="") | 1 | 2,163,254,681,540 | null | 69 | 69 |
from collections import deque
def main():
H,W=map(int,input().split())
S=[]
for i in range(H):
s=input()
S.append(s)
G=[]
for i in range(H):
for j in range(W):
tmp=[]
if S[i][j]=="#":
G.append(tmp)
continue
if i-1>=0:
if S[i-1][j]==".":
tmp.append((i-1)*W+j)
if i+1<=H-1:
if S[i+1][j]==".":
tmp.append((i+1)*W+j)
if j-1>=0:
if S[i][j-1]==".":
tmp.append(i*W+j-1)
if j+1<=W-1:
if S[i][j+1]==".":
tmp.append(i*W+j+1)
G.append(tmp)
res=0
for start in range(H*W):
dist = 0
v = [-1 for _ in range(H * W)]
que=deque([])
que.append(start)
v[start]=dist
while len(que)>0:
next_index=que.popleft()
next=G[next_index]
for i in next:
if v[i]==-1:
que.append(i)
v[i]=v[next_index]+1
if max(v)>=res:
res=max(v)
print(res)
if __name__=="__main__":
main()
| from copy import deepcopy
from collections import Counter, defaultdict, deque
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
def maze_solve(S_1,S_2,maze_list):
d = deque()
dist[S_1][S_2] = 0
d.append([S_1,S_2])
dx = [0,0,1,-1]
dy = [1,-1,0,0]
while d:
v = d.popleft()
x = v[0]
y = v[1]
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx < 0 or nx >= h or ny < 0 or ny >= w:
continue
if dist[nx][ny] == -1:
dist[nx][ny] = dist[x][y] + 1
d.append([nx,ny])
return max(list(map(lambda x: max(x), dist)))
h,w = MI()
ans = 0
maze = [list(input()) for _ in range(h)]
dist = [[-1]*w for _ in range(h)]
start_list = []
for i in range(h):
for j in range(w):
if maze[i][j] == "#":
dist[i][j] = 0
else:
start_list.append([i,j])
dist_copy = deepcopy(dist)
for k in start_list:
dist = deepcopy(dist_copy)
ans = max(ans,maze_solve(k[0],k[1],maze))
print(ans) | 1 | 94,730,827,636,632 | null | 241 | 241 |
S=input()
count = 0
for i in range(len(S)//2):
if S[i] != S[-1-i]:count+=1
print(count) | import numpy as np
import scipy as sp
import math
S = input()
n = len(S)
m = n//2
l = 0
for i in range (0,m):
if(S[i] != S[n-i-1]):
l = l + 1
print(l) | 1 | 120,366,770,005,690 | null | 261 | 261 |
n = int(input())
for _ in range(n):
edges = sorted([int(i) for i in input().split()])
if edges[0] ** 2 + edges[1] ** 2 == edges[2] ** 2:
print("YES")
else:
print("NO")
| n = int(input())
A = list(enumerate(list(map(int, input().split()))))
A.sort(key=lambda x:x[1])
ans = []
for i in A: ans.append(str(i[0]+1))
print(" ".join(ans)) | 0 | null | 90,120,406,951,820 | 4 | 299 |
N = int(input())
ans = 0
for i in range(1, N+1):
if i % 3 == 0:
continue
if i % 5 == 0:
continue
ans += i
print(ans)
| X,N = map(int,input().split())
p = list(map(int,input().split()))
for i in range(X+1):
for j in [-1,1]:
a = X + i*j
if p.count(a) == 0:
print(a)
exit(0) | 0 | null | 24,437,475,874,982 | 173 | 128 |
from collections import deque
q = deque()
for _ in range(int(input())):
b=input()
if b[0] == 'i':
q.appendleft(b[7:])
elif b[6] == ' ':
try:
q.remove(b[7:])
except:
pass
elif len(b) > 10:
q.popleft()
elif len(b) > 6:
q.pop()
print(*q)
| from collections import deque
n = int(input())
mylist = deque()
for i in range(n):
a = input()
if a == "deleteFirst":
mylist.popleft()
elif a == "deleteLast":
mylist.pop()
else:
a,key = a.split()
if a == "insert":
mylist.appendleft(key)
else:
try:
mylist.remove(key)
except:
pass
print(' '.join(mylist))
| 1 | 47,579,445,368 | null | 20 | 20 |
if __name__=="__main__":
num = int(input())
if num < 400:
pass
elif num<600:
print(8)
elif num<800:
print(7)
elif num<1000:
print(6)
elif num<1200:
print(5)
elif num<1400:
print(4)
elif num<1600:
print(3)
elif num<1800:
print(2)
elif num<2000:
print(1) | while True:
try:
a, b = map(int, raw_input().split())
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
g = gcd(a,b)
l = a*b/g
print g, l
except:
break | 0 | null | 3,379,943,220,950 | 100 | 5 |
#41
import math
N = int(input())
p = list(map(int,input().split()))
cou = 0
x = math.inf
for j in range(N):
if min(x,p[j]) == p[j]:
x = p[j]
cou += 1
print(cou)
| import sys
input = sys.stdin.readline
n, s, c = int(input()), list(map(int, input().split())), 0
m = s[0]
for i in range(n):
if s[i] <= m: m = s[i]; c += 1
print(c) | 1 | 85,313,814,798,058 | null | 233 | 233 |
a, b = map(int, input().split())
if a > b: a, b = b, a
while True:
if b % a == 0:
print(a)
break
else:
b = b % a
if a > b: a, b = b, a | def main():
N = int(input())
A = input().split()
if len(set(A)) == N:
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
| 0 | null | 36,737,295,936,300 | 11 | 222 |
import sys
input = lambda: sys.stdin.readline().rstrip()
s = input()
n = len(s)
if n == s.count("hi")*2:
print("Yes")
else:
print("No") | s = input()
while s[0:2:] == "hi":
s = s[2::]
if len(s) == 0:
print("Yes")
else:
print("No") | 1 | 53,063,408,887,648 | null | 199 | 199 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
S = list(map(int, LS()))
S = S[::-1]
ln = len(S)
mod = 2019
times = 1
for i in range(ln):
S[i] = S[i] * times
times = times * 10 % mod
R = [0] * (ln+1)
memo = {0: 1}
ans = 0
for i in range(1, ln+1):
tmp = (R[i-1] + S[i-1]) % mod
R[i] = tmp
cnt = memo.get(tmp, 0)
ans = ans + cnt
memo[tmp] = cnt + 1
print(ans)
if __name__ == '__main__':
solve()
| def i():
return int(input())
def i2():
return map(int,input().split())
def s():
return str(input())
def l():
return list(input())
def intl():
return list(int(k) for k in input().split())
n = i()
s = s()
cnt = 0
for i in range(n-2):
if s[i]+s[i+1]+s[i+2] == "ABC":
cnt += 1
print(cnt) | 0 | null | 64,739,491,591,852 | 166 | 245 |
N = int(input())
Stones = list(input())
count_red = 0
count_white = 0
for i in range(N):
if Stones[i] == "R":
count_red += 1
for i in range(count_red):
if Stones[i] == "W":
count_white += 1
print(count_white) | N = int(input())
s = input()
ans = min(s.count('R'), s.count('W'), s[N-s.count('W'):].count('R'))
print(ans) | 1 | 6,231,310,734,012 | null | 98 | 98 |
b=int(input())
a=list(map(int,input().split()))
ans=""
total=0
for i in a:
total^=i
for i in a:
ans+=str(total^i)+" "
print(ans) | import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
n = int(input())
A = list(map(int, input().split()))
xor = 0
for a in A:
xor ^= a
ans = [a ^ xor for a in A]
print(*ans)
resolve() | 1 | 12,396,145,879,260 | null | 123 | 123 |
import sys
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int, input().split())
INF = 10 **9 +1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
a, b, c = map(int, input().split())
a, b, = a - 1, b -1
G[a][b] = c
G[b][a] = c
#全点間最短距離を計算
G = floyd_warshall(G)
#コストL以下で移動可能な頂点間のコスト1の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
for j in range(N):
if G[i][j] <= L:
E[i][j] = 1
#全点間最短距離を計算
E = floyd_warshall(E)
#クエリに答えていく
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
s, t = s - 1, t-1
print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1) | s = input()
s = s[::-1]
m = [0] * 2019
m[0] = 1
a = 0
d = 1
ans = 0
for si in s:
a = (a + int(si) * d) % 2019
d = (d * 10) % 2019
ans += m[a]
m[a] += 1
print(ans)
| 0 | null | 102,117,404,665,920 | 295 | 166 |
N = int(input())
S = input()
Q = int(input())
qs = [input().split() for i in range(Q)]
def ctoi(c):
return ord(c) - ord('a')
class BinaryIndexedTree:
def __init__(self,size):
self.N = size
self.bit = [0]*(size+1)
def add(self,x,w): # 0-indexed
x += 1
while x <= self.N:
self.bit[x] += w
x += (x & -x)
def _sum(self,x): # 1-indexed
ret = 0
while x > 0:
ret += self.bit[x]
x -= (x & -x)
return ret
def sum(self,l,r): # [l,r)
return self._sum(r) - self._sum(l)
def __str__(self): # for debug
arr = [self.sum(i,i+1) for i in range(self.N)]
return str(arr)
bits = [BinaryIndexedTree(N) for i in range(26)]
s = []
for i,c in enumerate(S):
bits[ctoi(c)].add(i,1)
s.append(c)
ans = []
for a,b,c in qs:
if a=='1':
i = int(b)-1
bits[ctoi(s[i])].add(i,-1)
bits[ctoi(c)].add(i,1)
s[i] = c
else:
l,r = int(b)-1,int(c)
a = 0
for i in range(26):
if bits[i].sum(l,r):
a += 1
ans.append(a)
print(*ans,sep='\n') | h = int(input())
cnt = 0
while h > 1:
h //= 2
cnt += 1
print(2**(cnt+1)-1) | 0 | null | 71,361,024,166,130 | 210 | 228 |
import math
a=float(input())
print("{0:.9f} {1:.9f}".format(a*a*math.pi,a*2*math.pi))
| from math import pi
r = float(input())
z = r*r*pi
l = 2*r*pi
print('{} {}'.format(z,l)) | 1 | 652,070,046,470 | null | 46 | 46 |
N = int(input())
S = str(input())
i = 0
ans = len(S)
for i in range(len(S)-1):
if S[i] == S[i+1]:
ans -= 1
print(ans) |
from bisect import bisect_right
N, D, A = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
place = []
hps = []
for x, h in X:
place.append(x)
hps.append(h)
buf = [0] * (N + 2)
ans = 0
for i in range(N):
# Update
buf[i + 1] += buf[i]
# Calc count
tmp = -(-max(0, hps[i] - buf[i + 1] * A) // A)
ans += tmp
# Calc range
j = bisect_right(place, place[i] + D * 2)
buf[i + 1] += tmp
buf[min(j + 1, N + 1)] -= tmp
print(ans)
| 0 | null | 125,953,553,873,910 | 293 | 230 |
a,b,k=map(int,input().split())
if a>=k:
print(a-k,b)
else:
print(0,max(b+a-k,0)) | A,B,K=map(int,input().split())
if K<A:
ans1=A-K
ans2=B
else:
ans1=0
ans2=max(A+B-K,0)
print(ans1,ans2) | 1 | 104,246,046,016,938 | null | 249 | 249 |
from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
s=set()
for i in range(1,n+1):
for j in combinations(a,i):
s.add(sum(j))
for i in m:
if i in s:
print("yes")
else:
print("no")
| S = input()
print("%s:%s:%s"%(S/3600,(S//60)%60,S%60)) | 0 | null | 211,879,658,650 | 25 | 37 |
import math
m=[float(i)for i in input().split()]
x=m[2]-m[0]
y=m[3]-m[1]
print(math.sqrt(float(x*x+y*y))) | n,m = map(int,input().split())
a = []
b = []
c = []
for i in range(n):
a.append([int(j) for j in input().split()])
for k in range(m):
b.append(int(input()))
for x in range(n):
z = 0
for y in range(m):
z += a[x][y] * b[y]
c.append(z)
for i in c:
print(i)
| 0 | null | 651,786,078,368 | 29 | 56 |
from math import log, ceil
N, K = map(int, input().split())
res = ceil(log(N, K))
if res == 0:
res = 1
print(res) | from math import log
n, k = map(int, input().split())
print(int(log(n, k)) + 1) | 1 | 64,646,212,141,052 | null | 212 | 212 |
N = input()
n = len(N)
a = int(N[0])
b = 11-int(N[0])
for i in range(n-1):
a1 = min(a+int(N[i+1]), b+int(N[i+1]))
b1 = min(a+11-int(N[i+1]), b+9-int(N[i+1]))
a = a1
b = b1
print(min(a,b)) | s = input()
n = len(s)
ans = 0
sub = 0
judge = False
for i in range(n-1, -1, -1):
key = int(s[i])+sub
if key <= 4:
ans += key
sub = 0
elif key == 5:
ans += 5
if i == 0:
sub = 0
elif int(s[i-1]) <= 4:
sub = 0
else:
sub = 1
else:
ans += 10-key
sub = 1
ans += sub
print(ans) | 1 | 71,414,338,894,872 | null | 219 | 219 |
import sys
stdin = sys.stdin
ni = lambda: int(ns())
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))
# code here
N, R = na()
if N >= 10:
print(R)
else:
print(R + 100*(10-N))
| def solve():
N = int(input())
dfs("", 0, N)
def dfs(cur, n_type, N):
if len(cur) == N:
print(cur)
return
for offset in range(n_type+1):
next_chr = chr(ord('a') + offset)
next_n_type = n_type + 1 if offset==n_type else n_type
dfs(cur+next_chr, next_n_type, N)
return
if __name__ == '__main__':
solve() | 0 | null | 57,946,221,974,290 | 211 | 198 |
n,q = map(int,input().split())
name = []
time = []
for i in range(n):
tmp = input().split()
name.append(str(tmp[0]))
time.append(int(tmp[1]))
total = 0
result = []
while True:
try:
if time[0] > q:
total += q
time[0] = time[0] - q
tmp = time.pop(0)
time.append(tmp)
tmp = name.pop(0)
name.append(tmp)
elif q >= time[0] and time[0] > 0:
total += time[0]
time.pop(0)
a = name.pop(0)
print(a,total)
else:
break
except:
break | n,q = map(int,raw_input().split())
task = []
lst = []
a = 0
for i in range(n):
name,time = raw_input().split()
task.append(int(time))
lst.append(name)
while True:
if task[0] > q:
task[0] = task[0] - q
task.append(task.pop(0))
lst.append(lst.pop(0))
a += q
else:
a += task[0]
print lst[0],a
task.pop(0)
lst.pop(0)
if len(lst) == 0:
break | 1 | 46,395,948,128 | null | 19 | 19 |
a, b, c =map(int, input().split())
d=(a-1)//c
e=b//c
ans=e-d
print(ans) | a,b,c=map(int,input().split())
if b%c==0 or a%c==0:
print(int((b-a)/c)+1)
else:
print(int((b-a)/c)) | 1 | 7,572,660,998,548 | null | 104 | 104 |
import math
from math import cos, sin
a,b,C=map(float,input().split())
C = math.radians(C)
S = 0.5*a*b*sin(C)
L = math.sqrt(b**2+a**2-2*a*b*cos(C))+a+b
h = 2*S / a
print(S)
print(L)
print(h) | import math
a,b,C=map(float,input().split())
print(f'{a*b/2*math.sin(math.radians(C)):.6f}')
print(f'{a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**0.5:.6f}')
print(f'{b*math.sin(math.radians(C)):.6f}')
| 1 | 176,661,972,420 | null | 30 | 30 |
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))
from bisect import bisect_right as br
def main():
dic = {}
for i in range(1,N + 1):
A[ i ] += A[ i - 1 ]
for j in range(N + 1):
if (A[j] - j)%K in dic:
dic[(A[j] - j)%K].append(j)
else:
dic[(A[j] - j)%K] = [j]
ans = 0
for i in range(1,N + 1):
tmp = dic[(A[i] - i)%K]
left = br(tmp,i - K)
right = br(tmp,i) - 1
ans += right - left
print(ans)
return
if __name__ == "__main__":
main() | '''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
#setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
n,k = map(int,ipt().split())
a = [int(i) for i in ipt().split()]
memo = deque()
memo.append(0)
d = defaultdict(int)
ans = 0
nv = 0
d[0] += 1
for i,ai in enumerate(a):
nv += ai-1
nv %= k
memo.append(nv)
if i >= k-1:
pi = memo.popleft()
d[pi] -= 1
ans += d[nv]
d[nv] += 1
print(ans)
return None
if __name__ == '__main__':
main()
| 1 | 137,615,389,300,520 | null | 273 | 273 |
def main():
a,b = input().split()
b = b[0] + b[2:]
print(int(a)*int(b)//100)
if __name__ == "__main__":
main()
| def abc169c_multiplication3():
a, b = input().split()
a = int(a)
b = int(b[0] + b[2] + b[3])
print(a * b // 100)
abc169c_multiplication3()
| 1 | 16,502,275,010,342 | null | 135 | 135 |
def Euclidean(input_list):
# print input_list
x = input_list[1]
y = input_list[0]
r = x % y
if r != 0:
list = [r, y]
list.sort()
return Euclidean(list)
else:
return y
list = map(int, raw_input().split(" "))
list.sort()
print Euclidean(list) | def gcd(x, y):
if x < y:
return gcd(y, x)
if y == 0:
return x
return gcd(y, x % y)
x, y = map(int, input().split())
print(gcd(x, y))
| 1 | 8,519,437,828 | null | 11 | 11 |
n = int(input())
a = input()
s=list(map(int,a.split()))
q = int(input())
a = input()
t=list(map(int,a.split()))
i = 0
for it in t:
if it in s:
i = i+1
print(i) | X, Y = map(int, input().split())
MOD = 10 ** 9 + 7
def modpow(x, n):
ret = 1
while n > 0:
if n & 1:
ret = ret * x % MOD
x = x * x % MOD
n >>= 1
return ret
def modinv(x):
return modpow(x, MOD - 2)
def modf(x):
ret = 1
for i in range(2, x + 1):
ret *= i
ret %= MOD
return ret
ans = 0
if (X + Y) % 3 == 0:
m = (2 * X - Y) // 3
n = (2 * Y - X) // 3
if m >= 0 and n >= 0:
ans = modf(m + n) * modinv(modf(n) * modf(m))
ans %= MOD
print(ans) | 0 | null | 74,782,149,707,658 | 22 | 281 |
n = int(input())
A = list(map(int,input().split()))
f = 1
c = 0
while f == 1:
f = 0
for j in range(n-1,0,-1):
if A[j] < A[j-1]:
inc = A[j]
A[j] = A[j-1]
A[j-1] = inc
f = 1
c += 1
print(" ".join(map(str,A)))
print(c) | n=int(input())
if(n%2==0):
print((n//2)/n)
else:
print((n//2+1)/n) | 0 | null | 88,808,447,720,138 | 14 | 297 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.