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
|
---|---|---|---|---|---|---|
def mergeArray(a,b,bLength,c,cLength):
global count
apos,bpos,cpos=(0,0,0)
while bpos<bLength and cpos<cLength:
if b[bpos]<=c[cpos]:
a[apos]=b[bpos]
bpos+=1
else:
a[apos]=c[cpos]
cpos+=1
apos+=1
count+=1
while bpos<bLength:
a[apos]=b[bpos]
apos+=1
bpos+=1
count+=1
while cpos<cLength:
a[apos]=c[cpos]
apos+=1
cpos+=1
count+=1
def mergeSort(a,aLength):
b=[]
c=[]
if aLength>=2:
b=a[:aLength//2]
c=a[aLength//2:]
mergeSort(b,len(b))
mergeSort(c,len(c))
mergeArray(a,b,len(b),c,len(c))
count=0
aLength=int(input())
a=list(map(int,input().split()))
mergeSort(a,aLength)
print(*a)
print(count)
| def merge(a, left, mid, right):
global count
l = a[left:mid] + [sentinel]
r = a[mid:right] + [sentinel]
i = j = 0
for k in range(left, right):
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
count += right - left
def merge_sort(a, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(a, left, mid)
merge_sort(a, mid, right)
merge(a, left, mid, right)
sentinel = 10 ** 9 + 1
n = int(input())
a = list(map(int, input().split()))
count = 0
merge_sort(a, 0, len(a))
print(*a)
print(count) | 1 | 111,563,704,188 | null | 26 | 26 |
int=input()
int=int**3
print int | input_line = input()
input_line_cubic = input_line ** 3
print input_line_cubic | 1 | 281,089,861,860 | null | 35 | 35 |
a=list(map(int, input().split(' ')))
# ่ตทใใฆใๆ้๏ผๅ๏ผใฎ่จ็ฎ
h=a[2]-a[0]
m=a[3]-a[1]
mt=h*60+m
# ๆ้ใฎ่กจ็คบ
print(mt-a[4]) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
H1, M1, H2, M2, K = mapint()
if M2>=M1:
minutes = (H2-H1)*60
minutes += M2-M1
else:
minutes = (H2-H1-1)*60
minutes += M2-M1+60
print(max(0, minutes-K))
| 1 | 18,253,418,829,588 | null | 139 | 139 |
import bisect
n, d, a = map(int, input().split())
fox = [None]*n
for i in range(n):
x, h = map(int, input().split())
fox[i] = (x, h)
fox.sort()
x = [int(fox[i][0]) for i in range(n)]
h = [int(fox[i][1]) for i in range(n)]
ans = 0
bit = [0]*n
for i in range(n):
if i != 0:
bit[i] += bit[i-1]
if bit[i] >= h[i]:
continue
sub = (h[i]-bit[i]-1)//a+1
ans += sub
bit[i] += sub*a
index = bisect.bisect_right(x, x[i]+2*d)
if index == n:
continue
bit[index] -= sub*a
print(ans) | X=int(input())
C=X//500
c=(X-X//500*500)//5
print(C*1000+c*5) | 0 | null | 62,254,306,291,030 | 230 | 185 |
S, T = [input() for x in range(2)]
lenT = len(T)
max_match_len = 0
for i in range(len(S)-lenT+1):
compareS = S[i:i+lenT]
match_len = 0
for j in range(lenT):
if compareS[j] == T[j]:
match_len += 1
else:
if max_match_len < match_len:
max_match_len = match_len
print(lenT - max_match_len)
| MOD = 10 ** 9 + 7
n, k = map(int, input().split())
alst = list(map(int, input().split()))
alst.sort()
if n == k:
ans = 1
for num in alst:
ans *= num
ans %= MOD
print(ans)
exit()
if k == 1:
print(alst[-1] % MOD)
exit()
if alst[0] >= 0:
ans = 1
alst.sort(reverse = True)
for i in range(k):
ans *= alst[i]
ans %= MOD
print(ans)
exit()
if alst[-1] <= 0:
ans = 1
if k % 2 == 1:
alst = alst[::-1]
for i in range(k):
ans *= alst[i]
ans %= MOD
print(ans)
exit()
blst = []
for num in alst:
try:
blst.append([abs(num), abs(num) // num])
except ZeroDivisionError:
blst.append([abs(num), 0])
blst.sort(reverse = True,key = lambda x:x[0])
if blst[k - 1] == 0:
print(0)
exit()
minus = 0
last_minus = 0
last_plus = 0
ans_lst = []
for i in range(k):
if blst[i][1] == -1:
minus += 1
last_minus = blst[i][0]
elif blst[i][1] == 1:
last_plus = blst[i][0]
else:
print(0)
exit()
ans_lst.append(blst[i][0])
next_minus = 0
next_plus = 0
flg_minus = False
flg_plus = False
for i in range(k, n):
if blst[i][1] == -1 and (not flg_minus):
next_minus = blst[i][0]
flg_minus = True
if blst[i][1] == 1 and (not flg_plus):
next_plus = blst[i][0]
flg_plus = True
if (flg_plus and flg_minus) or blst[i][1] == 0:
break
if minus % 2 == 0:
ans = 1
for num in ans_lst:
ans *= num
ans %= MOD
print(ans)
else:
minus_s = last_minus * next_minus
plus_s = last_plus * next_plus
ans = 1
if minus == k:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
elif minus_s == plus_s == 0:
if next_minus == 0:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
else:
print(0)
exit()
elif minus_s > plus_s:
ans_lst.remove(last_plus)
ans_lst.append(next_minus)
else:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
for num in ans_lst:
ans *= num
ans %= MOD
print(ans)
| 0 | null | 6,505,917,816,292 | 82 | 112 |
s = input()
if(len(s)==0):
print("")
if(s[-1] == "s"):
print(s+"es")
if(s[-1] != "s"):
print(s+"s") | num = int(input())
if num%2==0:
print((num//2) / num)
else:
print(((num//2)+1) / num) | 0 | null | 89,490,555,159,840 | 71 | 297 |
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
p_1 = sum([abs(x[i]-y[i]) for i in range(n)])
p_2 = (sum([(x[i]-y[i])**2 for i in range(n)]))**0.5
p_3 = (sum([(abs(x[i]-y[i]))**3 for i in range(n)]))**(1/3)
p_inf = max([abs(x[i]-y[i]) for i in range(n)])
print("{:.5f}".format(p_1))
print("{:.5f}".format(p_2))
print("{:.5f}".format(p_3))
print("{:.5f}".format(p_inf)) | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s = input()
if 'a' <= s and s <= 'z':
print("a")
else:
print("A")
if __name__=='__main__':
main() | 0 | null | 5,746,788,579,540 | 32 | 119 |
def main():
a, b, c, d = map(int, input().split())
print(max(a*c, a*d, b*c, b*d))
if __name__ == "__main__":
main() | r = input()
p = 3.141592653589
print "%.6f %.6f" % (p*r*r,2*p*r) | 0 | null | 1,852,153,779,940 | 77 | 46 |
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # value of pre & cycle
sum_p = 0 # sum of pre + cycle
X = [False] * m # for cycle check
for _ in range(mn):
if X[x]: break
X[x] = True
P.append(x)
sum_p += x
x = x*x % m
if len(P) >= mn:
print(sum_p)
exit()
pre_len = P.index(x)
cyc_len = len(P) - pre_len
nxt_len = (n - pre_len) % cyc_len
cyc_num = (n - pre_len) // cyc_len
cyc = sum(P[pre_len:])
remain = sum(P[:pre_len + nxt_len])
print(cyc * cyc_num + remain)
|
def main(n,m,s):
#iๅๆๅ
i = n
tmp = []
while i > 0 :
for j in range(m,-1,-1):
if j == 0 :
i = -1
break
if i-j >= 0 :
if s[i-j] == '0':
i -= j
tmp.append(j)
break
if i == 0:
for l in reversed(tmp):
print(l,end=' ')
else:
print(-1)
n,m = map(int,input().split())
s = input()
main(n,m,s)
| 0 | null | 70,653,832,891,356 | 75 | 274 |
N = int(input().strip())
ans = ''
while N > 0:
ans = chr(ord('a') + (N-1) % 26) + ans
N = (N -1) // 26
print(ans)
| import collections
n,x,m=map(int,input().split())
if n==1 or x==0:
print(x)
exit()
start,end,loopcnt=0,0,0
a={x:0}
wk=x
for i in range(1,m):
wk=(wk*wk)%m
if not wk in a:
a[wk]=i
else:
start=a[wk]
end=i
break
a=sorted(a.items(),key=lambda x:x[1])
koteiindex=min(n,start)
koteiwa=0
for i in range(koteiindex):
koteiwa+=a[i][0]
loopcnt=(n-koteiindex)//(end-start)
loopindex=start-1+(n-koteiindex)%(end-start)
loopwa=0
amariwa=0
for i in range(start,end):
if i<=loopindex:
amariwa+=a[i][0]
loopwa+=a[i][0]
ans=koteiwa+loopwa*loopcnt+amariwa
print(ans)
| 0 | null | 7,355,100,131,730 | 121 | 75 |
print(len(set(input()))%2*'Yes'or'No') | i = input()
a,b,c = map(int, i.split())
s = set()
s.add(a)
s.add(b)
s.add(c)
if len(s) == 2:
print("Yes")
else:
print("No") | 1 | 68,141,073,420,530 | null | 216 | 216 |
beforex_plus_y=[]
beforex_minus_y=[]
for i in range(int(input())):
xy=list(map(int,input().split()))
beforex_plus_y.append(xy[0]+xy[1])
beforex_minus_y.append(xy[0]-xy[1])
print(max(max(beforex_plus_y)-min(beforex_plus_y),max(beforex_minus_y)-min(beforex_minus_y))) | n=int(input())
x=[0]*n
y=[0]*n
z=[]
w=[]
for i in range(n):
x[i],y[i]= list(map(int, input().strip().split()))
z.append(x[i]+y[i])
w.append(x[i]-y[i])
a=max(z)-min(z)
b=max(w)-min(w)
print(max(a,b)) | 1 | 3,397,725,296,800 | null | 80 | 80 |
n,a,b = list(map(int, input().split()))
if abs(b-a)%2==0:
print(abs(b-a)//2)
else:
#ๅ1ใซ่กใใณในใ
c1=max(a,b)-1
#ๅNใซ่กใใณในใ
c2=n-min(a,b)
ans=0
cost=min(c1,c2)
if c1<c2:
ans+=min(a,b)-1
else:
ans+=n-max(a,b)
cost-=ans
ans+=(cost+1)//2
print(ans) | n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
print(-(-(b - a) // 2))
else:
print(min(a - 1 + -(-(b - a + 1) // 2), n - b + -(-(b - a) // 2))) | 1 | 108,802,330,581,070 | null | 253 | 253 |
k = int(input())
a = 7 % k
count = 1
for i in range(1,k+1):
if a == 0:
print(count)
break
else:
a = (10 * a + 7) % k
count += 1
if i == k:
print(-1) | n,k=map(int,input().split())
a=[int(i) for i in input().split()]
w=[1]
x=set([1])
for i in range(k):
t=a[w[-1]-1]
if t in x: break
x.add(t)
w.append(t)
p=w.index(t)
if p==0:
print(w[k%len(w)])
else:#l 2,5,3
p=w.index(t)
k-=p
loop=len(w)-p
print(w[p+k%loop])
| 0 | null | 14,436,439,172,598 | 97 | 150 |
n, m = map(int, raw_input().split())
A = {}
for i in range(n):
temp = map(int, raw_input().split())
for j in range(m):
A[(i,j)] = temp[j]
b = {}
for j in range(m):
b[(j)] = input()
c = {}
for i in range(n):
c[(i)] = 0
for j in range(m):
c[(i)] += A[(i,j)] * b[(j)]
for i in range(n):
print c[(i)] | 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]
k = int(input())
print(s[k-1])
| 0 | null | 25,603,039,247,910 | 56 | 195 |
ans = 0
for i in xrange(input()):
n = int(raw_input())
if n <= 1:
continue
j = 2
while j*j <= n:
if n%j == 0:
break
j += 1
else:
ans += 1
print ans | N = int(input())
ans = 0
for i in range(1, N+1):
if i % 3 == 0:
continue
if i % 5 == 0:
continue
ans += i
print(ans)
| 0 | null | 17,324,877,758,220 | 12 | 173 |
# coding: utf-8
N = int(input())
_A = sorted(enumerate(map(int, input().split()), 1), key=lambda x:x[1], reverse=True)
dp = [[0] * (N+1) for i in range(N+1)]
for i in range(1,N+1):
k, Ak = _A[i-1]
if (N-i-k) < 0:break
dp[0][i] = dp[0][i-1] + (N-i+1-k) * Ak
for i in range(1,N+1):
k, Ak = _A[i-1]
if (k-i) < 0:break
dp[i][0] = dp[i-1][0] + (k-i) * Ak
for x in range(1, N+1):
for y in range(1, N-x+1):
k, val = _A[x+y-1]
dp[x][y]= max(dp[x-1][y] + abs(k-x)*val,
dp[x][y-1] + abs(N-y-k+1) * val)
print(int(max(dp[i][N-i] for i in range(N+1))))
| n = int(input())
a = [(int(x), i+1) for i, x in enumerate(input().split())]
a = sorted(a, reverse=True)
dp = [[0]*(n+1) for __ in range(n+1)]
for k in range(1, n+1):
child = a[k-1][0]
ind = a[k-1][1]
for i in range(k+1):
if i != 0:
dp[i][k-i] = dp[i-1][k-i] + child*(ind-i)
if k-i != 0:
dp[i][k-i] = max(dp[i][k-i], dp[i][k-i-1] + child*((n+1-(k-i))-ind))
ans = 0
for i in range(n+1):
ans = max(ans, dp[i][n-i])
print(ans) | 1 | 33,806,991,588,992 | null | 171 | 171 |
def popcount(x):
return bin(x).count("1")
n=int(input())
x=input()
num=int(x,2)
cnt=popcount(num)
A=[]
for i in range(n):
number=num
if x[i]=="1" and cnt==1:A.append(-1)
elif x[i]=="1":
number %=cnt-1
A.append((number-pow(2,n-i-1,cnt-1))%(cnt-1))
else:
number %=cnt+1
A.append((number+pow(2,n-i-1,cnt+1))%(cnt+1))
for i in A:
ans=i
if ans==-1:print(0)
else:
point=1
while ans!=0:
ans %=popcount(ans)
point +=1
print(point) | N=int(input())
x=input()
num=0
n=0
def twice(a):
ans=0
while a:
ans+=a%2
a//=2
return ans
ma=5*10**5
dp=[0]*ma
for i in range(1,ma):
dp[i]=dp[i%twice(i)]+1
c=x.count("1")
a=int(x,2)%(c+1)
if c==1:
for i in range(N):
if x[i]=="0":
print(dp[(a+pow(2,N-i-1,2))%2]+1)
else:
print(0)
exit()
b=int(x,2)%(c-1)
for i in range(N):
if x[i]=="0":
print(dp[(a+pow(2,N-i-1,c+1))%(c+1)]+1)
else:
print(dp[(b-pow(2,N-i-1,c-1))%(c-1)]+1) | 1 | 8,234,598,307,740 | null | 107 | 107 |
t = int(input())
h = int(t/3600)
m = int(t%3600/60)
s = int(t%3600%60)
print(str(h) + ":" + str(m) + ":" + str(s)) | S = int(input())
h = S//(60*60)
m = (S%(60*60))//60
s = (S%(60*60))%60
print(h, ':', m, ':', s, sep='')
| 1 | 327,067,288,294 | null | 37 | 37 |
# A Station and Bus
S = input()
bef = S[0]
for s in S[1:]:
if s != bef:
print("Yes")
exit()
else:
bef = s
print("No") | n = int(input())
r = n // 2
a = n % 2
print(r + a) | 0 | null | 56,782,904,916,452 | 201 | 206 |
import sys
def div(x, y):
if x % y == 0:
print y
else:
div(y, x%y)
line = sys.stdin.readline()
x, y = line.split(" ")
x = int(x)
y = int(y)
if x < y:
x, y = y, x
if x == y:
print x
else:
div(x, y) | import sys
input = sys.stdin.readline
def main():
S = input().rstrip()
ans = S[:3]
print(ans)
if __name__ == "__main__":
main() | 0 | null | 7,434,983,786,726 | 11 | 130 |
import math
import collections
import fractions
import itertools
import functools
import operator
import numpy as np
def solve():
h, w = map(int, input().split())
maze = [input() for _ in range(h)]
ans = 0
can_move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for x in range(h):
for y in range(w):
if maze[x][y] == "#":
continue
dist = [[0]*w for _ in range(h)]
stack = collections.deque()
stack.append([x,y])
while stack:
h2, w2 = stack.popleft()
for i, j in can_move:
newh, neww = h2+i, w2+j
if newh < 0 or neww < 0 or newh >= h or neww >= w:
continue
elif maze[newh][neww] != "#" and dist[newh][neww] == 0:
dist[newh][neww] = dist[h2][w2]+1
stack.append([newh, neww])
dist[x][y] = 0
ans = max(ans, np.max(dist))
print(ans)
return 0
if __name__ == "__main__":
solve() | from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
res = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
dist = [[-1] * w for _ in range(h)]
dist[i][j] = 0
d = deque()
d.append([i, j])
while d:
pos_x, pos_y = d.popleft()
dist_max = dist[pos_x][pos_y]
for k in range(4):
x, y = pos_x + dx[k], pos_y + dy[k]
if 0 <= x < h and 0 <= y < w and s[x][y] == "." and dist[x][y] == -1:
dist[x][y] = dist[pos_x][pos_y] + 1
d.append([x, y])
res = max(res, dist_max)
print(res) | 1 | 94,542,119,933,940 | null | 241 | 241 |
for i in range(1, 100000):
num = int(input())
if num == 0:
break
print('Case ' + str(i) + ':', num) | N = int(input())
S, T = input().split()
S_list = list(S)
T_list = list(T)
ans = ""
for i, j in zip(S_list, T_list):
ans += i + j
print(ans)
| 0 | null | 56,393,354,178,210 | 42 | 255 |
N = int(input())
if N % 2 == 1:
print(0)
exit()
res = 0
fives = 10
while True:
if N // fives == 0:
break
res += N//fives
fives *= 5
print(res) | import sys
input = sys.stdin.readline
def main():
N = int(input())
if N % 2 == 1:
print(0)
exit()
count = []
i = 0
while True:
q = N // (10 * 5 ** i)
if q == 0:
break
else:
count.append((q, i + 1))
i += 1
ans = 0
prev_c = 0
for c, n_zero in count[::-1]:
ans += n_zero * (c - prev_c)
prev_c = c
print(ans)
if __name__ == "__main__":
main()
| 1 | 116,232,051,045,012 | null | 258 | 258 |
import sys
while 1:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
else:
for h in range(0, H):
for w in range(0, W):
sys.stdout.write("#")
print ""
print "" | while True:
h,w = map(int,raw_input().split())
if h == 0 and w == 0:
break
for i in range(h):
print '#'*w
print '' | 1 | 787,505,843,258 | null | 49 | 49 |
W, H, x, y, r = [int(i) for i in input().split()]
if r <= y <= H - r and r <= x <= W - r:
print('Yes')
else:
print('No') | w, h, x, y, r = map(int, input().split())
if x - r < 0:
print('No')
elif x + r > w:
print('No')
elif y - r < 0:
print('No')
elif y + r > h:
print('No')
else:
print('Yes')
| 1 | 457,514,131,410 | null | 41 | 41 |
N, K = map(int, input().split(' '))
P = tuple(map(int, input().split(' ')))
values = [0]
for p in P:
values.append(values[-1] + (p * (p + 1) // 2 / p))
ans = 0
for i in range(K, N + 1):
ans = max(ans, values[i] - values[i - K])
print(ans)
| from itertools import accumulate
N, K = map(int, input().split())
P = [0]+list(map(int, input().split()))
Psum = list(accumulate(P))
total = 0
for i in range(K, N+1):
if Psum[i]-Psum[i-K] > total:
total = Psum[i]-Psum[i-K]
index = i
ans = 0
for i in range(index, index-K, -1):
ans += (P[i]+1)*0.5
print(ans)
| 1 | 74,992,512,059,458 | null | 223 | 223 |
from math import sin, cos, pi
def koch_curve(d, p1, p2):
if d == 0:
return
s = [None, None]
u = [None, None]
t = [None, None]
s[0] = (2*p1[0] + p2[0])/3
s[1] = (2*p1[1] + p2[1])/3
t[0] = (p1[0] + 2*p2[0])/3
t[1] = (p1[1] + 2*p2[1])/3
u[0] = (t[0] - s[0])*cos(1/3*pi) - (t[1] - s[1])*sin(1/3*pi) + s[0]
u[1] = (t[0] - s[0])*sin(1/3*pi) + (t[1] - s[1])*cos(1/3*pi) + s[1]
koch_curve(d-1, p1, s)
print(s[0], s[1])
koch_curve(d-1, s, u)
print(u[0], u[1])
koch_curve(d-1, u, t)
print(t[0],t[1])
koch_curve(d-1, t, p2)
num = int(input())
print(0.0, 0.0)
koch_curve(num, [0.0, 0.0], [100.0, 0.0])
print(100.0, 0.0)
| import math
class coordinate:
def __init__(self, x, y):
self.x = x
self.y = y
def koch(n, p1, p2):
if n == 0:
return str(p2.x) + " " + str(p2.y)
else:
s = coordinate((2*p1.x + p2.x)/3, (2*p1.y + p2.y)/3)
t = coordinate((p1.x + 2*p2.x)/3, (p1.y + 2*p2.y)/3)
u = coordinate((t.x-s.x)/2-(t.y-s.y)/2*math.sqrt(3)+s.x, (t.x-s.x)/2*math.sqrt(3)+(t.y-s.y)/2+s.y)
print(koch(n-1, p1, s))
print(koch(n-1, s, u))
print(koch(n-1, u, t))
return(koch(n-1, t, p2))
q1 = coordinate(0.00000000, 0.00000000)
q2 = coordinate(100.00000000, 0.00000000)
print(str(q1.x) + " " + str(q1.y))
print(koch(int(input()), q1, q2))
| 1 | 120,566,711,370 | null | 27 | 27 |
K = int(input())
S = input()
X = len(S)
mod = 10**9+7
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #ๅบๅใฎๅถ้
N = 2*10**6
g1 = [1, 1] # ๅ
ใใผใใซ
g2 = [1, 1] #้ๅ
ใใผใใซ
inverse = [0, 1] #้ๅ
ใใผใใซ่จ็ฎ็จใใผใใซ
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
def power(n, r, mod):
if r == 0: return 1
if r%2 == 0:
return power(n*n % mod, r//2, mod) % mod
if r%2 == 1:
return n * power(n, r-1, mod) % mod
A = 0
B = K
temp = cmb(A+X-1,X-1,mod)*power(25,A,mod)
temp %= mod
temp *= power(26,B,mod)
temp %= mod
ans = temp
for i in range(X+1,K+X+1):
temp *= 25
temp %= mod
temp *= pow(26, mod-2, mod)
temp %= mod
temp *= i-1
temp %= mod
temp *= pow(i-X, mod-2, mod)
temp %= mod
ans += temp
ans %= mod
print(ans) | s=list(map(int,input()))
c=0
cnt=[0]*2019
cnt[0]+=1
for k in range(len(s)-1,-1,-1):
c=(c+s[k]*pow(10,len(s)-1-k,2019))%2019
cnt[c]+=1
print(sum(x*(x-1)//2 for x in cnt)) | 0 | null | 21,952,258,447,420 | 124 | 166 |
from collections import defaultdict
s = input()
d = defaultdict(int)
tmp = 0
for i in range(len(s)):
tmp += int(s[-i - 1]) * pow(10, i, 2019)
tmp %= 2019
d[tmp] += 1
ans = 0
for key, value in d.items():
if key == 0:
ans += value * (value + 1) // 2
else:
ans += value * (value - 1) // 2
print(ans)
| from collections import Counter
n = list(input())
n.reverse()
x = [0]*(len(n))
a=0
ex=1
for i in range(len(n)):
a+=int(n[i])*ex
x[i]=a%2019
ex=ex*10%2019
c=Counter(x)
ans = c[0]
for i in c.keys():
b=c[i]
ans += b*(b-1)//2
print(ans)
| 1 | 30,689,020,279,658 | null | 166 | 166 |
n = int(input())
a = sorted([(i, int(ai)) for i, ai in zip(range(1, n + 1), input().split())], key=lambda x: x[1])
for i in range(n):
print(a[i][0], end=' ') | N=int(input())
A=map(int, input().split())
A=list(A)
ans= [0] * len(A)
for i,a in enumerate(A):
ans[a-1]= i+1
print(' '.join(map(str,ans)))
| 1 | 180,947,822,473,430 | null | 299 | 299 |
N = int(input())
if N % 2 == 1:
print(0)
exit()
ans = 0
N //= 2
i = 1
while N >= 5 ** i:
ans += (N // 5 ** i)
i += 1
print(ans)
| n = input()
ans = 0
temp = 0
for i in range(len(n)):
if n[i] == "R":
temp += 1
ans = max(temp,ans)
else:
temp = 0
print(ans) | 0 | null | 60,629,077,772,140 | 258 | 90 |
from math import pi
print(2 * pi * int(input()), end='\n\r')
| import sys
for i in sys.stdin.readlines()[:-1]:
h,w = map(int,i.strip().split())
for i in range(h):
for j in range(w):
print('#' if (i+j) % 2 == 0 else '.',end='')
print()
print() | 0 | null | 16,261,226,340,940 | 167 | 51 |
K,N=map(int,input().split())
A=[int(i) for i in input().split()]
dlist=[]
for i in range(1,N):
d=A[i]-A[i-1]
dlist.append(d)
dlist.append(A[0]+K-A[N-1])
print(K-max(dlist)) | K,N,*A = map(int, open(0).read().split())
ans = []
for i in range(N-1):
ans.append(abs(A[i+1] - A[i]))
ans.append(A[0] + K - A[-1])
ans.sort()
ans.pop()
print(sum(ans)) | 1 | 43,353,659,875,220 | null | 186 | 186 |
r, b = input().split()
a, b = map(int, input().split())
u = input()
if r == u:
print(a-1, b)
else:
print(a, b-1) | a = input().split()
b = list(map(int, input().split()))
c = input()
if a[0]==c:
print(b[0]-1, b[1])
else:
print(b[0], b[1]-1) | 1 | 71,825,042,279,940 | null | 220 | 220 |
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for q in range(Q):
b, c = map(int, input().split())
B.append(b)
C.append(c)
sam = sum(A)
baketu = [0]*(100001)
for a in A:
baketu[a] += 1
for q in range(Q):
sam = sam + baketu[B[q]] * (C[q] - B[q])
baketu[C[q]] += baketu[B[q]]
baketu[B[q]] = 0
#print(baketu)
print(sam) | import sys
import numpy as np
from math import ceil as C, floor as F
from collections import defaultdict as D
from functools import reduce as R
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def _Ss(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Ss(): return _Ss(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())
_ = I()
xs = Is()
sss = 0
count = D(int)
for x in xs:
sss += x
count[x] += 1
q = I()
for _ in range(q):
b, c = I()
sss += (c - b) * count[b]
print(sss)
count[c] += count[b]
count[b] = 0 | 1 | 12,145,923,829,128 | null | 122 | 122 |
a,b = map(int, input().split())
ans = 0
for i in range(10000):
x = int(i*0.08)
y = int(i*0.10)
if x == a and y == b:
ans = i
break
if ans == 0:
print(-1)
exit()
print(ans)
| A,B = map(int, input().split())
for X in range(1,1001):
if (X*108//100-X)==A and (X*110//100-X)==B:
print(X)
exit()
print(-1) | 1 | 56,617,148,074,002 | null | 203 | 203 |
#!python3
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
def _cmb(N, mod):
N1 = N + 1
fact = [1] * N1
inv = [1] * N1
for i in range(2, N1):
fact[i] = fact[i-1] * i % mod
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N-1, 1, -1):
inv[i] = inv[i+1]*(i+1) % mod
def cmb(a, b):
return fact[a] * inv[b] * inv[a-b] % mod
return cmb
def resolve():
K = int(input())
s = input()
ls = len(s) - 1
mod = 10**9+7
cmb = _cmb(ls+K, mod)
ans = 0
for i in range(K+1):
ans += cmb(ls+i, ls) * pow(25, i, mod) * pow(26, K - i, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
resolve()
| MOD=10**9+7
def facinv(N):
fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)
fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1
for i in range(2,N+1):
fac[i]=fac[i-1]*i%MOD
inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i]=finv[i-1]*inv[i]%MOD
return fac,finv,inv
fac,finv,inv=facinv(2*(10**6))
#nCr
def COM(n,r):
if n<r or r<0:
return 0
else:
return ((fac[n]*finv[r])%MOD*finv[n-r])%MOD
K=int(input())
S=input()
L=len(S)
M=L+K
ans=0
for i in range(M):
if i<L-1:
continue
c=COM(i,L-1)
l=pow(25,i-(L-1),MOD)
r=pow(26,M-i-1,MOD)
ans=(ans+c*l%MOD*r%MOD)%MOD
print(ans) | 1 | 12,823,070,181,780 | null | 124 | 124 |
import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
if p.count(x) == 0:
print(x)
else:
for i in range(1,110):
if p.count(x-i) == 0:
print(x-i)
sys.exit()
elif p.count(x+i) == 0:
print(x+i)
sys.exit()
| x, n = map(int,input().split())
p = list(map(int,input().split()))
d =100
num = 0
if n == 0:
num = x
else:
for i in range(102):
if i not in p:
d_temp = abs(x-i)
if d_temp < d:
d = d_temp
num = i
print(num) | 1 | 14,096,154,219,378 | null | 128 | 128 |
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
ans = [0]*(n-1)
d = deque()
d.append(1)
while d:
v = d.popleft()
for i in graph[v]:
if ans[i-2] != 0 or i == 1:
continue
ans[i-2] = v
d.append(i)
print('Yes')
print(*ans, sep='\n') | n,m=map(int,input().split())
if n%2==1:
for i in range(m):
print(n-i-1,i+1)
else:
cnt=1
for i in range(m):
if i%2==0:
print(n//4-i//2,n//4-i//2+cnt)
else:
print(n//2+n//4-i//2,n//2+n//4-i//2+cnt)
cnt+=1
| 0 | null | 24,712,178,136,062 | 145 | 162 |
h = int(input())
w = int(input())
n = int(input())
if h >= w and n%h != 0:
print(n//h+1)
elif h >= w and n%h == 0:
print(n//h)
elif w >= h and n%w != 0:
print(n//w+1)
else:
print(n//w) | def a_painting():
from math import ceil
H = int(input())
W = int(input())
N = int(input())
return ceil(N / max(H, W))
print(a_painting()) | 1 | 88,735,114,520,766 | null | 236 | 236 |
N,K = map(int,input().split())
h = [int(i) for i in input().split()]
ans = 0
for i in range(N):
if(h[i] >= K):
ans += 1
print(ans) | r=input().split()
N=int(r[0])
K=int(r[1])
d=[int(s) for s in input().split()]
ans=0
for i in range(N):
if d[i]>=K:
ans+=1
print(ans) | 1 | 178,755,493,409,232 | null | 298 | 298 |
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a)+min(b)
for i in range(M):
x,y,z = map(int,input().split())
s = a[x-1]+b[y-1]-z
ans = (s if s < ans else ans)
print(ans) | a, b, m = map(int, input().split())
lsa = list(map(int, input().split()))
lsb = list(map(int, input().split()))
cost = min(lsa) + min(lsb)
for i in range(m):
x, y, c = map(int, input().split())
cost2 = lsa[x - 1] + lsb[y - 1] - c
if cost2 < cost:
cost = cost2
print(cost)
| 1 | 54,048,672,978,972 | null | 200 | 200 |
from collections import deque
K = int(input())
nums = deque([])
for i in range(1, 10):
nums.appendleft(i)
count = 1
while count < K:
num = nums.pop()
last = int(str(num)[-1])
for i in range(max(0, last-1), min(10, last+2)):
nums.appendleft(int(str(num)+str(i)))
count += 1
print(nums.pop())
| def lu(n):
L.append(n)
a=n%10
if len(str(n))>11:
return 1
if a==0:
lu(n*10+1)
lu(n*10)
elif a==9:
lu(n*10+9)
lu(n*10+8)
else:
lu(n*10+1+a)
lu(n*10+a-1)
lu(n*10+a)
L=list()
lu(1)
lu(2)
lu(3)
lu(4)
lu(5)
lu(6)
lu(7)
lu(8)
lu(9)
L=sorted(set(L))
k=int(input())
print(L[k-1]) | 1 | 40,098,772,309,086 | null | 181 | 181 |
T1,T2=[int(i) for i in input().split()]
A1,A2=[int(i) for i in input().split()]
B1,B2=[int(i) for i in input().split()]
if((B1-A1)*((B1-A1)*T1+(B2-A2)*T2)>0):
print(0);
exit();
if((B1-A1)*T1+(B2-A2)*T2==0):
print("infinity")
exit();
ans=(abs((B1-A1)*T1)//abs((B1-A1)*T1+(B2-A2)*T2))*2+1
if(abs((B1-A1)*T1)%abs((B1-A1)*T1+(B2-A2)*T2)==0):
ans-=1
print(ans)
| def solve(t1, t2, a1, a2, b1, b2):
if a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2:
return 'infinity'
if a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2:
a1, a2, b1, b2 = b1, b2, a1, a2
at = a1 * t1 + a2 * t2
bt = b1 * t1 + b2 * t2
ans = 0
dg = bt - at
if a1 > b1:
ans += ((a1 - b1) * t1 - 1) // dg
ans += (a1 - b1) * t1 // dg + 1
return ans
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
print(solve(t1, t2, a1, a2, b1, b2)) | 1 | 131,922,614,946,110 | null | 269 | 269 |
n, k = map(int, input().split())
ww = [int(input()) for _ in range(n)]
def chk(p):
c = 1
s = 0
for w in ww:
if w > p:
return False
if s + w <= p:
s += w
else:
c += 1
s = w
if c > k:
return False
return True
def search(l, r):
if r - l < 10:
for i in range(l, r):
if chk(i):
return i
m = (l + r) // 2
if chk(m):
return search(l, m + 1)
else:
return search(m, r)
print(search(0, 2 ** 30)) | import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
#ๅ
จไฝใฎๆฐๅใซใคใใฆ็ญใใๆฑใใnC2=n(n-1)/2
ALL=0
for i in c.values():
if i>1:
ALL += i*(i-1)//2
#ๅ่ฆ็ด ใๅฝฑ้ฟใใๅใๆฑใใ
for i in A:
if c[i]>2:
print(ALL-c[i]+1)
elif c[i]==2:
print(ALL-1)
else:
print(ALL) | 0 | null | 24,047,559,689,252 | 24 | 192 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
temp,i = sum(a[:k]),k
for _ in range(n-k):
score = temp+a[i]-a[i-k]
print("Yes" if score>temp else "No")
temp = score
i+=1 | N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
ans=[None]*(N-K)
for i in range(N-K):
if A[K+i]>A[i]:
ans[i]='Yes'
else:
ans[i]='No'
print(*ans, sep='\n') | 1 | 7,091,228,679,484 | null | 102 | 102 |
def main():
S = input()
h = [0] * (len(S) + 1)
# < ใจใชใฃใฆใใๅ ดๅใ ใใ่ใใ
# a[i] < a[i+1] ใงใชใๅ ดๅใa[i] ใซ +1 ใใใใฎใ a[i+1] ใซใใ
for i in range(len(S)):
if(S[i] == "<"):
h[i+1] = max(h[i+1], h[i] + 1)
# > ใจใชใฃใฆใใๅ ดๅใ ใใ่ใใ
# a[i-1] > a[i] ใงใชใๅ ดๅใa[i] ใซ +1 ใใใใฎใ a[i-1] ใซใใ
# ใใฎๆใใฎๆไฝใฏ้้ ใใ่กใ
for i in range(len(S), 0, -1):
if(S[i-1] == ">"):
h[i-1] = max(h[i-1], h[i] + 1)
print(sum(h))
if __name__ == "__main__":
main() | 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))
| 1 | 156,168,893,661,760 | null | 285 | 285 |
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]
L=[0]*(10**5+1)
S=0
for i in range(N):
L[A[i]]+=1
S+=A[i]
for i in range(q):
S+=L[Q[i][0]]*(Q[i][1]-Q[i][0])
L[Q[i][1]]+=L[Q[i][0]]
L[Q[i][0]]=0
# print(L)
print(S) | n0 = int(1e5)+1
x = [0]*n0
n = int(input())
a0 = list(map(int,input().split()))
q = int(input())
bcs = []
for i in range(q):
bcs.append(list(map(int,input().split())))
for a in a0:
x[a] += 1
sum0 = sum(a0)
for bc in bcs:
sum0 = sum0 + bc[1]*x[bc[0]] - bc[0]*x[bc[0]]
x[bc[1]] += x[bc[0]]
x[bc[0]] = 0
print(sum0) | 1 | 12,150,872,980,828 | null | 122 | 122 |
n = int(input())
ans = ""
for i in range(1,99):
if n <= 26**i :
n -= 1
for j in range(i):
ans += chr(ord("a") + n%26)
n //= 26
break
else :
n -= 26**i
print(ans[::-1])
| import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
worst_score = 10 ** 12
n, k = ns()
a = na()
f = na()
a.sort()
f.sort(reverse=True)
score = [ai * fi for ai, fi in zip(a, f)]
l = 0
r = worst_score
while True:
middle = (l + r) // 2
tmp_k = k
for i in range(n):
tmp = (score[i] - middle + f[i] - 1) // f[i]
tmp_k -= max(0, tmp)
if tmp_k < 0:
break
if r - l == 1:
print(middle if tmp_k >= 0 else middle + 1)
exit(0)
if tmp_k < 0:
l = middle
else:
r = middle
if __name__ == '__main__':
main()
| 0 | null | 88,697,394,528,200 | 121 | 290 |
s = input()
counter = 0
ans = 0
for i in s:
if i == "R":
counter += 1
else:
counter = 0
ans = max(ans, counter)
print(ans) | import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
a,b,c = inpm()
k = inp()
for i in range(k):
if b <= a:
b *= 2
elif c <= b:
c *= 2
if a < b < c:
ans = 'Yes'
else:
ans = 'No'
print(ans)
| 0 | null | 5,887,383,771,350 | 90 | 101 |
s=input()
a=len(s)
if s[a-1]=='s':
print(s+str("es"))
else:
print(s+str('s')) | import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
S = input()
if S[-1] == 's':
S += 'es'
else:
S += 's'
print(S)
resolve() | 1 | 2,404,691,420,364 | null | 71 | 71 |
MOD = 1e9 + 7
n = int(input())
ans = [[0, 1, 1, 8]]
for i in range(n-1):
a, b, c, d = ans.pop()
a = (a * 10 + b + c) % MOD
b = (b * 9 + d) % MOD
c = (c * 9 + d) % MOD
d = (d * 8) % MOD
ans.append([a, b, c, d])
a, b, c, d = ans.pop()
print(int(a)) | import sys
nums = sorted( [ int( val ) for val in sys.stdin.readline().split( " " ) ] )
print( "{:d} {:d} {:d}".format( nums[0], nums[1], nums[2] ) ) | 0 | null | 1,766,441,284,462 | 78 | 40 |
"""
keyword: ใฉใธใขใณ, ๅบฆ
ๆๅคง้ๅพใใใจใใๆฐดใจๆฅใใฆใใ้ขใฏๆจชใใ่ฆใใจๅฐๅฝขใชใใไธ่งๅฝขใจใชใ
ๆฐดใจๆฅใใฆใใ้ขใฎ้ข็ฉ x/a ใ a*b/2 ใใๅคงใใๅ ดๅใฏๅฐๅฝขใจใชใใใใไปฅไธใฎๅ ดๅใฏไธ่งๅฝขใจใชใ
ใปๅฐๅฝขใฎๅ ดๅ
ๆๅคง้ๅพใใใจใใๆฐดใจๆฅใใฆใใๅฐๅฝขใฎไธ่พบใฎ้ทใใhใจใใใจ
(h+b)*a/2 = x/a
h = 2*x/(a**2) - b
ๆฑใใ่งๅบฆใthetaใจใใใจ
tan(theta) = (b-h)/a
theta = arctan((b-h)/a)
ใปไธ่งๅฝขใฎๅ ดๅ
ๆๅคง้ๅพใใใจใใๆฐดใจๆฅใใฆใใไธ่งๅฝขใฎๅบ่พบใฎ้ทใใhใจใใใจ
h*b/2 = x/a
h = 2*x/(a*b)
ๆฑใใ่งๅบฆใthetaใจใใใจ
tan(theta) = b/h
theta = arctan(b/h)
"""
import sys
sys.setrecursionlimit(10**6)
a,b,x = map(int, input().split())
import numpy as np
if x/a > a*b/2:
h = 2*x/(a**2) - b
theta = np.arctan2(b-h, a) # radian่กจ่จใชใฎใงๆปใๅคใฎ็ฏๅฒใฏ[-pi/2, pi/2]
theta = np.rad2deg(theta)
else:
h = 2*x/(a*b)
theta = np.arctan2(b, h)
theta = np.rad2deg(theta)
print(theta) | from math import atan,pi
A,B,X=map(int,input().split())
if 2*X>=A*A*B:
P=atan(2*(A*A*B-X)/(A*A*A))*180/pi
print(P)
else:
Q=atan((A*B*B)/(2*X))*180/pi
print(Q)
| 1 | 163,419,622,799,868 | null | 289 | 289 |
x1, y1, x2, y2 = map(float, input().split())
print(abs(complex(x1-x2, y1-y2)))
| import math
x1,y1,x2,y2=map(float,input().split())
A=abs(y1-y2)
B=abs(x1-x2)
C=math.sqrt(A**2+B**2)
print(f'{C:.8f}')
| 1 | 156,706,950,070 | null | 29 | 29 |
# ALDS_11_C - ๅน
ๅชๅ
ๆข็ดข
import sys
import heapq
N = int(input())
G = []
for _ in range(N):
u, k, *v = map(int, sys.stdin.readline().strip().split())
v = [i - 1 for i in v]
G.append(v)
distance = [-1] * N
q = []
fp = [True] * N # ๆข็ดขๅฏ่ฝใ่จ้ฒใใ
heapq.heapify(q)
heapq.heappush(q, (0, 0))
fp[0] = False
while q:
dist, u = heapq.heappop(q)
distance[u] = dist
for v in G[u]:
if fp[v] is True:
heapq.heappush(q, (dist + 1, v))
fp[v] = False
for i, d in enumerate(distance):
print(i + 1, d)
| #Breadth First Search
n=int(input())
V=[]
a=[1]
for i in range(n):
V.append([int(i) for i in input().split()])
a.append(0)
V=sorted(V,key=lambda x:x[0])
print('1 0')
d=1
c=0
w=[0]
p=[]
while c<n and w!=[]:
i=0
y=[]
# print(c)
while c<n and i<len(w):
j=2
while j<2+V[w[i]][1] and c<n:
if a[V[w[i]][j]-1]==0:
# print(a)
a[V[w[i]][j]-1]=1
p.append([V[w[i]][j],d])
c+=1
y.append(V[w[i]][j]-1)
j+=1
i+=1
w=y
d+=1
p=sorted(p, key=lambda x:x[0])
#print(p)
i=2
j=0
while i <=n and j<len(p):
while p[j][0]>i:
print(str(i) +" -1")
i+=1
print(str(p[j][0])+" "+str(p[j][1]))
i+=1
j+=1
while i<=n:
print(str(i)+" -1")
i+=1 | 1 | 3,898,345,152 | null | 9 | 9 |
N,M=map(int,input().split())
a=M//2
b=M-a
c=1
d=2*a+1
for i in range(a):
print(c,d)
c+=1
d-=1
e=2*a+2
f=2*M+1
for i in range(b):
print(e,f)
e+=1
f-=1 | import math
import sys
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()))
mod = 10**9 + 7
sys.setrecursionlimit(1000010)
N,M = nm()
used = [0] * N
start = 0
if N % 2 != 0:
s = (N-1)//2
else:
s = N//2 - 1
for i in range(1,M+1):
q= (i+1)//2
if i % 2 !=0:
print(q,N+1-q)
else:
print(s+1-q,s+1+q)
| 1 | 28,705,133,811,020 | null | 162 | 162 |
import collections
n = int(raw_input())
def g( a, b , n):
count = 0
## CASE 1
if a == b and a <=n :
count +=1
## CASE 2
if a *10 + b <= n:
count +=1
if len(str(n)) <=2:
return count
## CASE 3
s = str(n)
if len(s) - 3 >= 1:
count += 10 ** (len(s) - 3)
## CASE 4
s = str(n)
if a == int(s[0]):
m = s[1:-1]
if m != '':
#0,m-1
count += int(m)
if b <= int(s[-1]):
count +=1
elif a < int(s[0]):
count += 10 ** (len(s) - 2)
return count
h = collections.Counter()
for k in range(1, n+1):
ks = str(k)
a,b = int(ks[0]), int(ks[-1])
h[(a,b)] +=1
s= 0
for a in range(1,10):
for b in range(1,10):
s += h[(a,b)] * h[(b,a)]
print s
| def main():
s = input()
if s.count('hi') == len(s) // 2 and len(s) % 2 == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 69,942,411,251,260 | 234 | 199 |
import sys
def display(inp):
s = len(inp)
for i in range(s):
if i!=len(inp)-1:
print("%d" % inp[i], end=" ")
else:
print("%d" % inp[i], end="")
print("")
line = sys.stdin.readline()
size = int(line)
line = sys.stdin.readline()
inp = []
for i in line.split(" "):
inp.append(int(i))
display(inp)
for i in range(1,size):
if inp[i]!=size:
check = inp.pop(i)
for j in range(i):
if check<inp[j]:
inp.insert(j,check)
break
if j==i-1:
inp.insert(j+1,check)
break
display(inp) | N = int(input())
A = (input()).split()
for i in range(0,N):
A[i] = int(A[i])
for i in range(0,N):
innum = A[i]
j = i - 1
while j>=0 and innum < A[j]:
A[j+1] = A[j]
j = j -1
A[j+1] = innum
for j in range(0,N):
if j < N-1:
print(A[j], end=" ")
else:
print(A[j]) | 1 | 5,454,498,664 | null | 10 | 10 |
N=int(input())
MOD=10**9+7
in_9=10**N-9**N
in_0=10**N-9**N
nine_and_zero=10**N-8**N
ans=int(int(in_0+in_9-nine_and_zero)%MOD)
print(ans) | n=int(input())
s=list(input())
r=[]
g=[]
b=[]
for i in range(n):
if s[i]=='R':
r.append(i)
elif s[i]=='G':
g.append(i)
else:
b.append(i)
import bisect
def binary_search(a, x):
# ๆฐๅaใฎใชใใซxใจ็ญใใใใฎใใใใ่ฟใ
i = bisect.bisect_left(a, x)
if i != len(a) and a[i] == x:
return True
else:
return False
ans=0
for i in range(len(r)):
for j in range(len(g)):
p=0
if r[i]<g[j]:
if binary_search(b,g[j]-r[i]+g[j]):
p+=1
if binary_search(b,r[i]+(g[j]-r[i])/2):
p+=1
if binary_search(b,r[i]-(g[j]-r[i])):
p+=1
else:
if binary_search(b,r[i]-g[j]+r[i]):
p+=1
if binary_search(b,g[j]+(r[i]-g[j])/2):
p+=1
if binary_search(b,g[j]-(r[i]-g[j])):
p+=1
ans+=len(b)-p
print(ans)
| 0 | null | 19,739,940,877,312 | 78 | 175 |
import math
print([ ( int(x) * 360 // math.gcd(int(x),360) ) // int(x) for x in input().split(' ') ][0]) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
X = int(input())
from math import gcd
print(360*X//gcd(360, X)//X) | 1 | 13,149,258,785,514 | null | 125 | 125 |
#!python3
LI = lambda: list(map(int, input().split()))
# input
K = int(input())
S = input()
MOD = 10 ** 9 + 7
MAX = 2 * (10 ** 6) + 1
p25, p26 = [None] * MAX, [None] * MAX
fac, finv, inv = [None] * MAX, [None] * MAX, [None] * MAX
def comb_init():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = -inv[MOD%i] * int(MOD / i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def comb(n, k):
if n < k or n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
def power_init():
p25[0] = 1
p26[0] = 1
for i in range(1, MAX):
p25[i] = p25[i - 1] * 25 % MOD
p26[i] = p26[i - 1] * 26 % MOD
def main():
comb_init()
power_init()
n = len(S)
ans = 0
for i in range(K + 1):
x = p25[i] * comb(i + n - 1, n - 1) % MOD * p26[K - i] % MOD
ans = (ans + x) % MOD
print(ans)
if __name__ == "__main__":
main()
| mod = 1000000007
fact = []
fact_inv = []
pow_ = []
pow25_ = []
pow26_ = []
def pow_ini(nn):
global pow_
pow_.append(nn)
for j in range(62):
nxt = pow_[j] * pow_[j]
nxt %= mod
pow_.append(nxt)
return
def pow_ini25(nn):
global pow25_
pow25_.append(nn)
for j in range(62):
nxt = pow25_[j] * pow25_[j]
nxt %= mod
pow25_.append(nxt)
return
def pow_ini26(nn):
global pow26_
pow26_.append(nn)
for j in range(62):
nxt = pow26_[j] * pow26_[j]
nxt %= mod
pow26_.append(nxt)
return
def pow1(k):
ansk = 1
for ntmp in range(62):
if((k >> ntmp) % 2 == 1):
ansk *= pow_[ntmp]
ansk %= mod
return ansk
def pow25(k):
ansk = 1
for ntmp in range(31):
if((k >> ntmp) % 2 == 1):
ansk *= pow25_[ntmp]
ansk %= mod
return ansk
def pow26(k):
ansk = 1
for ntmp in range(31):
if((k >> ntmp) % 2 == 1):
ansk *= pow26_[ntmp]
ansk %= mod
return ansk
def fact_ini(n):
global fact
global fact_inv
global pow_
for i in range(n + 1):
fact.append(0)
fact_inv.append(0)
fact[0] = 1
for i in range(1, n + 1, 1):
fact_tmp = fact[i - 1] * i
fact_tmp %= mod
fact[i] = fact_tmp
pow_ini(fact[n])
fact_inv[n] = pow1(mod - 2)
for i in range(n - 1, -1, -1):
fact_inv[i] = fact_inv[i + 1] * (i + 1)
fact_inv[i] %= mod
return
def nCm(n, m):
assert(m >= 0)
assert(n >= m)
ans = fact[n] * fact_inv[m]
ans %= mod
ans *= fact_inv[n - m]
ans %= mod
return ans;
fact_ini(2200000)
pow_ini25(25)
pow_ini26(26)
K = int(input())
S = input()
N = len(S)
ans = 0
for k in range(0, K+1, 1):
n = N + K - k
anstmp = 1
anstmp *= pow26(k)
anstmp %= mod
anstmp *= nCm(n - 1, N - 1)
anstmp %= mod
anstmp *= pow25(n - N)
anstmp %= mod
ans += anstmp
ans %= mod
print(ans) | 1 | 12,671,471,253,312 | null | 124 | 124 |
def scan(s):
m = 0
a = 0
for c in s:
if c == '(':
a += 1
elif c == ')':
a -= 1
m = min(m, a)
return m, a
def key(v):
m, a = v
if a >= 0:
return 1, m, a
else:
return -1, a - m, a
N = int(input())
S = [input() for _ in range(N)]
c = 0
for m, a in sorted([scan(s) for s in S], reverse=True, key=key):
if c + m < 0:
c += m
break
c += a
if c == 0:
print('Yes')
else:
print('No')
| (N,) = [int(x) for x in input().split()]
brackets = [input() for i in range(N)]
delta = []
minDelta = []
for s in brackets:
balance = 0
mn = 0
for c in s:
if c == "(":
balance += 1
else:
balance -= 1
mn = min(mn, balance)
delta.append(balance)
minDelta.append(mn)
if sum(delta) == 0:
# Want to get balance as high as possible
# Take any positive as long there's enough balance to absorb their minDelta
# Can sort since anything that works will only increase balance and the ones with worse minDelta comes later
posIndices = [i for i in range(N) if delta[i] > 0]
posIndices.sort(key=lambda i: minDelta[i], reverse=True)
# At the top can take all with zero delta, just need to absorb minDelta
eqIndices = [i for i in range(N) if delta[i] == 0]
# When going back down, want to preserve existing balance as much as possible but take a hit for stuff that does need to use the balance to absorb minDelta
negIndices = [i for i in range(N) if delta[i] < 0]
negIndices.sort(key=lambda i: delta[i] - minDelta[i], reverse=True)
balance = 0
for i in posIndices + eqIndices + negIndices:
if balance + minDelta[i] < 0 or balance + delta[i] < 0:
print("No")
exit()
balance += delta[i]
assert balance == 0
print("Yes")
else:
print("No")
| 1 | 23,750,047,904,698 | null | 152 | 152 |
S = input()
P =2019
ans = 0
count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
u = (int(s) * pow(10, i, P) + u) % P
ans += count[u]
count[u] += 1
print(ans)
| d=raw_input().split(" ")
l=list(map(int,d))
if(l[2]>0 and l[3]>0):
if(l[0]>=(l[2]+l[4])):
if(l[1]>=(l[3]+l[4])):
print "Yes"
else:
print "No"
else:
print "No"
else:
print "No"
| 0 | null | 15,579,952,314,908 | 166 | 41 |
s = list(input())
if len(s) % 2 != 0:
print("No")
exit()
while s:
if s[0]=="h" and s[1] == "i":
s.pop(0)
s.pop(0)
else:
print("No")
exit()
print("Yes") | import sys
while True:
(x, y) = [int(i) for i in sys.stdin.readline().split(' ')]
if x == 0 and y == 0:
break
if x > y:
z = x
x = y
y = z
print(x, y) | 0 | null | 26,777,093,035,308 | 199 | 43 |
s = int(input())
h = s//3600
s = s%3600
m = s//60
s = s%60
print(h,':',m,':',s, sep='')
| t = int(input())
h = int(t/3600)
m = int(t%3600/60)
s = int(t%3600%60)
print(str(h) + ":" + str(m) + ":" + str(s)) | 1 | 322,875,366,660 | null | 37 | 37 |
N = int(input())
S, T = map(str, input().split())
result = []
for i in range(N):
result.append(S[i])
result.append(T[i])
print(''.join(result)) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????ยง?????????
FX????????ยง????????ยฐ?????????????????ยจ????????????????????ยจ??ยง????????????????????????????????ยจ?????ยง????????????
????????ยฐ????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????ยฃ??????????ยฃ??????ยจ???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????ยจ?????ยง????????????
???????????ยจ????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????ยจ??????????????????????????ยง??????????????? Rj???Ri (????????????j>i ??ยจ??????) ????????ยง??????
?ยฑ??????????????????????
"""
import math
# ?????????
cnt = -1000000000
n = int(input().strip())
min = int(input().strip())
for i in range(1,n):
a =int(input().strip())
x = a - min
if cnt < x:
cnt = x
if min > a:
min = a
print(cnt) | 0 | null | 55,868,483,891,748 | 255 | 13 |
import sys
n = int(input())
minv = int(input())
v = int(input())
maxv = v-minv
if v < minv: minv = v
for r in map(int,sys.stdin.readlines()):
m = r-minv
if maxv < m < 0:
maxv = m
minv = r
elif maxv < m:
maxv = m
elif m < 0:
minv = r
print(maxv) | n = int(input())
R =[]
for i in range(n):
R.append(int(input()))
maxR = R[1]
minR = R[0]
maxB = R[1] - R[0]
for i in range(1,n):
if R[i] < minR:
minR = R[i]
maxR = R[i] - 1
elif minR <= R[i] and R[i] <= maxR:
continue
else:
maxR = R[i]
if maxR - minR > maxB:
maxB = maxR - minR
print(str(maxB)) | 1 | 13,850,616,100 | null | 13 | 13 |
cnt = 0
s = input().lower()
while 1:
line = input()
if line == "END_OF_TEXT":
break
for w in line.lower().split():
if w == s:
cnt+=1
print(cnt) | # AOJ ITP1_9_A
# โปๅคงๆๅญใจๅฐๆๅญใๅบๅฅใใชใใฎใงๆณจๆ๏ผ๏ผ๏ผ๏ผ
# ๅ
จ้จๅคงๆๅญใซใใกใใใ
def main():
W = input().upper() # ๅคงๆๅญใซใใ
line = ""
count = 0
while True:
line = input().split(" ")
if line[0] == "END_OF_TEXT": break
for i in range(len(line)):
word = line[i].upper()
if W == word: count += 1
print(count)
if __name__ == "__main__":
main()
# Accepted.
| 1 | 1,811,571,769,142 | null | 65 | 65 |
string = input()
q = int(input())
for i in range(q):
order = list(input().split())
a, b = int(order[1]), int(order[2])
if order[0] == "print":
print(string[a:b+1])
elif order[0] == "reverse":
string = string[:a] + (string[a:b+1])[::-1] + string[b+1:]
else:
string = string[:a] + order[3] + string[b+1:]
| sen = input()
n = int(input())
for i in range(n):
cmd = input().split()
sta = int(cmd[1])
end = int(cmd[2])
if cmd[0] == 'replace':
sen = sen[0:sta] + cmd[3] + sen[end+1:]
elif cmd[0] == 'reverse':
rev = sen[sta:end+1]
rev = rev[::-1]
# print(rev)
sen = sen[0:sta] + rev +sen[end+1:]
elif cmd[0] == 'print':
print(sen[sta:end+1])
# print('sen : '+sen) | 1 | 2,128,370,585,390 | null | 68 | 68 |
import sys
readline = sys.stdin.readline
def main():
N, X, M = map(int, readline().split())
P = N.bit_length()
pos = [[0] * M for _ in range(P)]
value = [[0] * M for _ in range(P)]
for r in range(M):
pos[0][r] = r * r % M
value[0][r] = r
for p in range(P - 1):
for r in range(M):
pos[p + 1][r] = pos[p][pos[p][r]]
value[p + 1][r] = value[p][r] + value[p][pos[p][r]]
ans = 0
cur = X
for p in range(P):
if N & (1 << p):
ans += value[p][cur]
cur = pos[p][cur]
print(ans)
return
if __name__ == '__main__':
main()
| def readInt():
return int(input())
def readList():
return list(map(int,input().split()))
def readMap():
return map(int,input().split())
def readStr():
return input()
inf=float('inf')
mod = 10**9+7
import math
def solve(N,X,M):
seen=set()
order_seen=[]
while X not in seen:
seen.add(X)
order_seen.append(X)
X=f(X,M)
pos=order_seen.index(X) # Find position of when the cycle begins
if pos>N: # If position is greater than N, then we know we are not going to include any values from the cycle.
return sum(order_seen[:N])
terms_before_cycle=order_seen[:pos]
sum_terms_before_cycle=sum(terms_before_cycle)
ans=sum_terms_before_cycle
terms_in_cycle=order_seen[pos:]
sum_cycle=sum(terms_in_cycle)
length_cycle=len(terms_in_cycle)
number_remaining_terms=N-pos
mult_factor=(number_remaining_terms)//length_cycle
ans+=(sum_cycle*mult_factor)
numb_remain=(number_remaining_terms)%length_cycle
ans+=sum(terms_in_cycle[:numb_remain])
return ans
# The function for the recurrence relation. A_n+1=A_n^2%M
def f(A,M):
return pow(A,2,M)
N,X,M=readMap()
print(solve(N,X,M)) | 1 | 2,826,488,731,040 | null | 75 | 75 |
dice = map(int, raw_input().split())
inst = raw_input()
def rolling(inst, dice):
if inst == 'E':
dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
elif inst == 'W':
dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
elif inst == 'N':
dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
elif inst == 'S':
dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
for i in range(len(inst)):
rolling(inst[i], dice)
print dice[0] | class Dice:
def __init__(self, faces):
self.faces = tuple(faces)
def roll_north(self):
self.faces = (self.faces[1], self.faces[5], self.faces[2],
self.faces[3], self.faces[0], self.faces[4])
def roll_south(self):
self.faces = (self.faces[4], self.faces[0], self.faces[2],
self.faces[3], self.faces[5], self.faces[1])
def roll_west(self):
self.faces = (self.faces[2], self.faces[1], self.faces[5],
self.faces[0], self.faces[4], self.faces[3])
def roll_east(self):
self.faces = (self.faces[3], self.faces[1], self.faces[0],
self.faces[5], self.faces[4], self.faces[2])
def number(self, face_id):
return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
commands = input()
for c in commands:
if c == "N":
dice.roll_north()
elif c == "S":
dice.roll_south()
elif c == "W":
dice.roll_west()
elif c == "E":
dice.roll_east()
print(dice.number(1)) | 1 | 226,340,275,588 | null | 33 | 33 |
a, b = map(int, input().split())
sq = a * b
leng = a*2 + b*2
print('{} {}'.format(sq,leng)) | while True:
h,w=map(int,input().split())
if h==w==0:break
for hh in range(h):
ol=''
for ww in range(w):
if hh == 0 or ww == 0 or hh == h - 1 or ww == w - 1:
ol+='#'
else:
ol+='.'
print(ol)
print() | 0 | null | 566,461,321,060 | 36 | 50 |
# -*- coding:utf-8 -*-
def main():
List=[]
for i in range(10):
a=int(input())
List.append(a)
List.sort(reverse=True)
print(List[0])
print(List[1])
print(List[2])
if __name__ == '__main__':
main() | heights = [int(input()) for i in range(0, 10)]
heights.sort(reverse=True)
for height in heights[:3]:
print(height) | 1 | 22,767,980 | null | 2 | 2 |
n = int(input())
index = set()
for _ in range(n):
command, string = input().split()
if command == "insert":
index.add(string)
else:
if string in index:
print("yes")
else:
print("no")
| import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n, m, k = map(int, readline().rstrip().split())
A = list(map(int, readline().rstrip().split()))
B = list(map(int, readline().rstrip().split()))
a, b = [0], [0]
for i in range(n):
a.append(a[i] + A[i])
for i in range(m):
b.append(b[i] + B[i])
ans = 0
j = m
for i in range(n + 1):
if a[i] > k:
break
while b[j] > k - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 5,411,328,543,222 | 23 | 117 |
import sys
sys.setrecursionlimit(10000000)
n,x,y=map(int,input().split())
x-=1
y-=1
res=[0]*n
for i in range(n):
for j in range(i+1,n):
m = min(j-i, abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1)
res[m]+=1
for i in range(1,n):
print(res[i]) | print(eval("'ACL'*"+input())) | 0 | null | 23,250,674,077,540 | 187 | 69 |
W, H, x, y, r = [int(i) for i in input().split()]
if r <= y <= H - r and r <= x <= W - r:
print('Yes')
else:
print('No') | __author__ = 'CIPHER'
_project_ = 'PythonLehr'
class BoundingBox:
def __init__(self, width, height):
self.width = width;
self.height = height;
def CalculateBox(self, x, y, r):
if x>= r and x<=(self.width-r) and y>=r and y<=(self.height-r):
print("Yes")
else:
print("No")
'''
width = int(input("Width of the Box: "))
height = int(input("Height of the Box: "))
x = int(input("location of x: "))
y = int(input("location of y: "))
r = int(input("radius of the circle; "))
'''
# alternative input
inputList = input()
inputList = inputList.split(' ')
inputList = [int(x) for x in inputList]
# print(inputList)
width = inputList[0]
height = inputList[1]
x = inputList[2]
y = inputList[3]
r = inputList[4]
Box = BoundingBox(width, height)
Box.CalculateBox(x, y, r) | 1 | 455,469,057,270 | null | 41 | 41 |
import math
import collections
def prime_diviation(n):
factors = []
i = 2
while i <= math.floor(math.sqrt(n)):
if n%i == 0:
factors.append(int(i))
n //= i
else:
i += 1
if n > 1:
factors.append(n)
return factors
N = int(input())
if N == 1:
print(0)
exit()
#pr:็ด ๅ ๆฐๅ่งฃ prs:้ๅใซใใใใค prcnt:counter
pr = prime_diviation(N)
prs = set(pr)
prcnt = collections.Counter(pr)
#print(pr, prs, prcnt)
ans = 0
for a in prs:
i = 1
cnt = 2*prcnt[a]
#2*prcnt >= n(n+1)ใจใชใๆๅคงใฎnใๆขใใฎใๆฅฝใใ
# print(cnt)
while cnt >= i*(i+1):
i += 1
ans += i - 1
print(ans) | from collections import Counter
def aprime_factorize(n: int) -> list:
return_list = []
while n % 2 == 0:
return_list.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
return_list.append(f)
n //= f
else:
f += 2
if n != 1:
return_list.append(n)
return return_list
judge = []
cnt = 0
while len(judge) <= 40:
for i in range(cnt+1):
judge.append(cnt)
cnt += 1
N = int(input())
list = Counter(aprime_factorize(N)).most_common()
res = 0
for i, li in enumerate(list):
res += judge[li[1]]
print(res)
| 1 | 16,812,601,190,402 | null | 136 | 136 |
#https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_D
s = str(input())
l = len(s)
h = [0]
for i in range(l):
if s[i] == '\\':
h.append(h[i]-1)
elif s[i] == '/':
h.append(h[i]+1)
else:
h.append(h[i])
a = []
m = -200000
n = 0
for i in range(l+1):
if m == h[i] and i != 0:
a.append([n,i,m])
m = -200000
if m < h[i] or i == 0:
m = h[i]
n = i
if (m in h[i+1:]) == False:
m = -200000
b = []
tmp = 0
for i in range(len(a)):
for j in range(a[i][0],a[i][1]):
tmp += a[i][2] - h[j]
if s[j] == '/':
tmp += 1 / 2
elif s[j] == '\\':
tmp -= 1 / 2
b.append(int(tmp))
tmp = 0
if len(b) != 0:
i=0
while True:
if b[i] == 0:
del b[i]
i -= 1
i += 1
if i == len(b):
break
A = sum(b)
k = len(b)
print(A)
print(k,end = '')
if k != 0:
print(' ',end='')
for i in range(k-1):
print(b[i],end=' ')
print(b[len(b)-1])
else:
print('')
| import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
a.sort()
a_desc = a[::-1]
ok = 0
ng = 2 * max(a) + 1
while abs(ng - ok) > 1:
mid = (ok + ng) // 2
count = 0
i = 0
for elem in a:
while i < n:
if elem + a_desc[i] >= mid:
i += 1
else:
break
count += i
if count >= m:
ok = mid
else:
ng = mid
from itertools import accumulate
a_cum = list(accumulate(a_desc))
a_cum = a_cum[::-1] + [0]
ans = 0
j = n
cnt_over = 0
for elem in a:
while j > 0:
if elem + a[j - 1] > ok:
j -= 1
else:
break
cnt_over += (n - j)
ans += a_cum[j]
ans += elem * (n - j)
ans += ok * (m-cnt_over)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 54,221,020,908,348 | 21 | 252 |
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
n=int(input())
nlist=make_divisors(n)
n1list=make_divisors(n-1)
# print(nlist)
# print(n1list)
answer=len(n1list)-1#1ใ้คใใพใ
for i in nlist[1:len(nlist)]:
pra=n
while (pra%i==0):
pra=pra/i
if pra%i==1:
answer+=1
print(answer)
| x,k,d = list(map(int, input().split()))
amari = abs(x) % d
shou = abs(x) // d
amari_ = abs(amari - d)
if k < shou:
print(abs(x) - d * k)
else:
if (k - shou) % 2 == 0:
print(amari)
else:
print(amari_) | 0 | null | 23,356,387,485,668 | 183 | 92 |
n,k=map(int,input().split())
B=list(map(int,input().split()))
S=list(input())
A=[[] for i in range(k)]
for i in range(n):
if S[i]=="s":
A[i%k].append(0)
elif S[i]=="p":
A[i%k].append(1)
else:
A[i%k].append(2)
ans=0
for i in range(k):
f=0
for j in range(len(A[i])):
if f==0:
ans=ans+B[A[i][j]]
if j!=len(A[i])-1:
if A[i][j]==A[i][j+1]:
f=1
else:
f=0
print(ans) | N,K = (int(x) for x in input().split())
Conv = []
while N!=0:
Conv.append(N%K)
N = N//K
Disp = ''.join([str(x) for x in Conv[::-1]])
print(len(Disp)) | 0 | null | 85,338,015,412,288 | 251 | 212 |
k, n =map(int,input().split())
a = list(map(int,input().split()))
longest = k - a[-1] + a [0]
for i in range(len(a)-1):
longest = max(longest,a[i+1]-a[i])
print(k-longest) | import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
#็ดๆฐๅๆ
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
ans=set(make_divisors(N-1))
ans=ans - set([1])
ans.add(2)
L=make_divisors(N)
for i in range(1,len(L)):
temp=L[i]
N2=N
while N2>=temp:
if N2%temp==0:
N2=N2//temp
else:
N2=N2%temp
if N2==1:
ans.add(temp)
print(len(ans))
main()
| 0 | null | 42,384,626,400,998 | 186 | 183 |
n = int(input())
r = n // 2
a = n % 2
print(r + a) | n = int(input())
ans = (n//2) + (n%2)
print (ans) | 1 | 58,850,038,378,330 | null | 206 | 206 |
x,k,d=list(map(int,input().split()))
#print(x,k,d)
result=abs(x)-k*d
swithn=0
if result<0:
if k%2==1:
x-=d
result=min(x%(2*d),-x%(2*d))
print(result) | a,b=input().split()
a=int(a)
b=int(float(b)*100)
if (a*b<100):
print(0)
else:
print(str(a*b)[:-2]) | 0 | null | 10,494,209,113,080 | 92 | 133 |
MOD = 10**9 + 7
K = int(input())
S = len(input())
FCT = [1]
for i in range(1, K+S+1):
FCT.append((FCT[-1] * i)%MOD)
def pmu(n, r, mod=MOD):
return (FCT[n] * pow(FCT[n-r], mod-2, mod)) % mod
def cmb(n, r, mod=MOD):
return (pmu(n, r) * pow(FCT[r], mod-2, mod)) % mod
def solve():
ans = 1
for i in range(S+1, K+S+1):
ans = (ans*26) % MOD
add = pow(25, i-S, MOD)
add = (add * cmb(i-1, i-S)) % MOD
ans = (ans + add) % MOD
return ans
if __name__ == "__main__":
print(solve())
| k = int(input())
n = len(input())
mod = pow(10,9)+7
c = 1
ans = pow(26,k,mod)
for i in range(1,k+1):
c *= (i+n-1)*pow(i,mod-2,mod)
c %= mod
ans += (c*pow(25,i,mod)*pow(26,k-i,mod))
ans %= mod
print(ans) | 1 | 12,802,367,896,640 | null | 124 | 124 |
N = int(input())
lsa = list(map(int,input().split()))
a = 1
for i in range(N):
if lsa[i] == a:
a += 1
if a == 1:
ans = -1
else:
ans = N-(a-1)
print(ans) | # ABC155E
s = input()
d0 = [0,1,2,3,4,5,6,7,8,9]
d1 = [0,1,2,3,4,5,5,4,3,2] # ้ๅธธๆ
a0 = d1[int(s[0])]
a1 = d1[int(s[0]) + 1] if int(s[0])<=8 else 1
for c in s[1:]:
c = int(c)
b0 = min(a0 + c, a1 + (10 - c))
b1 = min(a0 + c + 1, a1 + (9 - c)) if c <=8 else a1
a0, a1 = b0, b1
print(a0) | 0 | null | 92,322,264,534,240 | 257 | 219 |
if sum(list(map(int, input().split()))) >= 22:
print("bust")
else:
print("win") | A, B, C = map(int, input().split())
if A+B+C > 21:
print('bust')
else:
print('win') | 1 | 118,610,625,119,868 | null | 260 | 260 |
a, a1, a2 = map(int,input().split())
if a + a1 + a2 >= 22:
print('bust')
else:
print('win') | import math
from collections import defaultdict
ml=lambda:map(float,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
"""========main code==============="""
a,b,c=ml()
if(a+b+c>=22):
print("bust")
else:
print("win") | 1 | 118,391,836,203,762 | null | 260 | 260 |
for i in range(1, 10):
for j in range(1, 10):
print(i,'x',j,'=',i*j,sep='') | x = 0
y = 0
z = 0
for i in range(9):
x += 1
y = 0
for j in range(9):
y += 1
z = x*y
print(x, end = 'x')
print(y, end = '=')
print(z) | 1 | 1,697,452 | null | 1 | 1 |
from copy import deepcopy
HEIGHT, WIDTH, K = map(int, input().split())
CELLS = [list(input()) for i in range(HEIGHT)]
ans = 0
for maskY in range(1<<HEIGHT):
for maskX in range(1<<WIDTH):
black=0
for y in range(HEIGHT):
for x in range(WIDTH):
if (maskY >> y & 1) == 0 and (maskX >> x & 1) == 0 and CELLS[y][x] == '#':
black+=1
if K == black:
ans+=1
print(ans)
| def main():
H, W, K = [int(k) for k in input().split(" ")]
C = []
black_in_row = []
black_in_col = [0] * W
for i in range(H):
C.append(list(input()))
black_in_row.append(C[i].count("#"))
for j in range(W):
if C[i][j] == "#":
black_in_col[j] += 1
black = sum(black_in_row)
if black < K:
print(0)
return 0
cnt = 0
for i in range(2 ** H):
row_bit = [f for f, b in enumerate(list(pad_zero(format(i, 'b'), H))) if b == "1"]
r = sum([black_in_row[y] for y in row_bit])
for j in range(2 ** W):
col_bit = [f for f, b in enumerate(list(pad_zero(format(j, 'b'), W))) if b == "1"]
c = sum([black_in_col[x] for x in col_bit])
bl = black - r - c + sum([1 for p in row_bit for q in col_bit if C[p][q] == "#"])
if bl == K:
cnt += 1
print(cnt)
def pad_zero(s, n):
s = str(s)
return ("0" * n + s)[-n:]
main() | 1 | 8,954,091,075,580 | null | 110 | 110 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
answers = ["Yes" if A[i] > A[i-K] else "No" for i in range(K, N)]
print("\n".join(answers)) | N = int(input())//2
S = input()
print('Yes' if S[:N] == S[N:] else 'No') | 0 | null | 76,983,403,234,528 | 102 | 279 |
data = input().split()
print(' '.join(map(str, sorted(data)))) | def i():
return int(input())
def i2():
return map(int,input().split())
def s():
return str(input())
def l():
return list(input())
def intl():
return list(int(k) for k in input().split())
n = i()
a = [int(i) for i in input().split()]
cnt = 1
ans = 0
for i in range(n):
if a[i] == cnt:
cnt += 1
else:
ans += 1
if cnt == 1:
print(-1)
else:
print(ans)
| 0 | null | 57,691,303,455,070 | 40 | 257 |
def first_three(str):
return str[:3] if len(str) > 3 else str
val = input()
print(first_three(val)) | full = input()
num = 0
for i in full:
if num < 3:
num += 1
print(i, end="") | 1 | 14,766,499,954,208 | null | 130 | 130 |
s = input()
print('No' if s.count('A') > 2 or s.count('B') > 2 else 'Yes') | # -*- coding: utf-8 -*-
def main():
S = input()
listS = S.split()
if S[0] == S[1] and S[1] == S[2]:
ans = 'No'
else:
ans = 'Yes'
print(ans)
if __name__ == "__main__":
main() | 1 | 54,917,752,323,082 | null | 201 | 201 |
x,y = map(int,input().split())
#xใใใผในใซ
r = 0 #โ2 โ1
u = x #โ1 โ2
while y != r + u*2:
u -= 2
r += 1
if u < 0: #ๅฐ้ใใๆนๆณใใชใ
print(0)
exit()
#modใใใฎใณใณใใใผใทใงใณ่จ็ฎ
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9 + 7
N = u+r+1 #ๅฟ
่ฆใชๆฐ
g1 = [1, 1] # ๅ
ใใผใใซ
g2 = [1, 1] #้ๅ
ใใผใใซ
inverse = [0, 1] #้ๅ
ใใผใใซ่จ็ฎ็จใใผใใซ
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
print(cmb(u+r,r,mod))
| def bigcmb(N, R, MOD):
if (R < 0) or (N < R):
return 0
R = min(R, N - R)
fact, inv = 1, 1
for i in range(1, R + 1):
fact = (fact * (N - i + 1)) % MOD
inv = (inv * i) % MOD
return fact * pow(inv, MOD - 2, MOD) % MOD
X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
print(0)
exit()
mod = 10**9 + 7
count = (X + Y) // 3
ans = bigcmb(count, X - count, mod)
print(ans) | 1 | 150,031,399,963,772 | null | 281 | 281 |
from collections import deque
def run_process(processes, slot):
"""Simulate the round-robin scheduler.
Returns a list of (process, elapsed_time).
>>> ps = [('p1', 150), ('p2', 80), ('p3', 200), ('p4', 350), ('p5', 20)]
>>> run_process(ps, 100)
[('p2', 180), ('p5', 400), ('p1', 450), ('p3', 550), ('p4', 800)]
"""
ps = deque(processes)
tot = 0
finish = []
while len(ps) > 0:
p, t = ps.popleft()
dt = min(t, slot)
if dt == t:
finish.append((p, tot+dt))
else:
ps.append((p, t-dt))
tot += dt
return finish
def run():
count, slot = [int(i) for i in input().split()]
ps = []
for _ in range(count):
p, t = input().split()
ps.append((p, int(t)))
for p, t in run_process(ps, slot):
print(p, t)
if __name__ == '__main__':
run()
| n,q = map(int,input().split())
A = []
B = []
C = []
t = 0
for i in range(n):
x,y = input().split()
A.append([x,int(y)])
while len(A)>0:
f = A[0][1]
if f<=q:
t += f
B.append(A[0][0])
C.append(t)
else:
t += q
A[0][1] -= q
A.append(A[0])
A.pop(0)
for j in range(len(B)):
print(B[j],C[j])
| 1 | 40,831,878,162 | null | 19 | 19 |
ans = []
for i, x in enumerate(open(0).readlines()):
ans.append("Case %d: %s" % (i+1, x))
open(1,'w').writelines(ans[:-1])
| import sys
sys.setrecursionlimit(1000000)
n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)
edge=[[] for i in range(n)]
k=0
for i in range(n-1):
a[i],b[i]=map(int,input().split())
a[i]-=1
b[i]-=1
edge[b[i]].append(a[i])
edge[a[i]].append(b[i])
color_dict={}
def dfs(x, last=-1, ban_color=-1):
global k
color=1
for to in edge[x]:
if to==last:
continue
if color==ban_color:
color+=1
color_dict[(x,to)]=color
k=max(k,color)
dfs(to,x,color)
color+=1
dfs(0)
print(k)
for i in range(n-1):
if (a[i],b[i]) in color_dict:
print(color_dict[(a[i],b[i])])
else:
print(color_dict[(b[i],a[i])]) | 0 | null | 68,245,339,704,840 | 42 | 272 |
from typing import List, Dict
INF = 10**9+1
def read_int() -> int:
return int(input().strip())
def read_ints() -> List[int]:
return list(map(int, input().strip().split(' ')))
def solve() -> int:
H, W = read_ints()
S: List[str] = []
for _ in range(H):
S.append(input().strip())
black_count = [[INF for _ in range(W)] for _ in range(H)]
if S[0][0] == '.':
black_count[0][0] = 0
else:
black_count[0][0] = 1
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
continue
if S[i][j] == '.':
if i > 0:
black_count[i][j] = min(black_count[i][j], black_count[i-1][j])
if j > 0:
black_count[i][j] = min(black_count[i][j], black_count[i][j-1])
else:
if i > 0:
if S[i-1][j] == '.':
black_count[i][j] = min(black_count[i][j], black_count[i-1][j]+1)
else:
black_count[i][j] = min(black_count[i][j], black_count[i-1][j])
if j > 0:
if S[i][j-1] == '.':
black_count[i][j] = min(black_count[i][j], black_count[i][j-1]+1)
else:
black_count[i][j] = min(black_count[i][j], black_count[i][j-1])
return black_count[H-1][W-1]
if __name__ == '__main__':
print(solve())
| H, W = map(int, input().split())
S = [input() for _ in range(H)]
vis = [[-1 for i in range(W)] for j in range(H)]
for v in range(H):
for h in range(W):
if v==0:
if h==0:
if S[v][h]=="#":
vis[v][h]=1
else:
vis[v][h]=0
else:
if S[v][h-1]=="." and S[v][h]=="#":
vis[v][h] = vis[v][h-1] + 1
else:
vis[v][h] = vis[v][h-1]
else:
if h==0:
if S[v-1][h]=="." and S[v][h]=="#":
vis[v][h] = vis[v-1][h] + 1
else:
vis[v][h] = vis[v-1][h]
else:
if S[v-1][h]=="." and S[v][h]=="#":
bufv = vis[v-1][h] + 1
else:
bufv = vis[v-1][h]
if S[v][h-1]=="." and S[v][h]=="#":
bufh = vis[v][h-1] + 1
else:
bufh = vis[v][h-1]
vis[v][h] = min(bufv, bufh)
#print(vis)
print(vis[H-1][W-1]) | 1 | 49,386,382,922,240 | null | 194 | 194 |
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans, cnt = 1, [0, 0, 0]
for i in a:
ans = ans * cnt.count(i) % mod
for j in range(3):
if cnt[j] == i:
cnt[j] += 1
break
print(ans)
| from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
a = LIST()
ans = 1
r = 0
g = 0
b = 0
for x in a:
ans = ans * ( (r == x) + (g == x) + (b == x) ) % (10**9+7)
if r == x:
r += 1
elif g == x:
g += 1
else:
b += 1
print(ans) | 1 | 130,201,354,252,960 | null | 268 | 268 |
import math
a, b, h, m = map(int,input().split())
time = h * 60 + m
ta = time * 2 * math.pi / (12 * 60)
tb = time * 2 * math.pi / 60
xa = a * math.sin(ta)
ya = a * math.cos(ta)
xb = b * math.sin(tb)
yb = b * math.cos(tb)
ans = math.sqrt((xa-xb)**2 + (ya-yb)**2)
print(ans) | n = input()
m = len(n)
x = 0
for i in range(m):
x += int(n[i])
print("Yes" if x % 9 == 0 else "No") | 0 | null | 12,153,900,015,850 | 144 | 87 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.