code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N = int(input())
XY = []
points = []
for i in range(N):
points.append(i)
x, y = list(map(int, input().split()))
XY.append((x, y))
import math
import itertools
count = math.factorial(N)
line = 0
for pp in itertools.permutations(points, N):
i = 0
while i < N - 1:
i1, i2 = pp[i], pp[i + 1]
t = ((XY[i1][0] - XY[i2][0]) ** 2 + (XY[i1][1] - XY[i2][1]) ** 2) ** 0.5
line += t
i += 1
ans = line / count
print(ans)
| #
# abc145 c
#
import sys
from io import StringIO
import unittest
import math
import itertools
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """3
0 0
1 0
0 1"""
output = """2.2761423749"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2
-879 981
-866 890"""
output = """91.9238815543"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310"""
output = """7641.9817824387"""
self.assertIO(input, output)
def resolve():
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]
R = itertools.permutations(range(N))
all = 0
for r in R:
for pi in range(1, len(r)):
all += math.sqrt((P[r[pi]][0]-P[r[pi-1]][0])**2 +
(P[r[pi]][1]-P[r[pi-1]][1])**2)
n = 1
for i in range(1, N+1):
n *= i
print(f"{all/n:.10f}")
if __name__ == "__main__":
# unittest.main()
resolve()
| 1 | 148,393,911,585,940 | null | 280 | 280 |
n = int(input())
m = list(map(int, input().split()))
count = 0
for i in range(n-1):
minj =i
for j in range(i+1, n):
if m[j] < m[minj]:
minj = j
if m[i] != m[minj]:
m[i], m[minj] = m[minj], m[i]
count += 1
print(" ".join(str(x) for x in m))
print(count) | N = int(input())
S = list(map(int, input().split(" ")))
Exchange_Number_of_times = 0
for i in range(N):
minj = i
for j in range(i, N):
if S[j] < S[minj]:
minj = j
if i != minj:
S[i], S[minj] = S[minj], S[i]
Exchange_Number_of_times += 1
print(' '.join(map(str,S)))
print(Exchange_Number_of_times)
| 1 | 19,833,721,248 | null | 15 | 15 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
h, a = map(int, input().split())
ans = h//a + (h%a!=0)
print(ans) | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, A: int, B: int):
return N//(A+B) * A + min(N % (A+B), A)
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
print(f'{solve(N, A, B)}')
if __name__ == '__main__':
main()
| 0 | null | 66,143,028,885,152 | 225 | 202 |
def knapsack_weight(single=True):
"""
重さが小さい時のナップサックDP
:param single: True = 重複なし
"""
""" dp[weight <= W] = 重さ上限を固定した時の最大価値 """
dp_min = 0 # 総和価値の最小値
dp = [dp_min] * (W + 1)
for item in range(N):
if single:
S = range(W, weight_list[item] - 1, -1)
else:
S = range(weight_list[item], W + 1)
for weight in S:
if weight - weight_list[item] < T:
dp[weight] = max2(dp[weight], dp[weight - weight_list[item]] + price_list[item])
return max(dp[T:])
import sys
input = sys.stdin.readline
def max2(x, y):
return x if x > y else y
def min2(x, y):
return x if x < y else y
N, T = map(int, input().split()) # N: 品物の種類 W: 重量制限
price_list = []
weight_list = []
data = []
for _ in range(N):
weight, price = map(int, input().split())
data.append((weight, price))
data.sort()
for weight, price in data:
price_list.append(price)
weight_list.append(weight)
max_weight = max(weight_list)
W = T + max_weight - 1
print(knapsack_weight(single=True)) | #!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7
def main():
N, T = map(int, input().split())
AB = []
for _ in range(N):
AB.append(list(map(int, input().split())))
AB.sort()
dp = [0] * (T + 1)
ans = 0
for i in range(N-1):
for j in range(T, -1, -1):
if j + AB[i][0] <= T:
dp[j + AB[i][0]] = max(dp[j + AB[i][0]], dp[j] + AB[i][1])
ans = max(ans, dp[T-1]+AB[i+1][1])
print(ans)
if __name__ == "__main__":
main()
| 1 | 151,234,437,724,580 | null | 282 | 282 |
#!/usr/bin/env python3
import sys
def main():
input = sys.stdin.readline
d, t, s = map(int, input().split())
if d / s <= t:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| d,t,s=list(map(int,input().split()))
if(t*s<d):
print("No")
else:
print("Yes")
| 1 | 3,567,040,752,070 | null | 81 | 81 |
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from bisect import bisect_left,bisect_right
from collections import deque
def main():
n,k = map(int,input().split())
ans = 0
G = [0] * (1 + k)
for g in range(k,0,-1):
ret = pow((k//g),n,MOD)
for j in range(2 * g,k + 1,g):
ret -= G[j]
G[g] = ret
ans += ret * g
ans %= MOD
print(ans)
if __name__ =='__main__':
main() | def main():
n, k = map(int, input().split())
MOD = 10**9 + 7
a = [0]*(k+1)
for i in range(1, k+1):
a[i] = pow(k//i, n, MOD)
for i in reversed(range(1, k+1)):
for j in range(2*i, k+1, i):
a[i] -= a[j]
a[i] %= MOD
ans = 0
for i in range(1, k+1):
ans += a[i]*i
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 1 | 36,933,472,349,312 | null | 176 | 176 |
s=j=0
a=[];b=[];d=[]
for i,x in enumerate(input()):
if x=='\\':a+=[i]
elif x=='/' and a:
j=a.pop()
c=i-j;s+=c
while b and b[-1]>j:c+=d.pop();b.pop()
b+=[j];d+=[c]
print(s)
print(len(b),*(d)) | from collections import deque
areas = input()
S1 = deque([])
S2 = deque([])
sum_ = 0
for i,ch in enumerate(areas):
if ch == "\\":
S1.append(i)
elif ch == "/" and len(S1) > 0:
j = S1.pop()
sum_ += i-j
a = i-j
while len(S2) > 0 and S2[-1][0] > j:
a += S2.pop()[1]
S2.append([j,a])
ans = []
while len(S2) > 0:
ans.append(S2.pop()[1])
ans.reverse()
A = sum(ans)
print(A)
ans.insert(0,len(ans))
L = map(str,ans)
print(" ".join(L))
| 1 | 59,180,094,632 | null | 21 | 21 |
# https://atcoder.jp/contests/abc163/tasks/abc163_d
def main():
n, k = map(int, input().split(" "))
# このやり方だと当然TLE
# total = 0
# for i in range(k, n + 2):
# a = 0
# b = 0
# for j in range(i):
# a += j
# b += n - j
# total += b - a + 1
# print(total)
max_num = sum(range(n - k + 1, n + 1))
min_num = sum(range(k))
c = max_num - min_num + 1
total = c
for i in range(k, n + 1):
max_num += n - i
min_num += i
c = max_num - min_num + 1
total += c
print(total % 1000000007)
if __name__ == '__main__':
main()
| def main():
""""ここに今までのコード"""
N, K = map(int, input().split())
dice_list = list(map(int, input().split()))
max, s = 0, 0
for i in range(K):
s += (dice_list[i] + 1) / 2
max = s
for i in range(N-K):
s -= (dice_list[i] + 1) / 2
s += (dice_list[i+K] + 1) / 2
if s > max:
max = s
print(max)
if __name__ == '__main__':
main() | 0 | null | 53,769,865,155,670 | 170 | 223 |
nm = raw_input().split()
n = int(nm[0])
m = int(nm[1])
d = raw_input().split()
c = [0] * 100000
c[0] = 0
for i in range(n):
min = 100000
for j in range(m):
if int(d[j]) < i + 2:
x = c[i + 1 - int(d[j])]
if x < min:
min = x
c[i + 1] = min + 1
print c[n] | N, K = [int(s) for s in raw_input().split()]
ws = [int(raw_input()) for _ in xrange(N)]
lo, hi = max(ws) - 1, sum(ws)
while hi - lo > 1:
p = P = (lo + hi) / 2
k = 1
for w in ws:
if w > p:
p = P
k += 1
p -= w
if k <= K:
hi = P
else:
lo = P
print hi | 0 | null | 109,384,929,132 | 28 | 24 |
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
input=sys.stdin.readline
##import numpy as np
#sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
return map(int,sin().split())
def ain():
return list(map(int,sin().split()))
def sin():
return input()
def inin():
return int(input())
##def power(x, y):
## if(y == 0):return 1
## temp = power(x, int(y / 2))%mo
## if (y % 2 == 0):return (temp * temp)%mo
## else:
## if(y > 0):return (x * temp * temp)%mo
## else:return ((temp * temp)//x )%mo
##
##for _ in range(inin()):
n=inin()
d=dd(int)
for i in range(n):
s=sin().strip()
d[s]+=1
print("AC x",d["AC"])
print("WA x",d["WA"])
print("TLE x",d["TLE"])
print("RE x",d["RE"])
##
##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
## pre=[0]*n
## if(f==0): ##from beginning
## pre[0]=a[0]
## for i in range(1,n):
## pre[i]=a[i]+pre[i-1]
## else: ##from end
## pre[-1]=a[-1]
## for i in range(n-2,-1,-1):
## pre[i]=pre[i+1]+a[i]
## return pre
##maxint=10**24
##def kadane(a,size):
## max_so_far = -maxint - 1
## max_ending_here = 0
##
## for i in range(0, size):
## max_ending_here = max_ending_here + a[i]
## if (max_so_far < max_ending_here):
## max_so_far = max_ending_here
##
## if max_ending_here < 0:
## max_ending_here = 0
## return max_so_far
| n = int(input())
dic = {"AC":0, "WA":0, "TLE":0, "RE":0}
for i in range(n):
s = input()
dic[s] += 1
print("AC x " + str(dic["AC"]))
print("WA x " + str(dic["WA"]))
print("TLE x " + str(dic["TLE"]))
print("RE x " + str(dic["RE"])) | 1 | 8,711,009,945,540 | null | 109 | 109 |
s = len(input())
print('x'*s)
| S = input()
N = len(S)
print("x" * N) | 1 | 72,726,842,419,840 | null | 221 | 221 |
h1, m1, h2, m2, k = map(int, input().split())
H = h2 - h1
if m1 <= m2:
M = m2 - m1
else:
M = 60 - m1 + m2
H -= 1
print(H*60 + M - k) | N,K = map(int,input().split())
A = list(map(int,input().split()))
left = 0
right = 10**9
while right - left > 1:
center = (right+left)//2
count = 0
for a in A:
if a%center == 0:
count += a//center-1
else:
count += a//center
if count > K:
left = center
else:
right = center
print(right) | 0 | null | 12,272,775,236,440 | 139 | 99 |
N = input()
Sum = 0
for n in list(N):
Sum = Sum + int(n)
ANS = 'Yes' if Sum % 9 == 0 else 'No'
print(ANS) | N = input()
SUM = 0
for i in N:
SUM += int(i)
if SUM % 9 == 0:
print('Yes')
else :
print('No') | 1 | 4,401,127,134,308 | null | 87 | 87 |
N = int(input())
ans = [0]*(1+N)
for x in range(1, 10**2+1):
for y in range(1, 10**2+1):
for z in range(1, 10**2+1):
v = x*x+y*y+z*z+x*y+y*z+z*x
if v<=N:
ans[v] += 1
for i in range(1, N+1):
print(ans[i]) | N = int(input())
X = input().split()
distance = 0
min_distance = float('Inf')
for i in range(1,101):
for j in range(N):
distance += (int(X[j]) - i) ** 2
min_distance = min(min_distance, distance)
distance = 0
print(min_distance) | 0 | null | 36,443,895,453,124 | 106 | 213 |
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
M = []
for i in range(N):
M.append(i+1)
p, q = 0, 0
for i, n in enumerate(list(permutations(M))):
if n == P:
p = i
if n == Q:
q = i
print(abs(p - q)) | import itertools
n = int(input())
j = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
j_i, q_i = None, None
for i, t in enumerate(itertools.permutations(range(1,n+1), n), start=1):
if t == j:
j_i = i
if t == q:
q_i = i
if j_i and q_i:
break
print(abs(j_i - q_i))
| 1 | 100,483,343,524,630 | null | 246 | 246 |
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import heapq
def main():
A=[]
B=[]
M=[]
values=[]
a,b,m = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
M=[list(map(int,input().split())) for _ in range(m)]
# #割引した組み合わせ
for m in M:
values.append(A[m[0]-1]+B[m[1]-1]-m[2])
heapq.heapify(A)
heapq.heapify(B)
#最も安い組み合わせ
cheap=heapq.heappop(A)+heapq.heappop(B)
print(min(cheap,min(values)))
if __name__=="__main__":
main() | nA, nB, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0] + A
B = [0] + B
X = [[] for _ in range(M)]
Y = [[] for _ in range(M)]
C = [[] for _ in range(M)]
for i in range(M):
X[i], Y[i], C[i] = map(int, input().split())
# indipendent
ans1 = min(A[1:]) + min(B[1:])
# set
ans2 = max(A) + max(B)
for x, y, c in zip(X, Y, C):
ans2 = min(ans2, A[x] + B[y] - c)
print(min(ans1, ans2)) | 1 | 53,976,092,851,428 | null | 200 | 200 |
n_s = list(input().rstrip())
n_t = list(input().rstrip())
cnt = 0
for i in range(len(n_s)):
if n_s[i] != n_t[i]:
cnt += 1
print(cnt) | S=input()
T=input()
N=len(S)
c=0
for i in range(N):
if S[i]!=T[i]:
c=c+1
print(c)
| 1 | 10,542,423,589,574 | null | 116 | 116 |
N=int(input());M=10**9+7
print((pow(10,N,M)-2*pow(9,N,M)+pow(8,N,M))%M)
| N = int(input())
ans = pow(10, N, mod=1000000007) - pow(9, N, mod=1000000007) - pow(9, N, mod=1000000007) + pow(8, N, mod=1000000007)
ans %= 1000000007
print(ans)
| 1 | 3,118,976,317,530 | null | 78 | 78 |
#!/usr/bin/env python3
H = int(input())
i = 1
while H >= 2**i:
i += 1
ans = 0
for x in range(i):
ans += 2 ** x
print(ans)
| # coding: utf-8
# Your code here!
H=int(input())
count=0
ans=0
while H>1:
H=H//2
count+=1
for i in range(count+1):
ans+=2**i
print(ans) | 1 | 79,985,844,292,520 | null | 228 | 228 |
h, w, k = map(int, input().split())
A =[]
for i in range(h):
a = input()
A.append([a[i] == "#" for i in range(w)])
ans = 0
for bit in range(1 << h):
for tib in range(1 << w):
now = 0
for i in range(h):
for j in range(w):
if(bit >> i) & 1 == 0 and (tib >> j) & 1 == 0 and A[i][j] == True: now += 1
if now == k: ans += 1
print(ans) | h, w, k = map(int, input().split())
board = [[-1 for j in range(w)] for i in range(h)]
for i in range(h):
color = input()
for j in range(w):
if color[j] == "#":
board[i][j] = 1 #黒=1
else:
board[i][j] = 0 #白=0
ans = 0
for row_choose in range(1<<h):
for col_choose in range(1<<w):
count = 0
for i in range(h):
for j in range(w):
if not (row_choose & (1<<i)) and not (col_choose & (1<<j)) and board[i][j]:
count += 1
if count == k:
ans += 1
print(ans) | 1 | 8,886,770,001,840 | null | 110 | 110 |
import sys
import math
def solve(a: int, b: int, n: int) -> int:
x = min(n, b - 1)
return math.floor(a * ((x / b) - int(x / b)))
def main():
input = sys.stdin.buffer.readline
a, b, n = map(int, input().split())
print(solve(a, b, n))
if __name__ == '__main__':
main()
| A,B,N= map(int,input().split())
max_num = 0
x = min(B-1,N)
print(int((A*x)/B)-(A*int(x/B))) | 1 | 27,988,087,365,380 | null | 161 | 161 |
T1, T2, A1, A2, B1, B2 = map(int, open(0).read().split())
P = (A1-B1)*T1
Q = (A2-B2)*T2
if P>0:
P *= -1
Q *= -1
if P+Q<0:
print(0)
elif P+Q==0:
print('infinity')
else:
S,T = divmod(-P,P+Q)
if T!=0:
print(S*2+1)
else:
print(S*2) | t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if (a1*t1-b1*t1)*(a1*t1+a2*t2-b1*t1-b2*t2)>0:print(0)
elif (a1*t1-b1*t1)*(a1*t1+a2*t2-b1*t1-b2*t2)==0:print('infinity')
else:print(-(a1*t1-b1*t1)//(a1*t1+a2*t2-b1*t1-b2*t2)*2+((a1*t1-b1*t1)%(a1*t1+a2*t2-b1*t1-b2*t2)!=0)) | 1 | 131,057,725,388,024 | null | 269 | 269 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
mod = 10**9+7
def p(m,n):
a = 1
for i in range(n):
a = a*(m-i)
return a
def p_mod(m,n,mod):
a = 1
for i in range(n):
a = a*(m-i) % mod
return a
def c(m,n):
return p(m,n) // p(n,n)
def c_mod(m,n,mod):
return (p_mod(m,n,mod)*pow(p_mod(n,n,mod),mod-2,mod)) % mod
C = [0]*(N-K+1) #C[i] = (N-i-1)C_(K-1),予め二項係数を計算しておく
for i in range(N-K+1):
if i == 0:
C[i] = c_mod(N-1,K-1,mod)
else:
C[i] = (C[i-1]*(N-K-i+1)*pow(N-i,mod-2,mod)) % mod
#各Aの元が何回max,minに採用されるかを考える
ans = 0
for i in range(N-K+1):
ans -= (A[i]*C[i]) % mod
A.reverse()
for i in range(N-K+1):
ans += (A[i]*C[i]) % mod
print(ans % mod) | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
MOD = 2019
# INF = int(1e15)
def solve():
S = Scanner.string()
S = S[::-1]
cnt = [0 for _ in range(MOD)]
tmp = 0
ans = 0
x = 1
for s in S:
cnt[tmp] += 1
tmp += int(s) * x
tmp %= MOD
x *= 10
x %= MOD
ans += cnt[tmp]
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| 0 | null | 63,397,729,465,588 | 242 | 166 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
c = [0] * (N + 1)
C = [0] * K
D = [0] * K
uf = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
uf.union(a-1, b-1)
c[a] += 1
c[b] += 1
for i in range(K):
C[i], D[i] = map(int, input().split())
for i in range(1,N + 1):
c[i] = uf.size(i-1) - c[i] - 1
for i in range(K):
if uf.same(C[i]-1, D[i]-1):
c[C[i]] -= 1
c[D[i]] -= 1
for i in range(1, N+1):
print(c[i], end=" ") | n, k = map(int, input().rstrip().split())
h = [int(v) for v in input().rstrip().split()]
h.sort()
r = 0
for i in range(len(h)):
if k <= h[i]:
r = len(h) - i
break
print(r)
| 0 | null | 120,241,047,805,230 | 209 | 298 |
x, y = [ int(i) for i in input().split()]
if x > y:
x, y = y, x
while True:
if x % y:
x, y = y, x % y
continue
break
print(y)
| def gcd(a, b):
c = max([a, b])
d = min([a, b])
if c % d == 0:
return d
else:
return gcd(d, c % d)
nums = input().split()
print(gcd(int(nums[0]), int(nums[1])))
| 1 | 7,957,270,268 | null | 11 | 11 |
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
Comlist = []
Ans = dict()
Answer = 0
for i in range(1,10):
for j in range(1,10):
M = i*10 + j
Comlist.append(str(M))
Ans[str(M)] = 0
for k in range(1,N+1):
strk = str(k)
if k < 10:
Tar = strk + strk
Ans[Tar] += 1
else:
Tar = strk[0] + strk[-1]
if Tar in Ans:
Ans[Tar] += 1
Answer = 0
for q in range(len(Comlist)):
p = Comlist[q]
pin = p[1] + p[0]
Answer += Ans[p] * Ans[pin]
print(Answer) | from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A1 = []
A2 = []
for i in range(1,N+1):
A1.append(i + A[i-1])
A2.append(i - A[i-1])
c1 = Counter(A1)
c2 = Counter(A2)
result = 0
for k in set(c1).intersection(c2):
result += c1[k] * c2[k]
print(result) | 0 | null | 56,318,185,204,332 | 234 | 157 |
n = int(input())
ans = ['a'] # 最初の一文字は'a'で固定
for i in range(n-1): # 'a'に'n-1'文字分ループで足す
tmp = [] # リセット
for j in ans:
l = len(set(j)) # 'j'の使用文字種の数をカウント
for k in range(l+1): # 'j'の使用文字種の数 '+1'回ループして...
tmp.append(j + chr(ord('a') + k)) # 'j'に appendする
ans = tmp[:] # 'ans'を書き換える
for i in ans:
print(i)
| N = int(input())
a_num = 97
def dfs(s, n): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値
if n == 0:
print(s)
return
for i in range(ord("a"), ord(max(s))+2):
dfs(s+chr(i), n-1)
dfs("a", N-1)
| 1 | 52,473,262,725,652 | null | 198 | 198 |
def isprime(n):
if n == 2:
return True
if n % 2 == 0:
return False
i = 3
while i * i <= n:
if n % i == 0:
return False
i += 2
return True
result = 0
for i in range(int(input())):
result += isprime(int(input()))
print(result) | s,t = [x for x in input().split()]
a,b = [int(x) for x in input().split()]
ss = input()
if ss == s:
print(a-1,b)
else:
print(a,b-1)
| 0 | null | 36,042,996,279,784 | 12 | 220 |
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) | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
n,k=map(int,input().split())
A=list(map(lambda x:int(x)-1,input().split()))
S=[0]*(n+1)
for i in range(n):
S[i+1]=S[i]+A[i]
S[i+1]%=k
C=defaultdict(int)
ans=0
for i in range(n+1):
ans+=C[S[i]]
C[S[i]]+=1
if(i-k+1>=0): C[S[i-k+1]]-=1
print(ans)
resolve() | 0 | null | 71,282,818,083,282 | 89 | 273 |
def GCD(a, b):
if b > a:
return GCD(b, a)
elif a % b == 0:
return b
return GCD(b, a % b)
def LCM(a, b):
return a * b // GCD(a, b)
import sys
L = sys.stdin.readlines()
for line in L:
x, y = list(map(int, line.split()))
print(GCD(x, y), LCM(x, y)) | d,t,s = map(int,input().split())
if d <= t*s:
result = "Yes"
else:
result = "No"
print(result) | 0 | null | 1,797,036,665,860 | 5 | 81 |
# -*- coding: utf-8 -*-
def linearSearch(l, key):
m = len(l)
l.append(key)
i = 0
while l[i] != key:
i += 1
l.pop()
if i == m:
return "NOT_FOUND"
return i
if __name__ == '__main__':
n = int(input())
S = [int(s) for s in input().split(" ")]
q = int(input())
T = [int(t) for t in input().split(" ")]
count = 0
for t in T:
if linearSearch(S, t) != "NOT_FOUND":
count += 1
print(count)
| n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
Sset = set(S)
Tset = set(T)
print(len(Sset & Tset))
| 1 | 67,934,483,392 | null | 22 | 22 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
p = [1]
mod = 10**9+7
for i in range(n):
p.append(p[-1]*(i+1)%mod)
p.pop()
def comb(n,k,mod):
s = p[n]*pow(p[k],mod-2,mod)%mod
s = s*pow(p[n-k],mod-2,mod)%mod
return s
max_sum = 0
min_sum = 0
for i in range(n-k+1):
max_sum += a[-(i+1)]*comb(n-1-i,k-1,mod)
max_sum = max_sum%mod
min_sum += a[i]*comb(n-1-i,k-1,mod)
min_sum = min_sum%mod
ans = max_sum-min_sum
if ans < 0:
ans += mod
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())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
A.sort()
ans = 0
comb = Combination(1000000)
cnt = []
for i in range(N-K+1):
cnt.append(comb(N-i-1,K-1))
ans -= comb(N-i-1,K-1) * A[i]
for i in range(N,N-len(cnt),-1):
ans += A[i-1] * (cnt[N-i])
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 1 | 95,755,318,055,380 | null | 242 | 242 |
#create date: 2020-07-03 10:09
import sys
stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def main():
s = ns()
t = ns()
print("Yes" if s==t[:-1] else "No")
if __name__ == "__main__":
main() | #a = list(map(int, input().split(' ')))
a = input()
b = input()
if a == b[:-1]:
print('Yes')
else:
print('No') | 1 | 21,409,458,124,822 | null | 147 | 147 |
X,Y,Z = map(int,input().split())
X,Y = Y,X
X,Z = Z,X
print(X,Y,Z,sep=" ") | X,Y,Z=map(int, input().split())
A=[Z,X,Y]
print(*A,end='')
| 1 | 38,250,423,738,440 | null | 178 | 178 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
A, B, M = getNM()
# それぞれ冷蔵庫の値段
ref_a = getList()
ref_b = getList()
# 一枚だけ使える
ticket = [getList() for i in range(M)]
ans = min(ref_a) + min(ref_b)
for i in ticket:
opt = ref_a[i[0] - 1] + ref_b[i[1] - 1] - i[2]
ans = min(ans, opt)
print(ans) | # listじゃなくてdict使いたい
n = int(input())
j = [0] * 4
moji = ["AC", "WA", "TLE", "RE"]
for i in range(n):
s=input()
if s == "AC":
j[0] += 1
elif s=="WA":
j[1] += 1
elif s=="TLE":
j[2] += 1
elif s == "RE":
j[3] += 1
for k in range(4):
print(f"{moji[k]} x {j[k]}")
| 0 | null | 31,535,175,522,972 | 200 | 109 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n, k =map(int,input().split())
A = list(map(int,input().split())) + [0]
while k > 0:
B = [0] * (n + 1)
for i, a in enumerate(A):
B[max(0, i - a)] += 1
B[min(n, i + a + 1)] -= 1
if B[0] == n:
flag = True
for i in range(1, n+1):
B[i] += B[i-1]
if B[i] != n and i < n:
flag = False
A = B[:]
if flag:
break
k -= 1
print(" ".join(map(str, B[:-1])))
if __name__=='__main__':
main() | import sys
import numpy as np
input = sys.stdin.readline
def main():
H, W, K = map(int, input().split())
s = np.zeros(shape=(H, W), dtype=np.bool)
for i in range(H):
s[i] = tuple(map(lambda x: True if x == "#" else False, input().rstrip()))
ans = np.zeros(shape=(H, W), dtype=np.int64)
h_keep = 0
k = 1
for h in range(H):
if s[h].sum() > 0:
indices = np.where(s[h])[0]
ans[h_keep:h + 1] = k
k += 1
for idx in reversed(indices[:-1]):
ans[h_keep:h + 1, :idx + 1] = k
k += 1
h_keep = h + 1
else:
h_keep = min(h_keep, h)
if h_keep < H:
h_base = h_keep - 1
for h in range(h_keep, H):
ans[h] = ans[h_base]
for h in range(H):
print(" ".join(map(str, ans[h])))
if __name__ == "__main__":
main()
| 0 | null | 79,475,572,830,478 | 132 | 277 |
S = input()
T = input()
if T.startswith(S) and len(T) == len(S) + 1:
print("Yes")
else:
print("No") | while(1):
m,f,r=map(int,input().split())
if m==-1 and f==-1 and r==-1:
break
elif m==-1 or f==-1:
print("F")
elif m+f>=80:
print("A")
elif m+f>=65 and m+f<80:
print("B")
elif m+f>=50 and m+f<65:
print("C")
elif m+f>=30 and m+f<50 and r>=50:
print("C")
elif m+f>=30 and m+f<50:
print("D")
elif m+f<30:
print("F")
| 0 | null | 11,383,247,257,518 | 147 | 57 |
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
n, m = inpl()
C = sorted(inpl())
DP = list(range(n+1))
for c in C[1:]:
for i in range(n-c+1):
if DP[i] + 1 < DP[i+c]:
DP[i+c] = DP[i] + 1
print(DP[-1])
| s = input()
ans=0
s=s[::-1]
t=1
ketame=0
amari10=1
kosuu=[1]+[0]*2020
for i in s:
ketame=(ketame+(int(i)*amari10)%2019)%2019
amari10*=10
amari10%=2019
kosuu[ketame]+=1
for i in range(len(kosuu)):
if kosuu[i]>0:
ans+=kosuu[i]*(kosuu[i]-1)/2
print(int(ans)) | 0 | null | 15,410,954,924,512 | 28 | 166 |
X, N = map(int, input().split())
if N == 0:
print(X)
exit()
p = list(map(int, input().split()))
ans = -1
for i in range(0,102):
if i not in p:
if abs(i-X) < abs(ans-X):
ans = i
print(ans) | N = int(input())
R = [int(input()) for i in range(N)]
maxv = -20000000000
minv = R[0]
for i in range(1, N):
maxv = max(R[i] - minv, maxv)
minv = min(R[i], minv)
print(maxv) | 0 | null | 7,010,028,664,960 | 128 | 13 |
import numpy as np
import itertools as it
H,W,N = [int(i) for i in input().split()]
dat = np.array([list(input()) for i in range(H)], dtype=str)
emp_r = ["." for i in range(W)]
emp_c = ["." for i in range(H)]
def plot(dat, dict):
for y in dict["row"]:
dat[y,:] = emp_r
for x in dict["col"]:
dat[:,x] = emp_c
return dat
def is_sat(dat):
count = 0
for y in range(W):
for x in range(H):
if dat[x, y] == "#":
count += 1
if count == N:
return True
else:
return False
# def get_one_idx(bi, digit_num):
# tmp = []
# for j in range(digit_num):
# if (bi >> j) == 1:
# tmp.append()
# plot(dat, dict={"row": [], "col":[0, 1]})
combs = it.product([bin(i) for i in range(2**H-1)], [bin(i) for i in range(2**W-1)])
count = 0
for comb in combs:
rows = comb[0]
cols = comb[1]
rc_dict = {"row": [], "col": []}
for j in range(H):
if (int(rows, 0) >> j) & 1 == 1:
rc_dict["row"].append(j)
for j in range(W):
if (int(cols, 0) >> j) & 1 == 1:
rc_dict["col"].append(j)
dat_c = plot(dat.copy(), rc_dict)
if is_sat(dat_c):
count += 1
print(count)
| n, k = map(int, input().split())
A = list(map(int, input().split()))
bottom, top = 0, max(A)
def cut(x):
cnt = 0
for Length in A:
if Length % x == 0:
cnt += Length // x
else:
cnt += Length // x + 1
cnt -= 1
return cnt <= k
while top - bottom > 1:
middle = (top + bottom) // 2
if cut(middle):
top = middle
else:
bottom = middle
print(top) | 0 | null | 7,728,478,493,820 | 110 | 99 |
n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 13
while r - l > 1:
m = (l + r) // 2
if sum([(a - m // f) if a * f > m else 0 for a, f in zip(A, F)]) <= k:
r = m
else:
l = m
print(r) | N = int(input())
def cal(N):
return abs(10**N - 9**N - 9**N + 8**N) % (10**9+7)
print(cal(N)) | 0 | null | 83,985,915,455,860 | 290 | 78 |
s = input()
n = len(s)
mod = 2019
t = [0]*n
dp = [0]*2020
t[0] = int(s[-1])
dp[t[0]] += 1
for i in range(n-1):
t[i+1] = t[i] + int(s[-2-i])*pow(10, i+1, mod)
t[i+1] %= mod
dp[t[i+1]] += 1
ans = 0
for D in dp[1:]:
ans += D*(D-1)//2
print(ans+(dp[0]+1)*(dp[0])//2)
| 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)
| 0 | null | 16,962,159,000,620 | 166 | 77 |
N=int(input())
R=[int(input()) for i in range(N)]
S=[0 for i in range(N)]
S[0]=R[0]
for i in range(1,N):
S[i]=min(S[i-1],R[i])
T=[R[i+1]-S[i] for i in range(N-1)]
print(max(T))
| import sys
n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1-r0
mn = min(r1,r0)
l = map(int,sys.stdin.readlines())
for i in l:
if mx < i - mn:
mx = i - mn
elif mn > i:
mn = i
print(mx) | 1 | 14,328,703,470 | null | 13 | 13 |
n = int(input())
a = list(map(int, input().split()))
a_sum = sum(a)
x = 0
y = 0
for i in range(n):
x += a[i]
if x * 2 >= a_sum:
y = a[i]
break
ans = min(abs(2 * x - a_sum), abs(a_sum - 2 * (x - y)))
print(ans)
| from itertools import accumulate
N = int(input())
A = list([int(x) for x in input().split()])
count = 0
ironbar = list(accumulate(A))
min_value = ironbar[-1]
for i in range(N):
bet = abs(ironbar[i] - (ironbar[-1] - ironbar[i]))
if min_value > bet:
min_value = bet
else:
print(min_value)
exit()
| 1 | 142,364,194,253,358 | null | 276 | 276 |
print(len({*input()})%2*'Yes'or'No') | N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
totalA = sum(A)
while totalA > K:
totalA -= A.pop()
ans = len(A)
totalB = 0
for i in range(M):
totalB += B[i]
while totalA + totalB > K:
if not A:
break
totalA -= A.pop()
if totalA + totalB <= K:
ans = max(ans, len(A) + i + 1)
print(ans)
| 0 | null | 39,429,162,029,312 | 216 | 117 |
# -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
numbers = [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]
k = int(input())
print(numbers[k - 1])
if __name__ == '__main__':
main()
| import sys
N = int(input())
S = input()
if N % 2 == 1:
print('No')
sys.exit()
if S[:N//2] == S[N//2:]:
print('Yes')
sys.exit()
print('No') | 0 | null | 98,921,864,378,040 | 195 | 279 |
x=list(map(int, input().split()))
L=x[0]
R=x[1]
d=x[2]
res=0
while L<=R:
if L%d==0:
res+=1
L+=1
print(res) | import sys
def input():
return sys.stdin.readline().strip()
n, d, a = map(int, input().split())
x = []
h = {} # x:h
for _ in range(n):
i, j = map(int, input().split())
x.append(i)
h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)
# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
attack[i] += attack[i-1]
if attack[i] >= h[x[i]]:
continue
if (h[x[i]] - attack[i]) % a == 0:
j = (h[x[i]] - attack[i]) // a
else:
j = (h[x[i]] - attack[i]) // a + 1
attack[i] += a * j
ans += j
# 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
# start <= y <= stop
start = i + 1
stop = n
k = stop - start + 1
while k > 1:
if x[start + k//2 - 1] <= x[i] + 2*d:
start += k//2
else:
stop = start + k//2 - 1
k = stop - start + 1
attack[start] -= a * j
print(ans) | 0 | null | 45,096,354,634,254 | 104 | 230 |
n,a,b=map(int,input().split())
mod=10**9+7
def pow(x, n):
ans = 1
while(n > 0):
if(bin(n & 1) == bin(1)):
ans = ans*x%mod
x = x*x%mod
n = n >> 1
return ans
N=pow(2,n)
def comb(c,d):
x=1
for i in range(d):
x=x*(c-i)%mod
y=1
for i in range(d):
y=y*(i+1)%mod
return x*pow(y,mod-2)%mod
A=comb(n,a)
B=comb(n,b)
print((N-A-B-1)%mod) | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n, a, b = map(int, input().split())
MOD = 10**9+7
def comb(n, r):
p, q = 1, 1
for i in range(r):
p = p * (n-i) % MOD
q = q * (i+1) % MOD
return p * pow(q, MOD-2, MOD) % MOD
ans = (pow(2, n, MOD)-1) % MOD
ans = (ans+MOD-comb(n, a)) % MOD
ans = (ans+MOD-comb(n, b)) % MOD
print(ans)
| 1 | 66,149,867,656,180 | null | 214 | 214 |
def kyu_in_atcoder():
X = int(input())
lis = [10 - i for i in range(10)]
x = X // 200
print(lis[x])
kyu_in_atcoder() | x = int(input())
if 400 <= x <= 599:
print(8)
if 600 <= x <= 799:
print(7)
if 800 <= x <= 999:
print(6)
if 1000 <= x <= 1199:
print(5)
if 1200 <= x <= 1399:
print(4)
if 1400 <= x <= 1599:
print(3)
if 1600 <= x <= 1799:
print(2)
if 1800 <= x <= 1999:
print(1) | 1 | 6,614,570,439,502 | null | 100 | 100 |
n = int(input())
cl = input()
if cl[:cl.count('R')].count('W') != 0:
print(min(cl[:cl.count('R')].count('W'), cl.count('R')))
else:
print(0) | def out(data) -> str:
print(' '.join(map(str, data)))
N = int(input())
data = [int(i) for i in input().split()]
out(data)
for i in range(1, N):
tmp = data[i]
j = i - 1
while j >= 0 and data[j] > tmp:
data[j + 1] = data[j]
j -= 1
data[j + 1] = tmp
out(data)
| 0 | null | 3,194,212,344,000 | 98 | 10 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
days = N - sum(A)
print(days) if days >= 0 else print('-1') | import math
a,b,h,m = map(int, input().split())
s = 30 * h + m * 0.5
l = m*6
x = abs(s-l)
if x >= 180: x = 360-x
c = math.cos(math.radians(x))
print((a**2+b**2-2*a*b*c)**0.5) | 0 | null | 26,061,443,064,008 | 168 | 144 |
# your code goes here
import sys
a=[]
for line in sys.stdin:
line.rstrip('rn')
tmp=line.split(" ")
a.append(int(tmp[-1]))
a.sort(reverse=True)
y=0
for i in a:
if y==3:
break
if i>=0 and i<=10000:
print(i)
y=y+1 | Xs = [int(x) for x in input().split()]
print(Xs.index(0) + 1) | 0 | null | 6,718,107,121,220 | 2 | 126 |
m, n = map(int, input().split())
l = list(map(int, input().split()))
for i in range(m-n):
if l[i] < l[i+n]:
print('Yes')
else:
print('No')
| S = input()
N = len(S)
ans = [0] * (N+1)
for i in range(N):
if S[i] == '<':
ans[i+1] = ans[i] + 1
for i in range(N-1, -1, -1):
if S[i] == '>' and ans[i] <= ans[i+1]:
ans[i] = ans[i+1]+1
print(sum(ans))
| 0 | null | 81,573,503,503,782 | 102 | 285 |
s = input()
if s[-1] == "s":
s += "e"
print(s + "s") | S=input()
i=len(S)-1
if S[i]=="s":
out=S+"es"
else:
out=S+"s"
print(out) | 1 | 2,405,139,611,732 | null | 71 | 71 |
s = input()
cnt = 0
if s == 'RSR':
cnt = 1
else:
for i in range(3):
if s[i] == 'R':
cnt += 1
print(cnt) | import sys
def gcd(a,b):
if a%b==0:
return b
return gcd(b,a%b)
r=[list(map(int,line.split())) for line in sys.stdin]
for i in r:
o=gcd(i[0],i[1])
p=i[0]*i[1]/o
print(o,int(p))
| 0 | null | 2,451,339,636,850 | 90 | 5 |
while True:
x = input()
if x == "0":
break
x = list(map(int, list(x)))
print(sum(x))
| while True:
x = input()
if x == '0':
quit()
print(sum([int(_) for _ in x])) | 1 | 1,579,619,940,248 | null | 62 | 62 |
from collections import deque
H, W = map(int, input().split())
S_raw = [list(input()) for _ in range(H)]
m = 0
def calc(h,w):
S = [list(S_raw[i][j] for j in range(W)) for i in range(H)]
S[h][w]=0
queue = deque([(h,w)])
while queue:
q = queue.popleft()
for x in ((q[0]-1, q[1]),(q[0]+1, q[1]), (q[0], q[1]-1), (q[0], q[1]+1)):
if 0<=x[0]<=H-1 and 0<=x[1]<=W-1:
if S[x[0]][x[1]]==".":
S[x[0]][x[1]] = S[q[0]][q[1]]+1
queue.append(x)
return max(S[h][w] for w in range(W) for h in range(H) \
if str(S[h][w]).isdigit())
for h in range(H):
for w in range(W):
if S_raw[h][w]==".":
m = max(m, calc(h,w))
print(m) | import sys
from collections import deque
def main():
h, w = map(int, input().split())
maze = [input() for i in range(h)]
# 行ったかどうかのフラグ
visited = [[-1]*w for j in range(h)]
start_yx = []
for i in range(h):
for j in range(w):
if maze[i][j] == '.':
sy = i
sx = j
start_yx .append([sy, sx])
# 移動パターン
mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0
for sy, sx in start_yx :
visited = [[-1]*w for j in range(h)]
q = deque([[sy, sx]])
visited[sy][sx] = 0
while q:
y, x = q.popleft()
ans = max(ans, visited[y][x])
for i, j in mv:
if (0 <= y + i < h) and (0 <= x + j < w):
ny = y+i
nx = x+j
if visited[ny][nx] != -1:
continue
if maze[ny][nx] == '.':
visited[ny][nx] = visited[y][x] + 1
q.append([ny, nx])
else:
continue
print(ans)
if __name__ == '__main__':
main()
| 1 | 94,601,276,840,580 | null | 241 | 241 |
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N = I()
s = S()
R = s.count("R")
G = s.count("G")
B = s.count("B")
dup = 0
for i in range(N):
for k in range(i+1, N):
if (i + k) % 2 == 0:
j = (i + k) // 2
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
dup += 1
print(R * G * B - dup)
main()
| import math
import sys
import os
from operator import mul
import bisect
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
N = I()
S = list(_S())
ans = 0
r = []
g = []
b = []
for i,s in enumerate(S):
if s == 'R':
r.append(i)
if s == 'G':
g.append(i)
if s == 'B':
b.append(i)
# j = bisect.bisect_right(<list>,<value>)
# print(r)
# print(g)
# print(b)
# for i in r:
# for j in g:
# for k in b:
# tmp = sorted([i,j,k])
# if not tmp[1]-tmp[0]==tmp[2]-tmp[1]:
# ans += 1
ans = len(r)*len(g)*len(b)
for i in range(N):
for j in range(i,N):
k = j + (j-i)
if k > N-1:
break
if S[i]==S[j]:
continue
if S[i]==S[k] or S[j]==S[k]:
continue
ans -= 1
print(ans)
# R G B
# R B G
# G B R
# G R B
# B G R
# B R G
# i j k
# - != -
# RBRBGRBGGB
# 1122233333
# 0000111233
# 0112223334
# B*3
# G*4
# GB系: (2,4), (4,5)
# RB系: (1,3), | 1 | 36,345,574,660,190 | null | 175 | 175 |
import sys
# input = sys.stdin.readline
def main():
S, T =input().split()
print(T,S,sep="")
if __name__ == "__main__":
main() | import sys
import math
import fractions
from collections import defaultdict
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
S=ns().split()
print(S[1]+S[0]) | 1 | 102,625,945,735,760 | null | 248 | 248 |
import collections
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
def main():
N, M, K = ZZ()
F = [0] * (N+1)
output = []
par = [i for i in range(N+1)]
rank = [0] * (N+1)
# 要素xの親ノードを返す
def find(x):
if par[x] == x:
return x
par[x] = find(par[x])
return par[x]
# 要素x, yの属する集合を併合
def unite(x, y):
x, y = find(x), find(y)
if x == y:
return
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
return
# xとyが同じ集合に属するか?
def same(x, y):
return find(x) == find(y)
for _ in range(M):
a, b = ZZ()
F[a] += 1
F[b] += 1
unite(a, b)
for i in range(1, N+1): find(i)
cnt = collections.Counter(par)
for _ in range(K):
c, d = ZZ()
if same(c, d):
F[c] += 1
F[d] += 1
for i in range(1, N+1):
cc = cnt[par[i]] - F[i] - 1
output.append(cc)
print(*output)
return
if __name__ == '__main__':
main()
| import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
[h, w, n] = [int(readline().rstrip()) for _ in range(3)]
print(math.ceil(n/max(h, w)))
if __name__ == '__main__':
main()
| 0 | null | 75,365,863,241,340 | 209 | 236 |
s,t=[str(i)for i in input().split()]
print(t+s) | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(S: str, T: str):
return T+S
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
T = next(tokens) # type: str
print(f'{solve(S, T)}')
if __name__ == '__main__':
main()
| 1 | 103,465,069,728,580 | null | 248 | 248 |
while True:
a= map(int,raw_input().split())
if a[0]==0 and a[1]==0:
break
a.sort()
print a[0],a[1] | num = int(input())
val = 100000
for i in range(num):
val = val * 1.05
rem = val%1000
if rem != 0:
val = val - rem + 1000
print(int(val))
| 0 | null | 262,342,518,900 | 43 | 6 |
import math
a, b, x = map(int, input().split())
if x == (a**2*b)/2:
print(45)
elif x > (a**2*b)/2:
print(math.degrees(math.atan((2*(b-x/(a**2)))/a)))
else:
print(math.degrees(math.atan(a*b**2/(2*x))))
| import sys
I=sys.stdin.readlines()
N,M,L=map(int,I[0].split())
a,b,c=0,0,0
D=[[L+1]*N for i in range(N)]
for i in range(M):
a,b,c=map(int,I[i+1].split())
a,b=a-1,b-1
D[a][b]=c
D[b][a]=c
for i in range(N):
D[i][i]=0
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j]=min(D[i][j],D[i][k]+D[k][j])
D2=[[N*N+2]*N for i in range(N)]
for i in range(N):
D2[i][i]=0
for j in range(N):
if D[i][j]<=L:
D2[i][j]=1
for k in range(N):
for i in range(N):
for j in range(N):
D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j])
Q=int(I[M+1])
for i in range(Q):
a,b=map(int,I[i+2+M].split())
if N<D2[a-1][b-1]:
print(-1)
else:
print(D2[a-1][b-1]-1) | 0 | null | 167,700,576,422,522 | 289 | 295 |
x, y = map(int, input().split())
money = [300000, 200000, 100000]
if x == 1 and y == 1:
print(1000000)
elif x <= 3 and y <= 3:
print(money[x - 1] + money[y - 1])
elif x <= 3:
print(money[x - 1])
elif y <= 3:
print(money[y - 1])
else:
print(0) | x = range(1, 10)
y = range(1, 10)
for i in x:
for j in y:
print(str(i)+'x'+str(j)+'='+str(i*j))
| 0 | null | 70,296,708,539,552 | 275 | 1 |
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
dp=[[0]*(t+1) for i in range(n+1)]
for i in range(1,n+1):
for j in range(t+1):
if j!=t:
if j-l[i-1][0]>=0:
dp[i][j]=max(dp[i-1][j],dp[i-1][j-l[i-1][0]]+l[i-1][1])
else:
dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]+l[i-1][1])
dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[n])) | from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
org_inp=[];g=[[] for i in range(n)]
for i in range(E):
inp=LI();org_inp.append(inp)
if index==0:inp[0]-=1;inp[1]-=1
if len(inp)==2:
a,b=inp;g[a].append(b)
if not Directed:g[b].append(a)
elif len(inp)==3:
a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
if not Directed:g[b].append(aa)
return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
mp=[boundary]*(w+2);found={}
for i in range(h):
s=input()
for char in search:
if char in s:
found[char]=((i+1)*(w+2)+s.index(char)+1)
mp_def[char]=mp_def[replacement_of_found]
mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
mp+=[boundary]*(w+2)
return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
if show_flg:print(*inp,end=end)
def show2d(g,h,w):
for i in range(h):show(g[i*w:i*w+w])
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
def ran_input():
n=random.randint(4,16)
rmin,rmax=1,10
a=[random.randint(rmin,rmax) for _ in range(n)]
return n,a
show_flg=False
show_flg=True
ans=0
def gcj(t,*x):
print("Case #"+str(t)+":",*x)
return
n,t=LI()
N=6001
N=31
dp=[[0]*t for i in range(n+1)]
c=[]
for i in range(n):
a,b=LI()
c+=[(a,b)]
c.sort(key=lambda x:x[0]*4000-x[1])
for i in range(n):
a,b=c[i]
ans=max(ans,dp[i][-1]+b)
for j in range(t):
dp[i+1][j]=max(dp[i+1][j],dp[i][j])
if j+a<t:
dp[i+1][j+a]=max(dp[i][j]+b,dp[i][j+a])
print(ans) | 1 | 151,707,230,066,590 | null | 282 | 282 |
N, K = map(int, input().split())
H = list(map(int, input().split()))
ANS = sum(x >= K for x in H)
print(ANS) | S_list = [input() for i in range(2)]
N,K = map(int,S_list[0].split())
h_list = list(map(int,S_list[1].split()))
number = 0
for i in h_list:
if i>=K:
number += 1
print(number) | 1 | 179,415,652,105,612 | null | 298 | 298 |
H,A = map(int, input().split())
ans=0
for i in range(H//A+1):
if H >0:
H=H-A
ans+=1
else:
break
print(ans) | import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
s=input()
len_s=len(s)
T=[0]*(len_s+1)
T[-1],T[-2]=0,int(s[-1])
mod=2019
for i in range(len_s-2,-1,-1):
T[i]=(T[i+1]+int(s[i])*pow(10,len_s-i-1,mod))%mod
tc=list(Counter(T).values())
ans=0
for tcc in tc:
ans+=tcc*(tcc-1)//2
print(ans)
if __name__=='__main__':
main() | 0 | null | 53,826,109,553,530 | 225 | 166 |
S = str(input())
if len(S) % 2 != 0:
ans = 'No'
else:
h = int(len(S) / 2)
s = [[S[2 * i - 2], S[2 * i -1]] for i in range(h)]
hi = s.count(['h', 'i'])
if h == hi:
ans = 'Yes'
else:
ans = 'No'
print(ans) | 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) | 0 | null | 54,821,794,037,790 | 199 | 203 |
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
def main():
x, y = (int(n) for n in input().split())
print(gcd(x, y))
main()
| def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
x, y = [int(n) for n in input().split()]
print(gcd(x, y)) | 1 | 8,457,809,052 | null | 11 | 11 |
n = int(input())
ans = 0
for i in range(1,n+1):
if (i % 3 == 0) or (i % 5 == 0):
pass
else:
ans += i
print(ans) | ans = 0
l,r,d = [int(x) for x in input().split()]
for i in range(l,r+1):
if i % d == 0:
ans = ans + 1
print(ans)
| 0 | null | 21,302,875,519,586 | 173 | 104 |
# ABC144 D
from math import atan2,pi
a,b,x=map(int,input().split())
if a*a*b>2*x:
h=2*x/(a*b)
print(90-atan2(2*x,a*b*b)*180/pi)
else:
print(atan2((2*(a*a*b-x)),a**3)*180/pi) | from collections import defaultdict
def bfs(s):
q = [s]
while q != []:
p = q[0]
del q[0]
for node in adj[p]:
if not visited[node]:
visited[node] = True
q.append(node)
n,m = map(int,input().split())
adj = defaultdict(list)
visited = [False]*(n+1)
comp = 0
for _ in range(m):
a,b = map(int,input().split())
adj[a].append(b)
adj[b].append(a)
for i in range(1,n+1):
if not visited[i]:
comp+=1
bfs(i)
print(comp-1) | 0 | null | 82,623,906,817,088 | 289 | 70 |
import math
class point:
def __init__(self, p):
self._x = p[0]
self._y = p[1]
def disp(self):
print("{0:f} {1:f}".format(self._x, self._y))
@property
def x(self):
return self._x
@property
def y(self):
return self._y
def get_s(p1, p2):
p = point((p1.x/3*2 + p2.x/3, p1.y/3*2 + p2.y/3))
return p
def get_t(p1, p2):
p = point((p1.x/3 + p2.x/3*2, p1.y/3 + p2.y/3*2))
return p
def get_u(s, t):
x = (t.x - s.x)*math.cos(math.radians(60)) - (t.y - s.y)*math.sin(math.radians(60)) + s.x
y = (t.x - s.x)*math.sin(math.radians(60)) + (t.y - s.y)*math.cos(math.radians(60)) + s.y
return point((x, y))
def kock(n, p1, p2):
if n == 0:
return
else:
s = get_s(p1, p2)
t = get_t(p1, p2)
u = get_u(s, t)
kock(n-1, p1, s)
s.disp()
kock(n-1, s, u)
u.disp()
kock(n-1, u, t)
t.disp()
kock(n-1, t, p2)
return
if __name__ == '__main__':
n = int(input())
p1 = point((0, 0))
p2 = point((100, 0))
p1.disp()
kock(n, p1, p2)
p2.disp()
| N = int(input())
a = [0]
i = 0
L = 26
while True:
if a[i] < N <= a[i] + L**(i + 1):
break
a.append(a[i] + L**(i + 1))
i += 1
N -= a[i] + 1
for j in range(i, -1, -1):
if j > 0:
print(chr(N // L**(j) + ord('a')), end="")
else:
print(chr(N + ord('a')), end="")
N = N % L**(j)
| 0 | null | 6,028,469,828,960 | 27 | 121 |
# 入力
monster_hp, quantity_of_skills = map(int, input().split())
skills = map(int, input().split())
skills_list = list(skills)
# 処理
total_damages = 0
for i in skills_list:
total_damages += i
if monster_hp <= total_damages:
print('Yes')
else:
print('No') | h,n= map(int, input().split())
a = list(map(int,input().split()))
for i in range(n):
h -= a[i]
print("Yes" if h <=0 else "No") | 1 | 78,040,653,053,952 | null | 226 | 226 |
k=int(input())
s=len(input())
def cmb(n,r,mod):
if r<0 or n<r:
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
mod=10**9+7
g1=[1,1]#元table
g2=[1,1]#逆元table
inv=[0,1]#逆元table計算用
for i in range(2,k+s+1):
g1.append(g1[-1]*i%mod)
inv.append(-inv[mod%i]*(mod//i)%mod)
g2.append(g2[-1]*inv[-1]%mod)
ans=1
for i in range(1,k+1):
ans=(ans*26+cmb(i+s-1,s-1,mod)*pow(25,i,mod))%mod
print(ans) | K=int(input())
S=input()
M=10**9+7
#----------------------------------------------------------------
f=1
Fact=[f]
for i in range(1,len(S)+K+1):
f=(f*i)%M
Fact.append(f)
Inv=[0]*(len(S)+K+1)
g=pow(f,M-2,M)
Inv=[0]*(len(S)+K+1)
Inv[-1]=g
for j in range(len(S)+K-1,-1,-1):
Inv[j]=(Inv[j+1]*(j+1))%M
def nCr(n,r):
if 0<=r<=n:
return (Fact[n]*Inv[r]*Inv[n-r])%M
else:
return 0
A=len(S)
T=0
for i in range(K+1):
T=(T+nCr(A+K-1-i,K-i)*pow(25,K-i,M)*pow(26,i,M))%M
print(T)
| 1 | 12,814,786,102,118 | null | 124 | 124 |
A,B,N=map(int,input().split())
if N<B:
x=N
elif N==B:
x=N-1
else:
x=(N//B)*B-1
ans=(A*x/B)//1-A*(x//B)
print(int(ans)) | name= list(map(str,input()))
print(name[0],name[1],name[2], sep="") | 0 | null | 21,427,383,674,528 | 161 | 130 |
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())
A = list(map(int, input().split()))
count = 0
for i in range(N):
for j in range(N - 1, i, -1):
if A[j] < A[j-1]:
A[j], A[j - 1] = A[j -1], A[j]
count += 1
print(*A)
print(count) | 1 | 17,443,875,540 | null | 14 | 14 |
a, b, c = map(int, input().split())
l = []
for i in range(1, c+1):
if c%i==0:
l.append(i)
res = 0
for i in range(a, b+1):
if i in l:
res+=1
print(res) | def main():
a = int(input())
ans = a + a ** 2 + a ** 3
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 5,346,252,771,900 | 44 | 115 |
a =sorted( [int(input()) for i in range(2)])
print("1" if a == [2,3] else "2" if a == [1,3] else "3")
| a = input()
b = input()
c = ['1', '2', '3']
for i in c:
if i != a and i != b:
print(i) | 1 | 110,952,714,873,540 | null | 254 | 254 |
def resolve():
import math
print(2*math.pi*int(input()))
if '__main__' == __name__:
resolve() | import numpy as np
R = int(input())
l = R * 2 * np.pi
print(str(l)) | 1 | 31,347,602,085,828 | null | 167 | 167 |
from statistics import median
n = int(input())
a = [None] * n
b = [None] * n
for i in range(n):
a[i], b[i] = map(int, input().split())
if n % 2 == 1:
print(median(b) - median(a) + 1)
else:
print(int((median(b) - median(a)) * 2) + 1) | def resolve():
N = int(input())
# set A and B arrays.
A = []
B = []
for _ in range(N):
A_i, B_i = map(int, input().split())
A.append(A_i)
B.append(B_i)
# count median
if N%2==1: # odd
i = int((N-1)/2)
median_min = sorted(A)[i]
median_max = sorted(B)[i]
else:
i_0 = int((N/2)-1)
i_1 = int(N/2)
ordered_A = sorted(A)
ordered_B = sorted(B)
median_min = ordered_A[i_0] + ordered_A[i_1] # 2 times of median of A
median_max = ordered_B[i_0] + ordered_B[i_1]
print(median_max - median_min +1)
resolve() | 1 | 17,338,991,982,182 | null | 137 | 137 |
from collections import deque
# end,cnt
dq = deque()
(n,d,a),*xh = [list(map(int, s.split())) for s in open(0)]
xh.sort()
total_bomb = 0
eff_bomb = 0
for x,h in xh:
while dq and dq[0][0] < x:
end, cnt = dq.popleft()
eff_bomb -= cnt
resid = h - eff_bomb * a
if resid > 0:
cnt = 0--resid//a
end = x + 2 * d
dq.append((end,cnt))
eff_bomb += cnt
total_bomb += cnt
print(total_bomb) | #!/usr/bin/env python3
from math import ceil
import heapq
def main():
n, d, a = map(int, input().split())
q = []
for i in range(n):
x, h = map(int, input().split())
heapq.heappush(q, (x, -(h // a + (1 if (h % a) else 0))))
bomb = 0
res = 0
while q:
x, h = heapq.heappop(q)
if h < 0:
h *= -1
if h > bomb:
heapq.heappush(q, (x + 2 * d, h - bomb))
res += h - bomb
bomb = h
else:
bomb -= h
print(res)
if __name__ == "__main__":
main()
| 1 | 82,188,628,734,550 | null | 230 | 230 |
def solve(N,K):
if N == 0:
return 1
digit_num = 0
while(1):
if N >= pow(K,digit_num):
digit_num += 1
else:
return digit_num
N, K = map(int,input().split())
ans = solve(N,K)
print(ans) |
n,k = map(int, input().split())
i=0
a=[]
while n!=0:
a.append(n%k)
n=n//k
i=i+1
print(len(a))
| 1 | 64,163,572,580,900 | null | 212 | 212 |
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a, b):
return a*b/gcd(a, b)
try :
while True :
(a,b) = map(int, raw_input().split())
print gcd(a,b), lcm(a,b)
except EOFError :
pass | #!/usr/bin/python
import sys
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a,b):
return a / gcd(a,b) * b
for l in sys.stdin:
a = [int(s) for s in l.split()]
print str(gcd(a[0],a[1]))+" "+str(lcm(a[0],a[1])) | 1 | 642,143,292 | null | 5 | 5 |
a = list(map(int, input().split()))
if a[0] < 10 and a[1] < 10:
print(a[0]*a[1])
else:
print(-1)
| A, B = list(map(int,input().split()))
if A>0 and A<10 and B>0 and B<10:
print(A*B)
else:
print(-1) | 1 | 157,526,553,517,728 | null | 286 | 286 |
import itertools
n=int(input())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
t=[int(i) for i in range(1,n+1)]
a=b=0
for i,j in enumerate(list(itertools.permutations(t,n))):
w=[1,1]
for x,y in enumerate(j):
if p[x]!=y: w[0]=0
if q[x]!=y: w[1]=0
if w[0]: a=i
if w[1]: b=i
print(abs(a-b)) | from itertools import permutations
def same(l1, l2, n):
for i in range(n):
if l1[i] != l2[i]:
return False
return True
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P = [p-1 for p in P]
Q = [q-1 for q in Q]
for i,pattern in enumerate(permutations(range(N))):
if same(P, pattern, N):
i_p = i
if same(Q, pattern, N):
i_q = i
print(abs(i_p - i_q)) | 1 | 100,679,448,497,770 | null | 246 | 246 |
s=input()
if s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi":
print("Yes")
else:
print("No") | s = input()
ans = "No"
for i in range(1, 6):
if s == "hi" * i:
ans = "Yes"
print(ans) | 1 | 53,239,518,149,818 | null | 199 | 199 |
from fractions import gcd
n, m = map(int, input().split())
a = [int(i)//2 for i in input().split()]
def lcm(x, y):
return x*y//gcd(x, y)
l = 1
for i in a:
l = lcm(l, i)
for i in a:
if l//i % 2 == 0:
print(0)
exit()
print((m//l+1)//2) | import sys
import fractions
readline = sys.stdin.buffer.readline
def main():
gcd = fractions.gcd
def lcm(a, b):
return a * b // gcd(a, b)
N, M = map(int, readline().split())
A = list(set(map(int, readline().split())))
B = A[::]
while not any(b % 2 for b in B):
B = [b // 2 for b in B]
if not all(b % 2 for b in B):
print(0)
return
semi_lcm = 1
for a in A:
semi_lcm = lcm(semi_lcm, a // 2)
if semi_lcm > M:
print(0)
return
print((M // semi_lcm + 1) // 2)
return
if __name__ == '__main__':
main()
| 1 | 101,647,272,946,550 | null | 247 | 247 |
# Common Raccoon vs Monster
H, N = map(int,input().split())
A = list(map(int, input().split()))
ans = ['No', 'Yes'][sum(A) >= H]
print(ans) | from itertools import permutations
import math
n = int(input())
x = []
y = []
for i in range(n):
xi, yi = map(int, input().split(' '))
x.append(xi)
y.append(yi)
l = [i for i in range(n)]
route = list(permutations(l))
length = 0
for ls in route:
for i in range(n-1):
length += math.sqrt((x[ls[i+1]]-x[ls[i]])**2+(y[ls[i+1]]-y[ls[i]])**2)
ans = length/math.factorial(n)
print(ans) | 0 | null | 112,878,076,918,038 | 226 | 280 |
K = int(input())
num = 0
for i in range(0,K):
num = num*10 + 7
if num % K == 0:
print(i + 1)
exit()
num %= K
print(-1)
| sa, sb = input().split()
a = int(sa)
bi,bf = map(int,sb.split("."))
b = bi * 100 + bf
print((a*b)//100) | 0 | null | 11,290,160,975,122 | 97 | 135 |
# -*- coding: utf-8 -*-
#mitsui f
import sys
import math
import collections
#sys.setrecursionlimit(100000)
#n=int(input())
tmp = input().split()
t1,t2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
a1,a2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
b1,b2 = list(map(lambda a: int(a), tmp))
if(a1*t1+a2*t2==b1*t1+b2*t2):
print("infinity")
sys.exit()
diff=(a1*t1+a2*t2)-(b1*t1+b2*t2)
if(diff>0):
c1=a1-b1
c2=a2-b2
else:
c1=b1-a1
c2=b2-a2
if(c1>0):
print("0")
sys.exit()
diff=c1*t1+c2*t2
pitch=c1*t1*-1
ans=pitch//diff*2+1
if(pitch%diff==0):
ans-=1
print(ans)
| S,T=input().split()
print('{}{}'.format(T,S)) | 0 | null | 116,911,745,824,864 | 269 | 248 |
# -*- coding: utf-8 -*-
func = lambda num_1, num_2: num_1 * num_2
for i1 in range(1,10):
for i2 in range(1,10):
print(str(i1) + "x" + str(i2) + "=" + str(func(i1, i2))) | # 164 A
S,W = list(map(int, input().split()))
print('safe') if S > W else print('unsafe') | 0 | null | 14,616,271,437,012 | 1 | 163 |
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
C=Counter(A)
for i in range(1,N+1):
print(C[i]) | import sys
n = int( sys.stdin.readline() )
cards = { pattern:[False]*13 for pattern in ( 'S', 'H', 'C', 'D' ) }
for i in range( n ):
pattern, num = sys.stdin.readline().split( " " )
cards[ pattern ][ int( num )-1 ] = True
for pattern in ( 'S', 'H', 'C', 'D' ):
for i in range( 13 ):
if not cards[ pattern ][ i ]:
print( "{:s} {:d}".format( pattern, i+1 ) ) | 0 | null | 16,803,439,993,190 | 169 | 54 |
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
mx=max(a for a,b in ab)
dp=[10**10]*(h+1+mx)
dp[0]=0
for i in range(1,h+1+mx):
dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[h:])) | x = int(input())
if 360 % x == 0:
print(360//x)
else:
for i in range(1, 10000):
if x*i % 360 == 0:
print(i)
exit() | 0 | null | 46,831,068,051,680 | 229 | 125 |
#!/usr/bin/env python
# coding: utf-8
def gcd ( ax, ay):
x = ax
y = ay
while (True):
if x < y :
tmp = x
x = y
y = tmp
x=x %y
if x == 0:
return y
elif x == 1:
return 1
x,y = map(int, input().split())
print(gcd(x,y))
| def gcd(a,b):
if a < b:
a,b = b,a
while b != 0:
a,b = b,a%b
return a
a,b = map(int,raw_input().split())
print gcd(a,b) | 1 | 7,332,121,148 | null | 11 | 11 |
from collections import deque
n, m = map(int, input().split())
eg = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
eg[a].append(b)
eg[b].append(a)
xs = [0] * (n + 1)
q = deque()
q.append(1)
seen = {1}
while len(q) > 0:
v = q.popleft()
for t in eg[v]:
if t in seen:
continue
q.append(t)
seen.add(t)
xs[t] = v
print("Yes")
print(*xs[2:], sep="\n")
| X, Y= map(int,input().split())
a=2*X
b=(Y-a)/2
c=X-b
if(2*c+4*b==Y and (Y-a)%2==0 and c>=0 and b>=0):
print("Yes")
else:
print("No")
| 0 | null | 17,190,196,146,910 | 145 | 127 |
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = 0
for i in range(M):
sum = sum + A[i]
if N > sum:
print(N - sum)
elif N == sum:
print(0)
else:
print(-1) | #!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, M: int, A: "List[int]"):
answer = N - sum(A)
if answer < 0:
answer = -1
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(M)] # type: "List[int]"
answer = solve(N, M, A)
print(answer)
if __name__ == "__main__":
main()
| 1 | 31,859,546,152,070 | null | 168 | 168 |
h,w,k=map(int, input().split())
Black = []
for i in range(h):
c = input()
for j in range(w):
if c[j] == "#":
Black.append((i,j))
# print(Black, len(Black))
ans = 0
for i in range(2 ** h):
for j in range(2 ** w):
a = len(Black)
for b in Black:
if ((i >> b[0]) & 1) or ((j >> b[1]) & 1):
# if b[0] != i - 1 and b[1] != j - 1:
a -= 1
if a == k:
ans += 1
# print(bin(i),bin(j))
print(ans) | h, w, k = map(int, input().split())
ccc = [input() for _ in range(h)]
ans = 0
for bit_h in range(2 ** h):
for bit_w in range(2 ** w):
cnt = 0
for i in range(h):
for j in range(w):
if (bit_h >> i) & 1 == 0 and (bit_w >> j) & 1 == 0:
if ccc[i][j] == '#':
cnt += 1
if cnt == k:
ans += 1
print(ans) | 1 | 8,992,442,290,010 | null | 110 | 110 |
S = input()
N = len(S)
ans = 'No'
# 文字列strの反転は、str[::-1]
if S == S[::-1] and S[:(N-1)//2] == S[:(N-1)//2][::-1] and S[(N+1)//2:] == S[(N+1)//2:][::-1]:
ans = 'Yes'
print(ans) | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7
for A in a:
ans *= rbg.count(A - 1)
ans %= mod
for i in range(3):
if rbg[i] == A - 1:
rbg[i] = A
break
print(ans)
| 0 | null | 88,327,412,004,010 | 190 | 268 |
n = int(input())
s = input()
if n%2 != 0 or s[:n//2] != s[n//2:]:
print("No")
else:
print("Yes") | # -*- coding: utf-8 -*-
x = []
y = []
while ( 1 ):
temp_x, temp_y = map(int, input().split() )
if (temp_x == 0 and temp_y == 0):
break
if (temp_y < temp_x):
temp_x, temp_y = temp_y, temp_x
x.append(temp_x)
y.append(temp_y)
for (i,j) in zip(x,y):
print(i,j) | 0 | null | 73,446,234,180,540 | 279 | 43 |
#ABC 175 C
x, k, d = map(int, input().split())
x = abs(x)
syou = x // d
amari = x % d
if k <= syou:
ans = x - (d * k)
else:
if (k - syou) % 2 == 0: #残りの動ける数が偶数
ans = amari
else:#残りの動ける数が奇数
ans = abs(amari - d)
print(ans) | X, K, D = list(map(int, input().split()))
X = abs(X)
if(X >= K * D):
print(X - K * D)
else:
q = X // D
r = X % D
if((K - q) % 2 == 0):
print(r)
else:
print(abs(r - D))
| 1 | 5,265,326,983,808 | null | 92 | 92 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.