code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
A1,A2,A3 = map(int,input().split())
if (A1+A2+A3) >= 22 :
print("bust")
else :
print("win") | #!/usr/bin/env python3
def solve(A: "List[int]"):
return ["win", "bust"][sum(A) >= 22]
def main():
A = list(map(int, input().split()))
answer = solve(A)
print(answer)
if __name__ == "__main__":
main()
| 1 | 118,565,177,603,968 | null | 260 | 260 |
import math
a, b, C = map(float, input().split())
h = b * math.sin(math.radians(C))
S = a * h / 2
a1 = b * math.cos(math.radians(C))
cc = math.sqrt(h * h + (a - a1) * (a - a1))
print("{a:5f}".format(a=S))
print("{a:5f}".format(a=a + b + cc))
print("{a:5f}".format(a=h))
| import math
a, b, C = map(float, input().split())
S = (a * b * math.sin(math.radians(C))) / 2
L = a + b + (math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))
h = b * math.sin(math.radians(C))
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| 1 | 174,029,614,672 | null | 30 | 30 |
n = int(input())
nums = []
for i in range(3, n + 1):
if i % 3 == 0 or i % 10 == 3 or '3' in str(i):
#print('',i,end='')
nums.append(i)
for i in nums:
print('',i,end='')
print() | # Aizu Problem ITP_1_5_D: Structured Programming
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
res = []
def CHECK_NUM2(n, i):
x = i
if x % 3 == 0:
res.append(i)
else:
while True:
if x % 10 == 3:
res.append(i)
break
x //= 10
if x == 0:
break
i += 1
if i <= n:
CHECK_NUM(n, i)
def CHECK_NUM(n, i):
while True:
x = i
if x % 3 == 0:
res.append(i)
else:
while True:
if x % 10 == 3:
res.append(i)
break
x //= 10
if x == 0:
break
i += 1
if i > n:
break
def call(n):
CHECK_NUM(n, 1)
n = int(input())
#n=1000
call(n)
print(' ' + ' '.join([str(r) for r in res])) | 1 | 954,590,199,270 | null | 52 | 52 |
s = ""
while True:
s = input()
if s == "-": break
loop_cnt = int(input())
for i in range(loop_cnt):
h = int(input())
s = s[h:] + s[:h]
else:
print(s) | while True:
chk_list = input()
if chk_list == "-":
break
num = int(input())
for i in range(num):
n = int(input())
chk_list = chk_list[n:] + chk_list[0:n]
print(chk_list)
| 1 | 1,935,032,965,048 | null | 66 | 66 |
k = int(input())
ans = 0
s = 7
for i in range(1, 10**6 + 1):
s %= k
if s == 0:
print(i)
exit()
s = s*10 +7
print(-1) | K = int(input())
if K%2==0:
print(-1)
elif K==1:
print(1)
elif K==7:
print(1)
else:
if K%7==0:
K = K//7
a = 1
cnt = 1
ind = -1
for i in range(K):
a = (a*10)%K
cnt += a
if cnt%K==0:
ind = i
break
if ind<0:
print(-1)
else:
print(ind+2) | 1 | 6,170,764,679,840 | null | 97 | 97 |
x=int(input())
if x>=10000 or x//100*5>=x%100:
print(1)
else:
print(0) | X = int(input())
num = X // 100 + 1
calc = X % 100
for a in range(num):
for b in range(num - a):
for c in range(num - a - b):
for d in range(num - a - b - c):
for e in range(num - a - b - c - d):
for f in range(num - a - b - c - d - e):
if calc == 0*a + 1*b + 2*c + 3*d + 4*e + 5*f:
print(1)
exit()
print(0) | 1 | 127,147,674,280,598 | null | 266 | 266 |
N, X, M = map(int, input().split())
existence = [False] * M
a = []
A = X
for i in range(N):
if existence[A]:
break
existence[A] = True
a.append(A)
A = A * A % M
for i in range(len(a)):
if a[i] == A:
break
loop_start = i
result = sum(a[:loop_start])
a = a[loop_start:]
N -= loop_start
loops = N // len(a)
remainder = N % len(a)
result += sum(a) * loops + sum(a[:remainder])
print(result)
| import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
N, M = inpl()
ac = [False] * (N+10)
wa = [0] * (N+10)
a = 0
w = 0
for _ in range(M):
p, S = input().split()
p = int(p)
if S == 'WA':
if not ac[p]:
wa[p] += 1
else:
if not ac[p]:
ac[p] = True
a += 1
w += wa[p]
print(a, w)
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 0 | null | 47,904,556,893,508 | 75 | 240 |
N = int(input())
A = list(map(int, input().split()))
sum = 0
for i in range(N-1):
if A[i] >= A[i+1]:
sum += A[i] - A[i+1]
A[i+1] = A[i]
print(sum)
| h,a= map(int, input().split())
if h==a:
print('Yes')
else:
print('No') | 0 | null | 44,009,949,696,350 | 88 | 231 |
while True:
x = input()
if x == '0 0':break
print(*sorted(map(int,x.split())))
| while 1:
a,b = map(int, raw_input().split())
if a == b == 0:
break
elif a < b:
print "%s %s" % (a,b)
else:
print "%s %s" % (b,a) | 1 | 518,294,130,332 | null | 43 | 43 |
# coding: utf-8
# Your code here!
n = int(input())
M = []
for i in range(n):
adj = list(map(int,input().split()))
if adj[1] == 0:
M += [[]]
else:
M += [adj[2:]]
time = 1
ans = [[j+1,0,0] for j in range(n)] # id d f
while True:
for i in range(n):
if ans[i][1] == 0:
stack = [i]
ans[i][1] = time
time += 1
break
elif i == n-1:
for k in range(n):
print(*ans[k])
exit()
while stack != []:
u = stack[-1]
if M[u] != []:
for i in range(len(M[u])):
v = M[u][0]
M[u].remove(v)
if ans[v-1][1] == 0:
ans[v-1][1] = time
stack.append(v-1)
time += 1
break
else:
stack.pop()
ans[u][2] = time
time += 1
| n = int(input())
Adj = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
u = list(map(int, input().split()))
if u[1] > 0:
for i in u[2: 2 + u[1]]:
Adj[u[0] - 1][i - 1] = 1
color = [0] * n
d = [0] * n
f = [0] * n
time = 0
def dfs(u):
global time
color[u - 1] = 1
time += 1
d[u - 1] = time
for i in range(1, n+1):
if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
dfs(i)
color[u - 1] = 2
time += 1
f[u - 1] = time
for i in range(1, n+1):
if color[i-1] == 0:
dfs(i)
for i in range(n):
print("{} {} {}".format(i+1,d[i],f[i])) | 1 | 3,041,759,200 | null | 8 | 8 |
A = list(map(float, input().split()))
if(A[0]/A[2] <= A[1]):
print("Yes")
else:
print("No") | a,b,c = map(int, input().split())
print("Yes") if b * c >= a else print("No") | 1 | 3,566,931,900,118 | null | 81 | 81 |
import math
import sys
sys.setrecursionlimit(10**9)
MOD = 10**9+7
n, k = map(int, input().split())
k = min(k, n-1)
fact = [1]
for i in range(1, 10**6):
fact.append((fact[i-1]*i)%MOD)
inv = [None]*10**6
def inv_fact(n):
if inv[n] == None:
inv[n] = pow(fact[n], MOD-2, MOD)
return inv[n]
def comb(n, r):
return (fact[n]*inv_fact(n-r)*inv_fact(r))%MOD
ans = 0
for i in range(k+1):
ans = (ans + comb(n-1, i)*comb(n, i))%MOD
print(ans) | mod = 10 ** 9 + 7
n, k = map(int, input().split())
fact = [1] * (2 * n + 1)
inv = [1] * (2 * n + 1)
invf = [1] * (2 * n + 1)
for i in range(2, 2 * n + 1):
fact[i] = fact[i-1] * i % mod
inv[i] = -inv[mod % i] * (mod // i) % mod
invf[i] = invf[i-1] * inv[i] % mod
count = 0
for i in range(min(n, k+1)):
c = fact[n] * invf[n-i] * invf[i] % mod
count += c * fact[n-1] * invf[n-i-1] * invf[i] % mod
count %= mod
print(count) | 1 | 67,143,536,786,690 | null | 215 | 215 |
import math
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N = read_int()
P = read_ints()
min_so_far = math.inf
count = 0
for p in P:
min_so_far = min(min_so_far, p)
if min_so_far >= p:
count += 1
return count
if __name__ == '__main__':
print(solve())
| 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,617,768,937,868 | null | 233 | 233 |
N,K=map(int,input().split())
m=N//K
print(min(abs(N-m*K),abs(N-(m+1)*K))) | 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() | 0 | null | 26,276,095,928,742 | 180 | 125 |
n = input()
digit1 = int(n[-1])
ans = ''
if digit1 in {2, 4, 5, 7, 9}:
ans = 'hon'
elif digit1 in {0, 1, 6, 8}:
ans = 'pon'
elif digit1 in {3}:
ans = 'bon'
print(ans)
| N = input()
PON = ["0","1","6","8"]
BON = ["3"]
if N[-1:] in BON:
print("bon")
elif N[-1:] in PON:
print("pon")
else:
print("hon") | 1 | 19,180,764,723,360 | null | 142 | 142 |
K, N = map(int, input().split())
Alst = list(map(int, input().split()))
zero = Alst[0] + K
M = 0
now = Alst[0]
for i in Alst:
dis = i - now
if dis > M:
M = dis
now = i
last = zero - now
if last > M:
M = last
print(K - M) | import copy
a = [int(c) for c in input().split()]
K = a[0]
N = a[1]
A = [int(c) for c in input().split()]
B = list(map(lambda x: x+K,copy.deepcopy(A)))
A = A+B
l = 0
tmp = 0
cnt = 0
for i in range(N):
tmp = A[i+1]-A[i]
if tmp > l :
cnt = i
l = tmp
print(K-l)
| 1 | 43,500,730,138,580 | null | 186 | 186 |
import math
A,B,C,D = map(int, input().split())
Taka=A/D
Aoki=C/B
if math.ceil(Taka)>=math.ceil(Aoki):
print("Yes")
else:
print("No") | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
s = input()
C = Counter(s)
w,r = 0,0
for k,v in C.items():
if k == 'W':
w += v
else:
r += v
p = 'R' * r + 'W' * w
ans = 0
for i in range(n):
if p[i] == s[i]:
pass
else:
ans += 1
print(ans//2)
| 0 | null | 18,065,846,991,210 | 164 | 98 |
a = int(input())
n = 3.141592
print((a + a) * n) | r=int(input())
pi=3.14159265358979323846
a=2*pi*r
print(a) | 1 | 31,340,364,093,952 | null | 167 | 167 |
N = int(input())
S = input()
count = 0
for i in range(0, N - 2):
if S[i] == 'A':
if S[i+1] == 'B':
if S[i+2] == 'C':
count += 1
print(count) | import sys
from itertools import combinations
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
s = S()
# print(s.count('ABC'))
ans = 0
for i in range(len(s)-2):
if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
ans += 1
print(ans)
| 1 | 99,631,591,633,860 | null | 245 | 245 |
# https://atcoder.jp/contests/agc039/tasks/agc039_a
s = list(input())
k = int(input())
i = 0
a = 0
while i < len(s):
if i == len(s) - 1:
break
if s[i] == s[i+1]:
a += 1
i += 2
else:
i += 1
else:
print(a * k)
exit()
i = -1
b = 0
while i < len(s):
if i == len(s) - 1:
print(a + b * (k - 1))
exit()
if s[i] == s[i + 1]:
b += 1
i += 2
else:
i += 1
else:
print(a * ((k + 1) // 2) + b * ((k - 1) // 2))
exit() | n = int(input())
for i in range(1, n + 1):
if i % 3 == 0 or str(i).find("3") != -1:
print(" {}".format(i), end = '')
print()
| 0 | null | 88,291,709,753,210 | 296 | 52 |
N, K = map(int, input().split())
def f(x):
return( N-x*K )
def test(x):
return( f(x) >= 0 )
left = - 1 # return = right = (取り得る値の最小値) の可能性を排除しないために、-1 が必要
right = 10**18
while right - left > 1: # 最終的に (right, left, mid) = (最小値, 最小値 - 1, 最小値 - 1) に収束するため、差が 1 になったときに終了すればよい
mid = (left+right)//2
if test(mid):
left = mid
else:
right = mid
print(min(abs(N-left*K), abs(N-right*K))) | def manipulate(x, k):
return abs(x - k)
n, k = list(map(int, input().split()))
n = n % k
while n > k / 2:
n = manipulate(n, k)
print(n) | 1 | 39,556,643,953,398 | null | 180 | 180 |
import math
while True:
line = int(input())
if line == 0:
break
l = [float(s) for s in input().split()]
avg = sum(l) / len(l)
a2 = 0
for i in l:
a2 += (avg - i) ** 2
print(math.sqrt(a2 / len(l))) | from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
W = [int(stdin.readline().rstrip()) for _ in range(N)]
def check(P):
i = 0
for _ in range(K):
s = 0
while s+W[i] <= P:
s += W[i]
i += 1
if i == N:
return N
return i
def solver():
mid, l, u = 0, 0, 100000*10000
while u-l > 1:
mid = (l+u)//2
v = check(mid)
if v >= N:
u = mid
else:
l = mid
return u
print(solver())
| 0 | null | 141,515,039,452 | 31 | 24 |
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#main code here!
n,k,s=MI()
ans=[]
if s==10**9:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(1)
else:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(10**9)
print(*ans)
if __name__=="__main__":
main()
| n,k,s = map(int,input().split())
if s == 10**9:
ans = [1]*n
for i in range(k):
ans [i] = s
else:
ans = [s+1]*n
for i in range(k):
ans[i] = s
for i in ans:
print(i,end = " ")
| 1 | 90,883,956,066,930 | null | 238 | 238 |
from itertools import combinations as cb
n,x,y = map(int, input().split())
pair = list(cb(range(1,n+1), 2))
dist = [0]*n
for a in pair:
if a[1] <= x or a[0] >= y:
dist[a[1]-a[0]] += 1
else:
dist[min(abs(x-a[0])+abs(y-a[1])+1,a[1]-a[0])] += 1
for i in range(1, n):
print(dist[i]) | import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *D = map(int, read().split())
csum = accumulate(D)
ans = sum(s * d for s, d in zip(csum, D[1:]))
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 106,396,100,154,890 | 187 | 292 |
n = int(input())
line = list(map(int, input().split()))
max = line[0]
min = line[0]
sum = line[0]
for i in range(1, n):
if max < line[i]:
max = line[i]
elif min > line[i]:
min = line[i]
sum += line[i]
print(min, max, sum)
| while True:
h,w=map(int,input().split())
if h==0 and w==0:
break
for i in range(h):
for j in range(w):
if i%2==0:
if j%2==0:
print("#",end="")
else:
print(".",end="")
else:
if j%2==0:
print(".",end="")
else:
print("#",end="")
print("")
print("")
| 0 | null | 807,682,233,452 | 48 | 51 |
def some():
n = int(input())
for i in range(9, 0, -1):
for j in range(9, 0, -1):
if i* j == n:
print("Yes")
exit()
print("No")
some() | # :20
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()
INF = float('inf')
x, y, a, b, c = LI()
p = sorted(LI())[::-1][:x]
q = sorted(LI())[::-1][:y]
r = sorted(LI())[::-1][:x+y]
# print(p, q, r)
bucket = []
bucket += [[i, 'p'] for i in p]
bucket += [[i, 'q'] for i in q]
bucket += [[i, 'r'] for i in r]
bucket = sorted(bucket, key=lambda x: x[0])
# print(bucket)
d = {'p': 0, 'q': 0}
ans = 0
cnt = 0
while cnt < x + y:
if bucket[-1][1] == 'p' and d[bucket[-1][1]] < x:
ans += bucket.pop()[0]
d['p'] += 1
cnt += 1
elif bucket[-1][1] == 'q' and d[bucket[-1][1]] < y:
ans += bucket.pop()[0]
d['q'] += 1
cnt += 1
else:
ans += bucket.pop()[0]
cnt += 1
print(ans)
| 0 | null | 102,481,143,357,956 | 287 | 188 |
import math
a, b, h, m = map(int, input().split())
x = 6 * m
y = 30 * h + 0.5 * m
C = max(x, y) - min(x, y)
C = min(C, 360 - C)
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))
| import math
n,d = map(int,input().split())
point_list = [0,0]*n
for i in range(n):
point = list(map(int,input().split()))
point_list[i]=point
count = 0
for j in range(n):
distance = math.sqrt(point_list[j][0]**2 + point_list[j][1]**2)
if distance <= d:
count += 1
print(count) | 0 | null | 13,062,991,663,680 | 144 | 96 |
X, Y, A, B, C = map(int, input().split())
*p, = map(int, input().split())
*q, = map(int, input().split())
*r, = map(int, input().split())
p.sort(key=lambda x: -x)
q.sort(key=lambda x: -x)
p = p[:X]
q = q[:Y]
pqr = p+q+r
pqr.sort(key=lambda x: -x)
print(sum(pqr[:X+Y])) | from collections import deque
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r = sorted(r, reverse=True)
ans_p = deque(p[:X])
ans_q = deque(q[:Y])
ans_r = deque(r)
while (ans_p[-1]<ans_r[0]) or (ans_q[-1]<ans_r[0]):
if ans_p[-1] <= ans_q[-1]:
ans_p.pop()
ans_p.appendleft(ans_r[0])
ans_r.popleft()
else:
ans_q.pop()
ans_q.appendleft(ans_r[0])
ans_r.popleft()
if not ans_r:
break;
ans = sum(ans_p) + sum(ans_q)
print(ans) | 1 | 44,582,524,967,288 | null | 188 | 188 |
a,b,c=map(int,input().split())
S=[a,b,c]
s=set(S)
if len(s)==2:
print('Yes')
else:
print('No')
| a,b,c,d=map(int,input().split())
ac = c/b
cc = -(-a//d)
if ac<=cc:
print('Yes')
else:
print('No') | 0 | null | 48,656,154,953,910 | 216 | 164 |
import math
n, a, b = map(int, input().split())
p = 10 ** 9 + 7
#ans = 2 ** n - 1 - N C a - N C b
def modpow(a, n, MOD):
res = 1
while (n > 0):
if (n & 1):
res = res * a % MOD
a = a * a % MOD
n >>= 1
return res
def cmb(n, r, p):
A = 1
for i in range(r):
A *= (n - i)
A *= modpow(i + 1, p - 2, p)
A %= p
return A
ans = (modpow(2, n, p) - 1) % p
ans -= cmb(n, a, p) + cmb(n, b, p)
print(ans % p)
| n,a,b=map(int,input().split())
MOD=10**9+7
def inv(a):
return pow(a,MOD-2,MOD)
def choose(n,r):
if r==0 or r==n:
return 1
else:
A=B=1
for i in range(r):
A=A*(n-i)%MOD
B=B*(i+1)%MOD
return A*inv(B)%MOD
print((pow(2,n,MOD)-1-choose(n,a)-choose(n,b))%MOD) | 1 | 66,010,250,633,122 | null | 214 | 214 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
H,W,K = map(int, readline().split())
S = [readline().strip() for j in range(H)]
white = []
for line in S:
white.append(line.count("1"))
white_total = sum(white)
if white_total <= K:
print(0)
exit()
ans = 10**5
for i in range(2**(H-1)):
impossible = False
x = 0
ly = bin(i).count("1")
y_sum = [0]*(ly + 1)
j = 0
while j < W:
m = 0
y = [0]*(ly + 1)
for k in range(H):
if S[k][j] == "1":
y[m] += 1
if y[m] > K:
impossible = True
break
y_sum[m] += 1
if y_sum[m] > K:
x += 1
y_sum = [0]*(ly + 1)
j -= 1
break
if (i >> k) & 1:
m += 1
j += 1
if impossible:
x = 10**6
break
ans = min(ans, x + ly)
print(ans)
if __name__ == "__main__":
main()
| from itertools import permutations
n = int(input())
s = input()
out = 0
ans = s.count("R")*s.count("G")*s.count("B")
combi = list(permutations(["R","G","B"],3))
for i in range(1,n):
for j in range(n-i*2):
if (s[j], s[j+i], s[j+i*2]) in combi:
ans -= 1
print(ans) | 0 | null | 42,250,844,152,220 | 193 | 175 |
# コッホ曲線 Koch curve
import math
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return str(self.x) + " " + str(self.y)
def Koch(p1, p2, n):
if n == 0:
print(p1)
else:
s = Point(p1.x * 2 / 3 + p2.x * 1 / 3, p1.y * 2 / 3 + p2.y * 1 / 3)
u = Point(p1.x / 2 + p2.x / 2 + p1.y * r3 / 6 - p2.y * r3 / 6, p1.y / 2 + p2.y / 2 + p2.x * r3 / 6 - p1.x * r3 / 6)
t = Point(p1.x * 1 / 3 + p2.x * 2 / 3, p1.y * 1 / 3 + p2.y * 2 / 3)
Koch(p1, s, n - 1)
Koch(s, u, n - 1)
Koch(u, t, n - 1)
Koch(t, p2, n - 1)
r3 = math.sqrt(3)
start = Point(0, 0)
goal = Point(100, 0)
n = int(input())
Koch(start, goal, n)
print(goal)
| import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
N = int(input())
ans = []
const = 2*3**0.5
def korch_curve(Lx,Ly,Rx,Ry,i):
if i == 0:
ans.append((Lx,Ly))
return
third_y = (Ly*2 + Ry)/3
third_x = (Lx*2 + Rx)/3
korch_curve(Lx,Ly,third_x,third_y,i - 1)
middle_x = (Lx + Rx)/2 - (Ry - Ly)/const
middle_y = (Ly + Ry)/2 + (Rx - Lx)/const
korch_curve(third_x,third_y,middle_x,middle_y,i - 1)
third_second_x = (Lx + Rx*2)/3
third_second_y = (Ly + Ry*2)/3
korch_curve(middle_x,middle_y,third_second_x,third_second_y,i - 1)
korch_curve(third_second_x,third_second_y,Rx,Ry,i - 1)
korch_curve(0,0,100,0,N)
ans.append((100,0))
for a in ans:
print(*a)
| 1 | 122,934,106,440 | null | 27 | 27 |
from collections import deque
q = deque()
n = int(input())
C = [deque() for _ in range(n+1)]
for i in range(n):
tmp = list(map(int,input().split()))
for j in range(tmp[1]):
C[tmp[0]].append(tmp[2+j])
visited = [False]*(n+1)
d = [0]*(n+1)
f = [0]*(n+1)
t = 0
def stack(i):
global t
if visited[i] == False:
q.append(i)
while q:
#ノードの探索開始
node = q[-1]
if d[node] == 0:
t += 1
d[node] = t
visited[node] = True
for _ in range(len(C[node])):
tmp = C[node].popleft()
if visited[tmp] == False:
next_node = tmp
q.append(next_node) #未探索の接続ノード
break
#未探索接続ノードがなければそのノードは探索終了
else:
t += 1
f[q.pop()] = t
for i in range(1,n+1):
stack(i)
for i in range(1,n+1):
print("{} {} {}".format(i,d[i],f[i]))
| n = int(input())
adjacency_list = []
for i in range(n):
input_list = list(map(int, input().split()))
adjacency_list.append(input_list[2:])
checked_set = set()
dfs_stack = []
v =[0 for i in range(n)]
f =[0 for i in range(n)]
time = 1
for i in range(n):
if i not in checked_set:
dfs_stack = []
dfs_stack.append(i)
while dfs_stack:
current = dfs_stack.pop()
if current not in checked_set:
checked_set.add(current)
v[current] = time
dfs_stack.append(current)
for ad in reversed(adjacency_list[current]):
if ad-1 not in checked_set:
dfs_stack.append(ad-1)
time +=1
elif f[current] == 0:
f[current] = time
time +=1
for i in range(n):
print(f'{i+1} {v[i]} {f[i]}')
| 1 | 2,813,638,248 | null | 8 | 8 |
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
l = 0
r = max(A)
while l + 1 < r:
m = (l+r)//2
n = sum([(x-1)//m for x in A])
if n > K:
l = m
else:
r = m
print(r) | X = int(input())
for a in range(121):
for b in range(121):
if a ** 5 - b ** 5 == X:
print(a, b)
break
elif a ** 5 + b ** 5 == X:
print(a, -b)
break
else:
continue
break
| 0 | null | 15,941,945,565,810 | 99 | 156 |
N=int(input())
LR=[]
for i in range(N):
X,L=map(int,input().split())
LR.append([X-L,X+L])
LR.sort(key=lambda x:x[1])
nin=LR[0][1]
ans=1
for i in range(1,N):
if nin<=LR[i][0]:
nin=LR[i][1]
ans+=1
print(ans) | from decimal import *
x,y,z = map(int,input().split())
a=Decimal(x)
b=Decimal(y)
c=Decimal(z)
if Decimal((c-a-b)**Decimal(2)) > Decimal(Decimal(4)*a*b) and c-a-b > 0:
print('Yes')
else:
print('No') | 0 | null | 70,666,978,083,940 | 237 | 197 |
def bubbleSort(A,N):
flag = 1 #????????????????????£??????????????????????????????????????¨??????
i = 0
while flag:
flag = 0
for j in range(N-1,i,-1):
if int(A[j][1]) < int(A[j-1][1]):
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag = 1
i += 1
return A
def selectionSort(A,N):
for i in range(0,N-1):
minj = i
j=i+1
for j in range(j,N):
if int(A[j][1]) < int(A[minj][1]):
minj = j
tmp = A[minj]
A[minj] = A[i]
A[i] = tmp
return A
def isStable(ori,sorted):
for i in range(len(ori)-1):
for j in range(i+1, len(ori)-1):
for a in range(len(ori)):
for b in range(a+1, len(ori)):
if ori[i][1] == ori[j][1] and ori[i] == sorted[b] and ori[j] == sorted[a]:
return 'Not stable'
return 'Stable'
def output(A):
for i in range(len(A)): # output
if i == len(A) - 1:
print(A[i])
else:
print(A[i], end=' ')
if __name__ == '__main__':
N = int(input())
numbers = input().split(' ')
n1 = numbers.copy()
n2 = numbers.copy()
A = bubbleSort(n1,N)
output(A)
print(isStable(numbers,A))
B = selectionSort(n2,N)
output(B)
print(isStable(numbers, B)) | #coding:utf-8
#1_2_C
def BubbleSort(cards, n):
for i in range(n):
for j in range(n-1, i, -1):
if cards[j][1] < cards[j-1][1]:
cards[j], cards[j-1] = cards[j-1], cards[j]
return cards
def SelectionSort(cards, n):
for i in range(n):
minj = i
for j in range(i, n):
if cards[minj][1] > cards[j][1]:
minj = j
cards[i], cards[minj] = cards[minj], cards[i]
return cards
n = int(input())
cards = input().split()
copy = list(cards)
print(*BubbleSort(cards, n))
print("Stable")
print(*SelectionSort(copy, n))
print("Stable" if cards == copy else "Not stable") | 1 | 23,394,293,120 | null | 16 | 16 |
cnt = int(input())
values = input()
i_list = [int(x) for x in values.split()]
print('{0} {1} {2}'.format(min(i_list), max(i_list), sum(i_list))) | _, lis = input(), list(map(int, input().split()))
print("{} {} {}".format(min(lis), max(lis), sum(lis)))
| 1 | 736,747,777,494 | null | 48 | 48 |
h = int(input())
ans = 0
i = 0
while True:
if(2**i>=h):
break
i+=1
if(i == 0):
print(1)
elif(2**i==h):
print(2**(i+1)-1)
else:
print(2**i-1)
| H = int(input())
num = 1
ans = 0
while H > 0:
H //= 2
ans += num
num *= 2
print(ans) | 1 | 79,754,550,510,278 | null | 228 | 228 |
N=int(input())
S=[input() for i in range(N)]
print(len(set(S))) | import math
N=int(input())
def era(n):
prime=[]
furui=list(range(2,n+1))
while furui[0]<math.sqrt(n):
prime.append(furui[0])
furui=[i for i in furui if i%furui[0]!=0]
return prime+furui
furui=era(10**6+7)
minfac=list(range(10**6+8))
for i in furui:
for j in range(i,(10**6+7)//i+1):
if minfac[i*j]==i*j:
minfac[i*j]=i
ans=0
for i in range(1,N):
temp=1
temp2=1
l=1
while i != 1:
if minfac[i]!=l:
temp*=temp2
temp2=2
else:
temp2+=1
l=minfac[i]
i//=l
temp*=temp2
ans+=temp
print(ans) | 0 | null | 16,378,400,303,870 | 165 | 73 |
def input_int():
return(int(input()))
def input_int_list():
return(list(map(int,input().split())))
def input_int_map():
return(map(int,input().split()))
def run():
S = list(input())
left = [0] * (len(S) + 1)
right = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == '<':
left[i + 1] += 1 + left[i]
for i in range(len(S) - 1, -1, -1):
if S[i] == '>':
right[i] = right[i + 1] + 1
ans = [0] * (len(S) + 1)
for i in range(len(S) + 1):
ans[i] = max(left[i], right[i])
print(sum(ans))
run()
| n,m = map(int, input().split())
a = [[] for x in range(0, n)]
b = [0 for x in range(0, m)]
for x in range(0, n):
a[x] = list(map(int, input().split()))
for x in range(0, m):
b[x] = int(input())
for i in range(0, n):
c = 0
for j in range(0, m):
c += a[i][j] * b[j]
print(c) | 0 | null | 79,035,763,532,350 | 285 | 56 |
N=int(input())
A=input().split()
S={}
for a in A:
if a in S.keys():
print('NO')
break
S[a]=1
else:
print('YES') | n = int(input())
P = list(map(int,input().split()))
S={}
ans="YES"
for p in P:
if p in S:
ans = "NO"
break
else:
S[p]=1
print(ans)
| 1 | 73,563,132,700,056 | null | 222 | 222 |
class CircleInaRectangle:
def __init__(self, W, H, x, y, r):
if 0 <= x - r and 0 <= y - r and x + r <= W and y + r <= H:
print "Yes"
else:
print "No"
if __name__ == "__main__":
W, H, x, y, r = map(int, raw_input().split())
CircleInaRectangle(W, H, x, y, r) | #!usr/bin/env python3
def string_five_numbers_spliter():
"""Split a given space-separated five numbers in a string into integers
Return five integer values from a given space-separated five integers in a string.
Returns:
Five integer values; namely, w, h, x, y and r
"""
w, h, x, y, r = [int(i) for i in input().split()]
return w, h, x, y, r
def main():
# Given that there are a rectangle and a circle.
# Let w, h, x, y and r be such that:
# w = width of the rectangle
# h = height of thek rectangle
# x = x coordinate for the centre of the circle
# y = y coordinate for the centre of the circle
# r = diameter of the circle
w, h, x, y, r = string_five_numbers_spliter()
if (not (x < 0) and not (y < 0) and
not (x + r < 0) and not (y + r < 0) and
not (x + r > w) and not (y + r > h)):
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 1 | 441,795,415,620 | null | 41 | 41 |
####
n = int(input())
memo = [-1]*(n+10)
def fib(i):
if i==0 or i == 1:
return 1
if memo[i] != -1:
return memo[i]
memo[i] = fib(i-1) + fib(i-2)
return memo[i]
print(fib(n))
| N = int(input())
memolist = [-1]*(N+1)
def fib(x):
if memolist[x] == -1:
if x == 0 or x == 1:
memolist[x] = 1
else:
memolist[x] = fib(x - 1) + fib(x - 2)
return memolist[x]
print(fib(N))
| 1 | 2,107,962,890 | null | 7 | 7 |
#!/usr/bin/env python3
# from numba import njit
# input = stdin.readline
# @njit
def solve(a,b,c):
return c-a-b >= 0 and pow(c-a-b,2) > 4*a*b
def main():
a,b,c = map(int,input().split())
print("Yes" if solve(a,b,c) else "No")
return
if __name__ == '__main__':
main()
| import sys
n = int(input())
A=[int(e)for e in sys.stdin]
cnt = 0
G = [int((3**i-1)/2)for i in range(14,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
for g in G:
insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')
| 0 | null | 25,859,632,860,392 | 197 | 17 |
#####
# B #
#####
N = input()
sum = sum(map(int,N))
if sum % 9 == 0:
print('Yes')
else:
print('No')
| import sys
def input(): return sys.stdin.readline().rstrip()
def main():
h,w,k=map(int,input().split())
S=[input() for _ in range(h)]
ANS=[[0]*w for _ in range(h)]
cunt=0
for i,s in enumerate(S):
for j,ss in enumerate(s):
if ss=='#':
cunt+=1
ANS[i][j]=cunt
elif j>=1 and ANS[i][j-1]>0:
ANS[i][j]=ANS[i][j-1]
if ANS[i][-1]!=0:
for j in range(w-2,-1,-1):
if ANS[i][j]==0:
ANS[i][j]=ANS[i][j+1]
for i in range(h-2,-1,-1):
if ANS[i][0]==0:
for j,ans in enumerate(ANS[i+1]):
ANS[i][j]=ans
for i in range(h):
if ANS[i][0]==0:
for j,ans in enumerate(ANS[i-1]):
ANS[i][j]=ans
for ans in ANS:
print(*ans)
if __name__=='__main__':
main() | 0 | null | 73,973,658,008,888 | 87 | 277 |
import sys
input = sys.stdin.readline
MAX = 2*10**6+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r):
if n<r:
return 0
if n<0 or r<0:
return 0
return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
K = int(input())
S = input()[:-1]
L = len(S)
ans = 0
for i in range(L, L+K+1):
ans += C(i-1, L-1)*pow(25, i-L, MOD)*pow(26, L+K-i, MOD)
ans %= MOD
print(ans) | MOD = 10**9+7
k = int(input())
s = input()
MAX = k + len(s)
factorial = [0] * (MAX + 1)
factorial[0] = 1
for i in range(1, MAX + 1):
factorial[i] = factorial[i-1] * i % MOD
ifactorial = [0] * (MAX + 1)
ifactorial[MAX] = pow(factorial[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
ifactorial[i - 1] = ifactorial[i] * i % MOD
pow25 = [1] * (k + 1)
pow26 = [1] * (k + 1)
for i in range(k):
pow25[i + 1] = pow25[i] * 25
pow25[i + 1] %= MOD
pow26[i + 1] = pow26[i] * 26
pow26[i + 1] %= MOD
def combination(n, k):
ret = factorial[n] * ifactorial[k] * ifactorial[n - k]
return ret % MOD
ans = 0
for i in range(k + 1):
tmp = combination(i + len(s) - 1, len(s) - 1)
tmp *= pow25[i]
tmp %= MOD
# tmp *= pow(25, i, MOD)
tmp *= pow26[k - i]
# tmp *= pow(26, k - i, MOD)
tmp %= MOD
ans += tmp
ans %= MOD
print(ans)
| 1 | 12,860,376,751,992 | null | 124 | 124 |
def abc169c_multiplication3():
a, b = input().split()
a = int(a)
b = int(b[0] + b[2] + b[3])
print(a * b // 100)
abc169c_multiplication3()
| a,b = input().split()
#print(a,b)
A = int(a)
x,y = b.split('.')
B = int(x)*100+int(y)
print(int(A*B)//100) | 1 | 16,655,570,902,092 | null | 135 | 135 |
"""
AtCoder :: Beginner Contest 175 :: C - Walking Takahashi
https://atcoder.jp/contests/abc175/tasks/abc175_c
"""
import sys
def solve(X, K, D):
"""Solve puzzle."""
# print('solve X', X, 'K', K, 'D', D)
if D == 0:
return X
X = abs(X)
soln = abs(X - (K * D))
steps_to_zero = abs(X) // D
# print('steps to zero', steps_to_zero, K - steps_to_zero)
# print('to zero', abs(X - (steps_to_zero * D)))
# Undershoot or get directly on to zero.
if steps_to_zero <= K and ((K - steps_to_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_to_zero * D)))
# Overshoot by one step
steps_past_zero = steps_to_zero + 1
# print('steps past zero', steps_past_zero, K - steps_past_zero)
# print('past zero', abs(X - (steps_past_zero * D)))
if steps_past_zero <= K and ((K - steps_past_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_past_zero * D)))
# Overshoot and return by one
steps_back_zero = steps_past_zero + 1
# print('steps back zero', steps_back_zero, K - steps_back_zero)
# print('back zero', abs(X - (steps_back_zero * D)))
if steps_back_zero <= K and ((K - steps_back_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_back_zero * D)))
return soln
def main():
"""Main program."""
X, K, D = (int(i) for i in sys.stdin.readline().split())
print(solve(X, K, D))
if __name__ == '__main__':
main()
| x, k, d = map(int, input().split())
x = abs(x)
if x >= k*d:
ans = x - k*d
elif k&1:
ans = min((x-d)%(2*d), 2*d - (x-d)%(2*d) )
else:
ans = min(x%(2*d), 2*d - x%(2*d))
print(ans) | 1 | 5,165,861,055,462 | null | 92 | 92 |
x1,y1,x2,y2=list(map(float,input().split()))
d=((x1-x2)**2+(y1-y2)**2)**0.5
print(d) | def main():
X = int(input())
ans = 0
money = 100
while money < X:
ans += 1
money = money * 101 // 100
print(ans)
if __name__ == '__main__':
main() | 0 | null | 13,613,760,319,100 | 29 | 159 |
from collections import defaultdict
N, X, M = map(int, input().split())
A = [X]
visited = set()
visited.add(X)
idx = defaultdict()
idx[X] = 0
iii = -1
for i in range(1, M):
tmp = (A[-1]**2) % M
if tmp not in visited:
A.append(tmp)
visited.add(tmp)
idx[tmp] = i
else:
iii = idx[tmp]
ans = 0
if iii == -1:
ans = sum(A[:N])
print(ans)
exit()
else:
# ループの頭の直前まで
ans += sum(A[:iii])
N -= iii
if N > 0:
# ループの長さ
l = len(A) - iii
ans += (N // l) * sum(A[iii:])
N -= N // l * l
if N > 0:
# ループに満たないN
ans += sum(A[iii:iii + N])
print(ans)
| n, x, m = map(int, input().split())
A = [0, x]
d = {x:1}
for i in range(2, n+1):
A.append(A[i-1]**2 % m)
if A[i] in d:
j = d[A[i]]
q, r = divmod(n-j+1, i-j)
print(sum(A[:j]) + q*sum(A[j:i]) + sum(A[j:j+r]))
break
else:
d[A[i]] = i
else:
print(sum(A)) | 1 | 2,819,581,048,050 | null | 75 | 75 |
N,K=map(int, input().split())
if K>=N:
print(min(N, K-N))
else:
res = N % K
print(min(res, K-res)) | N, K = map(int, input().split())
t = N % K
print(min(t, K-t)) | 1 | 39,324,479,526,982 | null | 180 | 180 |
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
Y,Z=0,0
V,W=0,0
T,U=0,0
for i in range(D):
for j in range(26):
X[j]+=C[j]
XX[j]+=X[j]
Y,Z=-1,-10**20
V,W=Y,Z
T,U=V,W
for j in range(26):
if Y==-1:
Y,Z=0,X[0]+S[i][0]
continue
if Z<X[j]+S[i][j]:
T,U=V,W
V,W=Y,Z
Y,Z=j,X[j]+S[i][j]
elif W<X[j]+S[i][j]:
T,U=V,W
V,W=j,X[j]+S[i][j]
elif U<X[j]+S[i][j]:
T,U=j,X[j]+S[i][j]
XX[Y]-=X[Y]
X[Y]=0
P.append([Y,V,T])
if randrange(0,50)==0:
P[i][1]=randrange(0,26)
if randrange(0,5)==0:
P[i][2]=randrange(0,26)
P[i]=tuple(P[i])
SCORE=0
X=[0]*26
for i in range(D):
SCORE+=S[i][P[i][0]]
for j in range(26):
X[j]+=C[j]
X[P[i][0]]=0
SCORE-=sum(X)
SCORE2=0
YY=[]
for i in range(D):
for k in range(2):
d,q=i,P[i][k+1]
SCORE2=SCORE
YY=XX[:]
SCORE2-=S[d][P[d][0]]
SCORE2+=S[d][q]
for j in range(26):
X[j]=0
YY[P[d][0]],YY[q]=0,0
for j in range(D):
if j==d:
Z=q
else:
Z=P[j][0]
X[P[d][0]]+=C[P[d][0]]
X[q]+=C[q]
X[Z]=0
YY[P[d][0]]+=X[P[d][0]]
YY[q]+=X[q]
if SCORE2-sum(YY)>SCORE-sum(XX):
z=[P[i][k+1]]
for l in range(3):
if l!=k:
z.append(P[i][l])
P[i]=tuple(z)
XX=YY[:]
SCORE=SCORE2
for i in range(D):
print(P[i][0]+1) | target = input()
sum = 0
for each in target:
sum += int(each)
if sum % 9 == 0:
print("Yes")
else:
print("No") | 0 | null | 6,982,276,907,920 | 113 | 87 |
t = 0
h = 0
for i in range(int(input())):
cards = input().split()
if cards[0] > cards[1]:
t += 3
elif cards[0] == cards[1]:
t += 1
h += 1
else:
h += 3
print(str(t) + " " + str(h)) | def MI(): return map(int, input().split())
N,X,T=MI()
if N%X!=0:
ans=(N//X+1)*T
else:
ans=N//X*T
print(ans) | 0 | null | 3,161,764,147,950 | 67 | 86 |
s = input()
k = int(input())
if len(set(s)) == 1:
print((len(s)*k)//2)
exit()
ss = s + s
shoko = 0
prev = ''
cnt = 0
for i in range(len(s)):
if s[i] == prev:
cnt += 1
else:
shoko += cnt // 2
cnt = 1
prev = s[i]
shoko += cnt // 2
kosa = 0
prev = ''
cnt = 0
for i in range(len(ss)):
if ss[i] == prev:
cnt += 1
else:
kosa += cnt // 2
cnt = 1
prev = ss[i]
kosa += cnt // 2
kosa -= shoko
print(shoko + (k-1)*kosa) | from math import floor
S = input()
K = int(input())
# Sが1文字しかない
if len(set(S)) == 1:
print(floor(len(S) * K / 2))
exit()
ans = 0
if S[0] != S[-1]:
# Sの中での答え × K回数
c = "0"
count = 0
for i in range(len(S)):
if c == S[i]:
count += 1
else:
# floor(連続した文字の回数 / 2)だけ書き換える
ans += count // 2
c = S[i] # 情報更新
count = 1
ans += count // 2 # 最後の分
ans = ans * K
else:
# 先頭と末端もある
c1 = 1
for i in range(1, len(S)):
if S[i] == S[0]:
c1 += 1
else:
break
c2 = 1
for j in reversed(range(len(S) - 1)):
if S[j] == S[-1]:
c2 += 1
else:
break
ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1))
c3 = 0
c = "0"
for k in range(i, j + 1):
if S[k] == c:
c3 += 1
else:
ans += c3 // 2 * K
c = S[k]
c3 = 1
ans += c3 // 2 * K
print(ans) | 1 | 175,335,000,202,780 | null | 296 | 296 |
a, b = input().split()
print(int(a)*int(b[0]+b[2]+b[3])//100)
| from decimal import Decimal
A, B = input().split()
A = int(A)
if len(B) == 1:
B = int(B[0] + '00')
elif len(B) == 3:
B = int(B[0] + B[2] + '0')
else:
B = int(B[0]+B[2]+B[3])
x = str(A*B)
print(x[:-2] if len(x) > 2 else 0)
| 1 | 16,504,485,498,240 | null | 135 | 135 |
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
L = int(readline())
print((L/3)**3) | w,h,x,y,r=map(int,raw_input().split())
f=0
if x+r>w:
f=1
if y+r>h:
f=1
if r>x:
f=1
if r>y:
f=1
if f==0:
print "Yes"
else:
print "No" | 0 | null | 23,650,654,559,270 | 191 | 41 |
K,N = map(int,input().split())
A = list(map(int,input().split()))
B = []
for i in range(N-1):
temp = A[i+1]-A[i]
B.append(temp)
B.append(K-A[-1]+A[0])
B.sort()
#print(B)
ans = K-B[-1]
print(ans)
| from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
sl = []
flag = False
for i in range(h):
for j in range(w):
if s[i][j] == '.':
sl.append([i, j])
q = deque()
dire = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = 0
for sh, sw in sl:
c = [[0]*w for _ in range(h)]
q.append((sh, sw, 0))
while q:
ph, pw, k = q.pop()
if c[ph][pw] == 0:
ans = max(ans, k)
c[ph][pw] = 1
for dh, dw in dire:
hdh, wdw = ph+dh, pw+dw
if 0 <= hdh < h and 0 <= wdw < w and c[hdh][wdw] == 0:
if s[hdh][wdw] == '.':
q.appendleft((hdh, wdw, k+1))
print(ans) | 0 | null | 69,081,724,948,540 | 186 | 241 |
n,k=map(int,input().split())
h=list(map(int,input().split()))
sum=0
h.sort()
h=h[:n-k]
if n <= k:
print(0)
exit()
else:
for i in h:
sum += i
print(sum) | alphabet = 'abcdefghijklmnopqrstuvwxyz'
C = input()
print(alphabet[(alphabet.index(C)) + 1])
| 0 | null | 85,301,795,585,010 | 227 | 239 |
n, m = map(int, input().split())
ans = [0]*(n)
for i in range(m):
a = list(map(int, input().split()))
if n>=2:
if a[0] == 1:
if a[1] == 0:
print("-1")
exit()
a[0] -= 1
if ans[a[0]] == 0 or ans[a[0]] == a[1]:
ans[a[0]] = a[1]
else:
print("-1")
exit()
if n>=2:
for i in range(n):
if ans[0] == 0:
ans[0] = 1
print(ans[i],end="")
else:
print(ans[i],end="")
else:
print(ans[0])
| while True:
c = 0
n, x= map(int, input().split())
if n == 0 and x == 0:
break
for i in range(1, n + 1):
for j in range(1, n + 1 ):
if j <= i:
continue
for k in range(1, n + 1):
if k <= j:
continue
if i != j and i != k and j != k and i + j + k == x:
c += 1
print(c)
| 0 | null | 31,089,271,979,808 | 208 | 58 |
i = raw_input()
a, b = map(int, i.split())
print a * b, 2 * (a + b) | a,b,c=map(int,input().split(" "))
count=0
while(a<=b):
if c%a==0:
count+=1
a+=1
print(count)
| 0 | null | 439,455,138,720 | 36 | 44 |
n = int(input())
def count_ab(start, end):
l = len(str(n))
if start == 0:
return 0
if l == 1:
if start == end:
if n >= start:
return 1
else:
return 0
else:
return 0
else:
if start == end:
cnt = 1
else:
cnt = 0
if int(str(n)[0]) > start:
for i in range(1, l):
cnt += 10 ** i // 10
if int(str(n)[0]) == start:
for i in range(1, l - 1):
cnt += 10 ** i //10
cnt += int(str(n)[1:]) // 10
if int(str(n)[-1]) >= end:
cnt += 1
if int(str(n)[0]) < start:
for i in range(1, l - 1):
cnt += 10 ** i //10
return cnt
ans = 0
for i in range(10):
for j in range(10):
A = count_ab(i, j)
B = count_ab(j, i)
ans += A * B
print(ans) | import sys
def input():
return sys.stdin.readline().strip()
def main():
def make_factorial_table(n):
result = [0] * (n+1)
result[0] = 1
for i in range(1,n+1):
result[i] = result[i-1] * i % mod
return result
def nCr(n,r):
return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod
K = int(input())
S = input()
mod = 10 ** 9 + 7
n = len(S)
ans = 0
fact = make_factorial_table(n+K+1)
for i in range(K+1):
tmp = pow(25,i,mod)
tmp *= nCr(i+n-1,n-1)
tmp *= pow(26,K-i,mod)
ans += tmp
ans %= mod
print(ans)
if __name__ == "__main__":
main() | 0 | null | 49,509,519,626,202 | 234 | 124 |
N = list(map(int, "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".split(", ")))
n = int(input())
print(N[n-1]) |
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def acinput():
return list(map(int, input().split(" ")))
def II():
return int(input())
directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))
mod = 10**9+7
def factorial(n):
fact = 1
for integer in range(1, n + 1):
fact *= integer
return fact
def serch(x, count):
#print("top", x, count)
for d in directions:
nx = d+x
#print(nx)
if np.all(0 <= nx) and np.all(nx < (H, W)):
if field[nx[0]][nx[1]] == "E":
count += 1
field[nx[0]][nx[1]] = "V"
count = serch(nx, count)
continue
if field[nx[0]][nx[1]] == "#":
field[nx[0]][nx[1]] = "V"
count = serch(nx, count)
return count
K=int(input())
s = [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]
print(s[K-1])
| 1 | 50,122,337,635,712 | null | 195 | 195 |
def main():
N = int(input())
S = input()
ans = 0
for i in range(1000):
d0 = str(i % 10)
d1 = str((i // 10) % 10)
d2 = str((i // 100) % 10)
j = 0
found = False
while j < N:
if S[j] == d0:
found = True
j += 1
break
j += 1
if not found:
continue
found = False
while j < N:
if S[j] == d1:
found = True
j += 1
break
j += 1
if not found:
continue
found = False
while j < N:
if S[j] == d2:
found = True
j += 1
break
j += 1
if not found:
continue
if found:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| N = int(input())
S = str(input())
num = []
for _ in range(10):
num.append([])
for i in range(N):
num[int(S[i])].append(i)
ans = 0
for X1 in range(0, 10):
for X2 in range(0, 10):
for X3 in range(0, 10):
X = str(X1) + str(X2) + str(X3)
if num[X1] != [] and num[X2] != [] and num[X3] != []:
if num[X1][0] < num[X2][-1]:
for i in num[X2]:
if num[X1][0] < i < num[X3][-1]:
ans += 1
break
print(ans)
| 1 | 128,745,817,696,640 | null | 267 | 267 |
import math
def main():
X=int(input())
for a in range(-120,120):
flag=0
for b in range(-120,120):
if pow(a,5)-pow(b,5)==X:
print("{} {}".format(a,b))
flag=1
break
if flag==1:
break
if __name__=="__main__":
main()
| X=int(input())
def check():
for a in range(-200,200):
for b in range(-200,200):
if a**5-b**5==X:
print(a,b)
return 0
check() | 1 | 25,614,564,566,176 | null | 156 | 156 |
import math
a,b,deg = map(float,input().split(" "))
sindeg = math.sin(math.radians(deg))
S = (a*b*sindeg)/2
cosdeg = math.cos(math.radians(deg))
z = a*a + b*b - 2*a*b*cosdeg
L = a + b + math.sqrt(z)
h = b*sindeg
print("{:.5f}".format(S))
print("{:.5f}".format(L))
print("{:.5f}".format(h))
| H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans=float("inf")
counter=[[999]*W for _ in range(H)]
def search(i,j,count):
global ans
if counter[i][j]!=999:
ans=min(ans,count+counter[i][j])
return(counter[i][j])
dist=999
if i==H-1 and j==W-1:
ans=min(ans,count)
return 0
countj=count
counti=count
if j<W-1:
if S[i][j]=="." and S[i][j+1]=="#":
countj+=1
dist=search(i,j+1,countj) + (S[i][j]=="." and S[i][j+1]=="#")
if i<H-1:
if S[i][j]=="." and S[i+1][j]=="#":
counti+=1
dist=min(dist,search(i+1,j,counti)+(S[i][j]=="." and S[i+1][j]=="#"))
counter[i][j]=dist
return dist
search(0,0,(S[0][0]=="#")*1)
print(ans) | 0 | null | 24,873,952,676,820 | 30 | 194 |
N = int(input())
for i in range(1, 10):
if N % i == 0 and 1 <= N / i <= 9:
print('Yes')
exit()
print('No') | n=int(input())
s=input().split()
q=int(input())
t=input().split()
cnt=0
for i in range(q):
for j in range(n):
if s[j]==t[i]:
cnt+=1
break
print(cnt)
| 0 | null | 79,671,816,811,538 | 287 | 22 |
N=int(input())
K=set(input().split())
i=len(K)
if i==N:
print('YES')
else:
print('NO') | N = int(input())
A = list(map(int, input().split()))
A_set = set(A)
if len(A) == len(A_set):
print('YES')
else:
print('NO') | 1 | 73,649,387,349,472 | null | 222 | 222 |
n, m = map(int,input().split())
a = [[0]*m for i in range(n)]
b = [0]*m
for i in range(n):
a[i] = list(map(int,input().split()))
for j in range(m):
b[j] = int(input())
c = [0]*n
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
for i in c:
print(i)
| nm = list(map(int, input().split(" ")))
n = nm[0]
m = nm[1]
matrix_A = [list(map(int, input().split(" "))) for i in range(n)]
vector_b = [int(input()) for i in range(m)]
for i in range(n):
c_i = sum([matrix_A[i][j] * vector_b[j] for j in range(m)])
print(c_i) | 1 | 1,157,466,982,802 | null | 56 | 56 |
N = int(input())
i = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる
s = 0
for j in range(0,N,2):
if i[j] % 2 == 1 :
s += 1
print(s) | D, T, S=map(int, input().split())
if S*T-D>=0:print('Yes')
else:print('No') | 0 | null | 5,678,949,952,592 | 105 | 81 |
A = []
for _ in range(12):
A.append([0]*10)
n = int(input())
for _ in range(n):
b, f, r, v = map(int, input().split())
A[3*b-(3-f)-1][r-1] += v
for i in range(12):
print(' ', end='')
print(' '.join(map(str, A[i])))
if i in [2, 5, 8]:
print('#'*20)
| n=int(input())
s=input()+'*'
ans=0
for i in range(n):
if s[i]!=s[i+1]:
ans+=1
print(ans) | 0 | null | 85,348,531,473,790 | 55 | 293 |
# -*- coding: utf-8 -*-
def main():
from math import ceil
n = int(input())
count = 0
for i in range(1, ceil(n / 2)):
j = n - i
if i != j:
count += 1
print(count)
if __name__ == '__main__':
main()
| import sys
import fractions
input = sys.stdin.readline
mod = 10 ** 9 + 7
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))
lcm = 1
for a in A:
lcm = a // fractions.gcd(a, lcm) * lcm
ans = 0
for a in A:
ans += lcm // a
print(ans % mod) | 0 | null | 120,807,711,279,510 | 283 | 235 |
if __name__ == "__main__":
a,b,c = map(int,input().split())
count = 0
for i in range(a,b+1):
if c % i == 0:
count += 1
print("%d"%(count)) | a = int(input())
b = input().split()
c = "APPROVED"
for i in range(a):
if int(b[i]) % 2 == 0:
if int(b[i]) % 3 == 0 or int(b[i]) % 5 == 0:
c = "APPROVED"
else:
c = "DENIED"
break
print(c) | 0 | null | 34,713,606,966,390 | 44 | 217 |
n=int(input())
flag=0
for i in range(n):
a=list(map(int,input().split()))
if a[0]==a[1]:
flag+=1
else:
flag=0
if flag==3:
break
if flag==3:
print("Yes")
else:
print("No") | n = int(input())
z = []
cnt = 0
for _ in range(n):
a, b = map(int, input().split())
if a == b:
cnt += 1
else:
cnt = 0
if cnt == 3:
print('Yes')
exit()
print('No') | 1 | 2,488,762,797,544 | null | 72 | 72 |
from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,m = [int(x) for x in stdin.readline().rstrip().split()]
check = [0 for i in range(n)]
count = [0 for i in range(n)]
for i in range(m):
p, q = [x for x in stdin.readline().rstrip().split()]
p = int(p)
if q == 'AC':
check[p-1] = 1
if q == 'WA' and check[p-1] == 0:
count[p-1] = count[p-1] + 1
for i in range(n):
if check[i] == 0: count[i] = 0
print(sum(check), sum(count))
| n, m = map(int, input().split())
ps = [input().split() for i in range(m)]
b = [False] * n
wa = [0] * n
for i in ps:
if b[int(i[0])-1] == False and i[1] == "AC":
b[int(i[0])-1] = True
elif b[int(i[0])-1] == False and i[1] == "WA":
wa[int(i[0])-1] += 1
print(b.count(True),end=" ")
ans = 0
for i in range(n):
if b[i]:
ans += wa[i]
print(ans) | 1 | 93,168,227,106,610 | null | 240 | 240 |
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
A=list(map(float, input().split()))
low=0
high=10**9+1
while high-low!=1:
mid=(high+low)//2
cut_temp=0
ans=-1
for a in A:
cut_temp+=-(-a//mid)-1
if cut_temp>K:
low=mid
else:
high=mid
print(high) | N=int(input())
L=list(map(int,input().split()))
A=1
if 0 in L:
print(0)
exit()
for i in range(N):
A=A*L[i]
if 10**18<A:
print(-1)
exit()
if 10**18<A:
print(-1)
else:
print(A) | 0 | null | 11,293,346,531,908 | 99 | 134 |
n, m, l = list(map(lambda x: int(x), input().split(" ")))
A = list()
for i in range(n):
A.extend([list(map(lambda x: int(x), input().split(" ")))])
B = list()
for i in range(m):
B.extend([list(map(lambda x: int(x), input().split(" ")))])
C = list([[0 for l_ in range(l)]for n_ in range(n)])
for i in range(n):
for j in range(l):
for k in range(m):
C[i][j] += A[i][k] * B[k][j]
for a in C:
print("%d" % a[0], end="")
for b in a[1:]:
print(" %d" % b, end="")
print() | while True:
h, w =map(int,input().split())
odd = '#.'*300
even = '.#'*300
if h == 0 and w==0:
break
for i in range(h):
if i%2 ==0:
out = odd[:w]
else:
out= even[:w]
print(out)
print() | 0 | null | 1,144,191,754,592 | 60 | 51 |
X=int(input())
div=X//100
mod=X%100
print(1 if 5*div>=mod else 0) | x = int(input())
n = x//100
if x%100 <= 5*n:
print(1)
else:
print(0) | 1 | 126,951,927,919,960 | null | 266 | 266 |
L = int(input())
x = L/3
y = L/3
z = L - x - y
print(x*y*z) | import itertools
import functools
import math
from collections import Counter
from itertools import combinations
L = int(input())
ans=(L/3)**3
print(ans)
| 1 | 47,018,385,097,398 | null | 191 | 191 |
# -*- coding: utf-8 -*-
S = input()
if 'RRR' in S:
print("3")
elif 'RR' in S:
print("2")
elif 'R' in S:
print("1")
else:
print("0") | even,odd = map(int, input().split())
print(int(even * (even-1)/2 + odd * (odd-1)/2))
| 0 | null | 25,050,078,504,036 | 90 | 189 |
import math
a,b,h,m=map(int,input().split())
print((a**2+b**2-2*a*b*math.cos(math.pi*(m*11/360-h/6)))**0.5) | N,X,T=map(int,input().split())
if N%X==0:
print(N//X*T)
else:
print((N//X+1)*T)
| 0 | null | 12,192,969,028,080 | 144 | 86 |
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
s_l = []
for i in range(q):
s = list(map(int, input().split()))
s_l.append(s)
A = []
for v in combinations_with_replacement(range(1,m+1), n):
A.append(v)
ans = 0
for a in A:
cnt = 0
for i in range(q):
if a[s_l[i][1] - 1] - a[s_l[i][0] - 1] == s_l[i][2]:
cnt += s_l[i][3]
ans = max(ans, cnt)
print(ans) | N, M, Q = map(int, input().split())
a = [0 for _ in range(Q)]
b = [0 for _ in range(Q)]
c = [0 for _ in range(Q)]
d = [0 for _ in range(Q)]
for k in range(Q):
a[k], b[k], c[k], d[k] = map(int, input().split())
A = [1 for _ in range(N)]
def point(A):
p = 0
for ai, bi, ci, di in zip(a, b, c, d):
if A[bi-1] - A[ai-1] == ci:
p += di
return p
def next(A):
k = 1
while k < N+1:
if A[-k] < M:
A[-k] += 1
return A
break
else:
for j in range(1, k+1):
A[-j] = A[-k-1] + 1
k += 1
ans = point([M for _ in range(N)])
while A[0] < M:
ans = max(ans, point(A))
A = next(A)
print(ans) | 1 | 27,654,930,049,472 | null | 160 | 160 |
m1,_ = input().split()
m2,_ = input().split()
ans = 0
if m1 != m2:
ans = 1
print(ans) | m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
if d1 == 31:
print("1")
elif d1 == 30 and d2 == 1:
print("1")
elif d1 == 28 and m1 == 2:
print("1")
else:
print("0") | 1 | 124,542,552,338,246 | null | 264 | 264 |
S = input()
ans = ""
for s in range(len(S)):
if S[s] == "?":
print("D", end="")
else:
print(S[s], end="")
print("") | n, k = map(int, input().split())
p = sorted(list(map(int, input().split())))
a = 0
for i in range(k):
a += p[i]
print(a)
| 0 | null | 15,057,949,625,030 | 140 | 120 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit
INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def mapline(t = int):
return map(t, sysread().split())
def mapread(t = int):
return map(t, read().split())
def run():
N, *A = mapread()
dp = [defaultdict(lambda:0) for _ in range(N+1)]
dp[0][(0,0,0)] = 1
for i in range(N):
a = A[i]
k = i + 1
for key in dp[k-1].keys():
for ii, v in enumerate(key):
if v == a:
tmp = list(key)
tmp[ii] += 1
dp[k][tuple(tmp)] += dp[k-1][key] % mod
ans = 0
for key in dp[N].keys():
ans = (ans + dp[N][key]) % mod
#print(dp)
print(ans)
if __name__ == "__main__":
run()
| N = int(input())
A = list(map(int, input().split()))
mod = int(1e9+7)
CNT = [0] * (N+10)
CNT[-1] = 3
ans = 1
for a in A:
CNT[a] += 1
ans *= CNT[a-1]
ans %= mod
CNT[a-1] -= 1
print(ans) | 1 | 129,755,258,334,300 | null | 268 | 268 |
n, m, x = map(int, input().split())
book = [list(map(int, input().split())) for i in range(n)]
min_num = 10**18
for i in range(1<<n):
cost = 0
l = [0]*m
for j in range(n):
if (i>>j)&1:
c, *a = book[j]
cost += c
for k ,ak in enumerate(a):
l[k] += ak
if all(lj >= x for lj in l):
min_num = min(min_num,cost)
print(-1 if min_num == 10**18 else min_num)
| n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(n)]
ans=float('inf')
for i in range(2**n):
data=[0]*(m+1)
for j in range(n):
if i&(1<<j):
for k in range(m+1):
data[k]+=c[j][k]
cnt=0
for l in range(1,m+1):
if data[l]>=x:
cnt+=1
if cnt==m:
ans=min(ans,data[0])
if ans==float('inf'):
print(-1)
exit()
print(ans) | 1 | 22,324,170,081,990 | null | 149 | 149 |
import queue
K = int(input())
q = queue.Queue()
for i in range(1, 10):
q.put(i)
for _ in range(K):
x = q.get()
r = x%10
y = 10*x+r
if r != 0: q.put(y-1)
q.put(y)
if r != 9: q.put(y+1)
print(x) | def s_print(s, line):
a, b = map(int, line.split()[1:])
print(s[a:b + 1])
return s
def s_reverse(s, line):
a, b = map(int, line.split()[1:])
return s[:a] + s[a:b + 1][::-1] + s[b + 1:]
def s_replace(s, line):
ls = line.split()
a, b = map(int, ls[1:3])
rep = ls[-1]
return s[:a] + rep + s[b + 1:]
func_dict = {'pri': s_print, 'rev': s_reverse, 'rep': s_replace}
s, q = input(), int(input())
while q:
line = input()
s = func_dict[line[:3]](s, line)
q -= 1 | 0 | null | 20,883,607,599,228 | 181 | 68 |
x, n = map(int,input().split())
l = list(map(int,input().split()))
a = 0
ab = 0
for i in range(100):
if x - i not in l:
ans = x - i
a = i + 1
break
for i in range(100):
if x + i not in l:
ansb = x + i
ab = i + 1
break
if a > ab:
print(ansb)
else:
print(ans)
| N=int(input())
num = 7
i=1
a=[]
prir1=1
while i<=N:
xx=num%N
if xx==0:
print(i)
prir1=0
break
num=10*xx+7
i+=1
if prir1:
print(-1) | 0 | null | 10,140,288,824,420 | 128 | 97 |
def main():
n = int(input())
l = list(map(int, input().split()))
if 0 in l:
print(0)
return
prod = 1
for i in l:
prod *= i
if prod > 1000000000000000000:
print(-1)
return
print(prod)
if __name__ == '__main__':
main() |
a,b,c,d = map(int, input().split())
if a*b <= 0 and c*d <= 0:
print(max([a*c, b*d]))
elif a*b <= 0 and c >= 0:
print(b*d)
elif a*b <=0 and d <=0:
print(a*c)
elif a>=0 and c*d<=0:
print(b*d)
elif a>=0 and c>=0:
print(b*d)
elif a>=0 and d<=0:
print(a*d)
elif b<=0 and c*d<=0:
print(a*c)
elif b<=0 and c>=0:
print(b*c)
elif b<=0 and d<=0:
print(a*c) | 0 | null | 9,647,009,347,690 | 134 | 77 |
N, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
s = 0
for i in h:
if i >= k:
s += 1
print(s) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
a = sorted(inpl())
ng = 10**9+1
ok = -1
def sol(x):
cnt = 0
for i,t in enumerate(a):
tmp = x - t
c = bisect.bisect_left(a,tmp)
cnt += n-c
return True if cnt >= m else False
while ng-ok > 1:
mid = (ng+ok)//2
if sol(mid):
ok = mid
else: ng = mid
# print(ok,ng)
# print(ok)
res = 0
cnt = 0
revc = [0]
for i in range(n)[::-1]:
revc.append(revc[-1] + a[i])
# print(revc)
for i in range(n):
j = n-bisect.bisect_left(a,ok-a[i])
res += j*a[i] + revc[j]
cnt += j
res -= (cnt-m) * ok
print(res) | 0 | null | 143,350,673,921,812 | 298 | 252 |
A, B = map(int, input().split())
# floor(1009*0.1)=100 かつ floor(1010*0.1)=101 より、1から1009までの数字を調べればよい
ans = '-1'
for i in range(1010)[::-1]:
if i*8 // 100 == A and i // 10 == B:
ans = i
print(ans)
| import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
a_sum =[0]
b_sum=[0]
for i in range(n):
a_sum.append(a_sum[-1]+ a_list[i])
for i in range(m):
b_sum.append(b_sum[-1] + b_list[i])
#print(a_sum, b_sum)
total = 0
num = m
for i in range(n+1):
if a_sum[i] > k:
break
while (k - a_sum[i]) < b_sum[num]:
num -=1
#print(i, num)
if num == -1:
break
total = max(i+num, total)
print(total) | 0 | null | 33,662,046,722,820 | 203 | 117 |
import itertools
N = int(input())
l = []
kyori = []
for _ in range(N):
xy = list(map(int, input().split()))
l.append(xy)
for i in itertools.combinations(l,2):
t = ((i[0][0]-i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5
kyori.append(t)
print((N-1)*sum(kyori)/len(kyori)) | def main():
C = input()
ans = chr(ord(C) + 1)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 120,129,585,504,830 | 280 | 239 |
#!/usr/bin/env python3
# input
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n):
p[i] -= 1
# calc
ans = -int(1e18)
for si in range(n):
x = si
s = []
opscore = 0
while True:
x = p[x]
opscore += c[x]
s.append(c[x])
if x == si:
break
oplen = len(s)
t = 0
for i in range(oplen):
t += s[i]
if i+1 > k:
break
now = t
if opscore > 0:
e = (k-(i+1))//oplen
now += opscore * e
ans = max(ans, now)
print(ans)
| INF = float("inf")
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -INF
for s in range(N):
### STEP1
cum = []
i = P[s] - 1 #s-> i
cum.append(C[i])
while i != s:
i = P[i] - 1
cum.append(cum[-1] + C[i])
# STEP2
if K <= len(cum):
#1週未満しかできない
score = max(cum[:K])
elif cum[-1] <= 0:
#一周以上できるが、ループしたら損する場合
score = max(cum)
else:
# K//Length - 1回だけループし、最後は最適に止まる
score1 = cum[-1] * (K//len(cum) - 1)
score1 += max(cum)
#ループをK//length回だけループする場合
score2 = cum[-1]*(K//len(cum))
resi = K % len(cum) #残り進める回数
if resi != 0:
#まだ進めるなら
score2 += max(0, max(cum[:resi]))
score = max(score1, score2)
ans = max(ans, score)
print(ans)
| 1 | 5,324,456,282,158 | null | 93 | 93 |
a = input()
s = list(a)
for i in range(len(s)):
if (a[i] == '?'):
s[i] = 'D'
s = "".join(s)
print(s)
| x = int(input())
balance = 100
cnt = 0
while balance < x:
balance += int(balance//100)
cnt += 1
print(cnt) | 0 | null | 22,910,813,661,298 | 140 | 159 |
from sys import stdin, stdout
s = input()
n = len(s)
P = 2019
# suffix_rems is a list of remainders obtained by dividing the suffix starting at i with P. suffix[i] = s[i:]%P.
suffix_rems = [-1]*n
suffix_rems[-1] = int(s[-1])%P
# Stores the frequency of remainders obtained. We just want number of (i, j) pairs.
rems_d = dict()
rems_d[0] = 1
rems_d[int(s[-1])] = 1
# Those remainders which occur more than once. To pick (i, j) pairs from N, we need N > 1.
special_keys = set()
for i in range(n-1)[::-1]:
rem = (pow(10, n-i-1, P) * int(s[i]) + suffix_rems[i + 1])%P
if rem in rems_d:
rems_d[rem] += 1
special_keys.add(rem)
else:
rems_d[rem] = 1
suffix_rems[i] = rem
ans = 0
for key in special_keys:
t = rems_d[key]
# pick any two of those same remainder indices.
ans += (t*(t-1))//2
print(ans) | import collections
from math import factorial
def permutations_count(n, r):
''' 順列 '''
return factorial(n) // factorial(n - r)
def combinations_count(n, r):
''' 組み合わせ '''
return factorial(n) // (factorial(n - r) * factorial(r))
S = input()
lis = []
amari = 1
lis.append(int(S[-1]))
for i in range(2,len(S)+1):
amari = (amari * 10) % 2019
lis.append((int(S[-1*i]) * amari + lis[i-2]) % 2019)
c = collections.Counter(lis)
su = 0
for k in c:
if c[k] > 1:
su += combinations_count(c[k], 2)
su += c[0]
print(su) | 1 | 30,973,446,416,000 | null | 166 | 166 |
a,b,c = map(int, input().split())
X = c
Y = a
Z = b
print (X,Y,Z) | #!/usr/bin/env python3
import sys
import collections as cl
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 main():
a, b, c = MI()
print(c, a, b, sep=" ")
main()
| 1 | 38,070,604,180,112 | null | 178 | 178 |
# -*- coding: utf-8 -*-
from collections import deque
import sys
COMMAND = ("insert", "delete", "deleteFirst", "deleteLast")
if __name__ == "__main__":
n = int(sys.stdin.readline())
ans = deque()
inp = sys.stdin.readlines()
for i in range(n):
com = inp[i].split()
if com[0] == COMMAND[0]:
ans.appendleft(com[1])
elif com[0] == COMMAND[1]:
if com[1] in ans:
ans.remove(com[1])
elif com[0] == COMMAND[2]:
ans.popleft()
elif com[0] == COMMAND[3]:
ans.pop()
print(" ".join(ans)) | N = int(input())
a = list(map(int, input().split()))
b = []
j = N-1
while j > 0:
print("{} ".format(a[j]),end = "")
j -= 1
print(a[j]) | 0 | null | 510,754,748,910 | 20 | 53 |
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
min_S = S
sum_B = 0
for i in range(N):
sum_B += A[i]
min_S = min(min_S, abs(sum_B - (S - sum_B)))
print(min_S) | #-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np
def main():
N=[]
n = int(input())
N=np.array(list(map(int,input().split())))
Ncum=N.cumsum()
L=Ncum[:-1]
R=Ncum[-1]-L
ans=np.abs(L-R).min()
print(ans)
if __name__=="__main__":
main() | 1 | 142,101,748,221,732 | null | 276 | 276 |
import collections
s = str(input())
k = int(input())
ans = 0
#if s[0] == s[-1]:
# ans += k
tmp = ''
tmp_num = 0
check = ''
check_num = 0
if len(collections.Counter(s).keys()) == 1:
ans = len(s)*k//2
else:
for i, w in enumerate(s):
if i == 0:
tmp += w
tmp_num += 1
continue
if tmp[-1] == w:
tmp += w
tmp_num += 1
elif tmp[-1] != w:
if check_num == 0:
check = tmp
check_num = 1
ans += (tmp_num // 2) * k
#print('ans', ans)
tmp = w
tmp_num = 1
if i == len(s)-1:
if len(tmp) == 1:
if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
ans += k-1
else:
#print(check, tmp)
if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
ans += k-1
ans += (tmp_num // 2) * k
#print('last', ans)
print(ans)
| s = input()
k = int(input())
li = list(s)
lee = len(s)
if len(list(set(li))) == 1:
print((lee)*k//2)
exit()
def motome(n,list):
count = 0
kaihi_flag = False
li = list*n
for i,l in enumerate(li):
if i == 0:
continue
if l == li[i-1] and not kaihi_flag:
count += 1
kaihi_flag = True
else:
kaihi_flag = False
#print(count)
#print(count*k)
return count
if k >= 5 and k%2 == 1:
a = motome(3,li)
b = motome(5,li)
diff = b - a
ans = b + (k-5)//2*diff
print(ans)
elif k >=5 and k%2 == 0:
a = motome(2,li)
b = motome(4,li)
diff = b - a
ans = b + (k-4)//2*diff
print(ans)
else:
count = 0
kaihi_flag = False
li = li*k
for i,l in enumerate(li):
if i == 0:
continue
if l == li[i-1] and not kaihi_flag:
count += 1
kaihi_flag = True
else:
kaihi_flag = False
#print(count)
#print(count*k)
print(count)
| 1 | 175,844,522,672,780 | null | 296 | 296 |
# -*- coding: utf-8 -*-
S = [0] * 13
H = [0] * 13
C = [0] * 13
D = [0] * 13
n = int(raw_input())
for i in xrange(n):
symbol, num = map(str, raw_input().split())
if symbol == 'S':
S[int(num)-1] = 1
elif symbol == 'H':
H[int(num)-1] = 1
elif symbol == 'C':
C[int(num)-1] = 1
else:
D[int(num)-1] = 1
cards = [S, H, C, D]
marks = ['S', 'H', 'C', 'D']
for card, mark in zip(cards, marks):
for index, num in enumerate(card):
if num < 1:
print mark, index+1 | cards = {
'S': [0 for _ in range(13)],
'H': [0 for _ in range(13)],
'C': [0 for _ in range(13)],
'D': [0 for _ in range(13)],
}
n = int(input())
for _ in range(n):
(s, r) = input().split()
cards[s][int(r) - 1] = 1
for s in ('S', 'H', 'C', 'D'):
for r in range(13):
if cards[s][r] == 0:
print(s, r + 1) | 1 | 1,034,342,499,516 | null | 54 | 54 |
class Dice(object):
"""Dice Class
"""
def __init__(self, numbers):
"""
Args:
numbers:
"""
self.numbers = {1: numbers[0], 2: numbers[1], 3: numbers[2], 4: numbers[3], 5: numbers[4], 6: numbers[5]}
self.vertical = [self.numbers[1], self.numbers[2], self.numbers[6], self.numbers[5]]
self.horizontal = [self.numbers[4], self.numbers[1], self.numbers[3], self.numbers[6]]
def move_dice(self, s):
"""
Args:
s: move direction
Returns:
"""
if s == 'N':
self.move_north()
elif s == 'S':
self.move_south()
elif s == 'W':
self.move_west()
elif s == 'E':
self.move_east()
def move_south(self):
"""move this dice towered north
"""
self.vertical = (self.vertical * 2)[3:7]
self.horizontal[1] = self.vertical[0]
self.horizontal[3] = self.vertical[2]
def move_north(self):
"""move this dice towered south
"""
self.vertical = (self.vertical * 2)[1:5]
self.horizontal[1] = self.vertical[0]
self.horizontal[3] = self.vertical[2]
def move_east(self):
"""move this dice towered east
"""
self.horizontal = (self.horizontal * 2)[3:7]
self.vertical[0] = self.horizontal[1]
self.vertical[2] = self.horizontal[3]
def move_west(self):
"""move this dice towered west
"""
self.horizontal = (self.horizontal * 2)[1:5]
self.vertical[0] = self.horizontal[1]
self.vertical[2] = self.horizontal[3]
def get_top(self):
return self.vertical[0]
numbers = [int(x) for x in raw_input().split()]
dice1 = Dice(numbers=numbers)
for s in raw_input():
dice1.move_dice(s)
print(dice1.get_top()) | from collections import defaultdict
from collections import deque
from collections import Counter
import math
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n,k = readInts()
a = readInts()
a.sort(reverse=True)
if n==1:
print(math.ceil(a[0]/(k+1)))
exit()
def get(left, right):
l = (right-left)//2+left
ans = 0
for i in a:
ans+=math.ceil(i/l)-1
#print(l, ans, left, right)
return ans,l
def nibu(left,right):
ans,l = get(left, right)
if left<right:
if ans<=k:
return nibu(left,l)
else:
return nibu(l+1, right)
else:
return right
print(nibu(1,a[0]))
| 0 | null | 3,369,733,632,898 | 33 | 99 |