Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
V = list(map(int, input().split()))

rs = []
def check(k, v, current):
	global rs
	rs += [sum(current)]
	if 0 == k:
		return
	else:
		if current:
			mc = min(current)
			if mc < 0:
				i = current.index(mc)
				check(k - 1, v + [mc], current[:i] + current[i + 1:])
				check(k - 1, [mc] + v, current[:i] + current[i + 1:])
		if v:
			check(k - 1, v[1:], current + [v[0]])
			check(k - 1, v[:-1], current + [v[-1]])
		return

check(K, V, [])

print(max(rs))


Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))

vmax = 0
for l in range(0, K + 1):
	for r in range(0, K - l + 1):
		if N < l + r:
			break
		tv = V[:l] + V[N - r:]
		#print(tv)
		tv.sort()
		for n in range(min(len(tv), K - (l + r))):
			if tv[n] < 0:
				tv[n] = 0
		vmax = max(vmax, sum(tv))

print(vmax)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = list(map(int, input().split()))

rs = [0]
def check(k, v, current):
	global rs
	rs += [sum(current)]
	if 0 == k:
		return
	else:
		if current:
			i = current.index(min(current))
			check(k - 1, v + [min(current)], current[:i] + current[i + 1:])
			check(k - 1, [min(current)] + v, current[:i] + current[i + 1:])
		check(k - 1, v[1:], current + [v[0]])
		check(k - 1, v[:-1], current + [v[-1]])
		return

check(K, V, [])

print(max(rs))


Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))

vmax = 0
for l in range(0, K + 1):
	for r in range(0, K - l + 1):
		if N < l + r:
			break
		tv = V[:l] + V[N - r:]
		#print(tv)
		tv.sort()
		for n in range(min(len(tv), K - (l + r))):
			if tv[n] < 0:
				tv[n] = 0
		vmax = max(vmax, sum(tv))

print(vmax)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

cards = A.copy()
for b, c in BC:
	cards += [c] * b

print(sum((sorted(cards)[::-1])[:N]))


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

am = {}
for a in A:
	if not a in am:
		am[a] = 1
	else:
		am[a] += 1

for b, c in BC:
	if not c in am:
		am[c] = b
	else:
		am[c] += b

al = sorted(am)[::-1]

c, v = N, 0
for k in al:
	if am[k] < c:
		c -= am[k]
		v += am[k] * k
	else:
		v += c * k
		break

print(v)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

for b, c in BC:
	A += [c] * b

A.sort()

print(sum(A[-N:]))


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

am = {}
for a in A:
	if not a in am:
		am[a] = 1
	else:
		am[a] += 1

for b, c in BC:
	if not c in am:
		am[c] = b
	else:
		am[c] += b

al = sorted(am)[::-1]

c, v = N, 0
for k in al:
	if am[k] < c:
		c -= am[k]
		v += am[k] * k
	else:
		v += c * k
		break

print(v)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

a = sorted(A)

for b, c in BC:
	for i in range(b):
		if a[i] < c:
			a[i] = c
		else:
			break
	a = sorted(a)

print(sum(a))


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

am = {}
for a in A:
	if not a in am:
		am[a] = 1
	else:
		am[a] += 1

for b, c in BC:
	if not c in am:
		am[c] = b
	else:
		am[c] += b

al = sorted(am)[::-1]

c, v = N, 0
for k in al:
	if am[k] < c:
		c -= am[k]
		v += am[k] * k
	else:
		v += c * k
		break

print(v)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

r = 0
def func(n):
	c, t = 0, n
	while t <= K:
		t <<= 1
		c += 1
	#return (1 / 2) ** c
	return c
"""
for n in range(N):
	#r += [func(n)]
	r += 2 ** n
	#print(r)
"""

base = func(1)

r = int("1" * (base - 1), 2)
#print(r)

print(r * ((1 / 2) ** base) / N)


Fixed submission:
N, K = map(int, input().split())

r = 0
for n in range(1, N + 1):
	c, t = 0, n
	while t < K:
		t *= 2
		c += 1
	r += (1 / N) * (1 / 2) ** c
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

c = 0
for r in range(N + 1):
	if N < r * R:
		break
	for g in range(N + 1):
		if N < r * R + g * G:
			break
		x = (N - r * R - g * G)
		if not x % B and (0 <= (x // B)):
			#print(r, g, b)
			c += 1
print(c)


Fixed submission:
R, G, B, N = map(int, input().split())

c = 0
for r in range(0, N + 1, R):
	for g in range(0, N + 1, G):
		if N < r + g:
			break
		d = N - r - g
		if not d % B:
			c += 1
	
"""
	for g in range(N + 1):
		if N < r * R + g * G:
			break
		x = (N - r * R - g * G)
		if not (x % B) and (0 <= (x // B)):
			#print(r, g, b)
			c += 1
"""
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

c = 0
for r in range(N + 1):
	for g in range(N + 1):
		if N < r * R + g * G:
			break
		f = (N - r * R - g * G) % B
		b = (N - r * R - g * G) // B
		if not f and (0 <= b) and (N == (r * R + g * G + b * B)): 
			#print(r, g, b)
			c += 1
print(c)


Fixed submission:
R, G, B, N = map(int, input().split())

c = 0
for r in range(0, N + 1, R):
	for g in range(0, N + 1, G):
		if N < r + g:
			break
		d = N - r - g
		if not d % B:
			c += 1
	
"""
	for g in range(N + 1):
		if N < r * R + g * G:
			break
		x = (N - r * R - g * G)
		if not (x % B) and (0 <= (x // B)):
			#print(r, g, b)
			c += 1
"""
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

c = 0
for r in range(N + 1):
	for g in range(N + 1):
		f = (N - r * R - g * G) % B
		b = (N - r * R - g * G) // B
		if not f and (0 <= b) and (N == (r * R + g * G + b * B)): 
			#print(r, g, b)
			c += 1
print(c)


Fixed submission:
R, G, B, N = map(int, input().split())

c = 0
for r in range(0, N + 1, R):
	for g in range(0, N + 1, G):
		if N < r + g:
			break
		d = N - r - g
		if not d % B:
			c += 1
	
"""
	for g in range(N + 1):
		if N < r * R + g * G:
			break
		x = (N - r * R - g * G)
		if not (x % B) and (0 <= (x // B)):
			#print(r, g, b)
			c += 1
"""
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
STAGE = [list(input()) for _ in range(H)]

black, white = [], 0
for y, line in enumerate(STAGE):
	for x, cell in enumerate(line):
		if "#" == cell:
			black += [(y, x)]
		else:
			white += 1

stage = STAGE
ds = ((0, 1), (1, 0), (0, -1), (-1, 0))

def get_next(p, d):
	n = (p[0] + d[0], p[1] + d[1])
	if 0 <= n[0] < H and 0 <= n[1] < W:
		return n
	return None

def set_val(p, v):
	global stage
	stage[p[0]][p[1]] = v

def get_val(p):
	return stage[p[0]][p[1]]

count = 0
while white:
	count += 1
	next_black = []
	for b in black:
		for d in ds:
			n = get_next(b, d)
			if n:
				v = get_val(n)
				if "." == v:
					white -= 1
					set_val(n, "#")
					next_black += [n]
	black = next_black

print(count)


Fixed submission:
H, W = map(int, input().split())
STAGE = [list(input()) for _ in range(H)]

black, white = [], 0
for y, line in enumerate(STAGE):
	for x, cell in enumerate(line):
		if "#" == cell:
			black += [(y, x)]
		else:
			white += 1

stage = STAGE
ds = ((0, 1), (1, 0), (0, -1), (-1, 0))

def get_next(p, d):
	n = (p[0] + d[0], p[1] + d[1])
	if 0 <= n[0] < H and 0 <= n[1] < W:
		return n
	return None

def set_val(p, v):
	global stage
	stage[p[0]][p[1]] = v

def get_val(p):
	return stage[p[0]][p[1]]

count = 0
while white:
	count += 1
	next_black = []
	for b in black:
		for d in ds:
			n = get_next(b, d)
			if n:
				v = get_val(n)
				if "." == v:
					white -= 1
					set_val(n, "#")
					next_black += [n]
	black = next_black

print(count)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
STAGE = [list(input()) for _ in range(H)]

black, white = [], 0
for y, line in enumerate(STAGE):
	for x, cell in enumerate(line):
		if "#" == cell:
			black += [(y, x)]
		else:
			white += 1

stage = STAGE.copy()
ds = ((0, 1), (1, 0), (0, -1), (-1, 0))

def get_next(p, d):
	n = (p[0] + d[0], p[1] + d[1])
	if 0 <= n[0] < H and 0 <= n[1] < W:
		return n
	return None

def set_val(p, v):
	global stage
	stage[p[0]][p[1]] = v

def get_val(p):
	return stage[p[0]][p[1]]

count = 0
while white:
	count += 1
	next_black = []
	for b in black:
		for d in ds:
			n = get_next(b, d)
			if n:
				v = get_val(n)
				if "." == v:
					white -= 1
					set_val(n, "#")
					next_black += [n]
	black = next_black

print(count)


Fixed submission:
H, W = map(int, input().split())
STAGE = [list(input()) for _ in range(H)]

black, white = [], 0
for y, line in enumerate(STAGE):
	for x, cell in enumerate(line):
		if "#" == cell:
			black += [(y, x)]
		else:
			white += 1

stage = STAGE
ds = ((0, 1), (1, 0), (0, -1), (-1, 0))

def get_next(p, d):
	n = (p[0] + d[0], p[1] + d[1])
	if 0 <= n[0] < H and 0 <= n[1] < W:
		return n
	return None

def set_val(p, v):
	global stage
	stage[p[0]][p[1]] = v

def get_val(p):
	return stage[p[0]][p[1]]

count = 0
while white:
	count += 1
	next_black = []
	for b in black:
		for d in ds:
			n = get_next(b, d)
			if n:
				v = get_val(n)
				if "." == v:
					white -= 1
					set_val(n, "#")
					next_black += [n]
	black = next_black

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ab = []
for a in A:
	for b in B:
		ab += [a + b]

ab3000 = sorted(ab)[::-1][:3000]

abc = []
for ab in ab3000:
	for c in C:
		abc += [ab + c]

abc.sort(reverse=True)

for k in range(K):
	print(abc[k])


Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ab = []
for a in A:
	for b in B:
		ab += [a + b]

ab3000 = sorted(ab)[::-1][:3000]

abc = []
for ab in ab3000:
	for c in C:
		abc += [ab + c]

abc.sort(reverse=True)

for k in range(K):
	print(abc[k])
Buggy python submission (verdict: Runtime Error):
S = input()
H = re.findall("[ACGT]+", S)
max_length = 0
for h in H:
	if max_length < len(h):
		max_length = len(h)
print(max_length)

Fixed submission:
import re
S = input()
H = re.findall("[ACGT]+", S)
max_length = 0
for h in H:
	if max_length < len(h):
		max_length = len(h)
print(max_length)
Buggy python submission (verdict: Runtime Error):
import re

N, Q = map(int, input().split())
S = list(input())
P = []

for _ in range(Q):
	l, r = map(int, input().split())
	P.append((l, r))

for p in P:
	s = S[p[0] - 1:p[1]]
	I = [i for i, x in enumerate(s) if x == "A"]
	if I[-1] == (len(s) - 1):
		I.pop()
	count = 0
	for i in I:
		if s[i + 1] == "C":
			count += 1
	print(count)


Fixed submission:
N, Q = map(int, input().split())
S = input()

# S         * A C * A C C
# sumlist   0 0 1 1 1 2 2
sumlist = [0]
for i in range(1, len(S)):
	sumlist.append(sumlist[-1])
	if S[i - 1] == "A" and S[i] == "C":
		sumlist[-1] += 1

query = []
for i in range(Q):
	l, r = map(int, input().split())
	query.append(dict(l=l-1, r=r-1))

for q in query:
	print(sumlist[q["r"]] - sumlist[q["l"]])

Buggy python submission (verdict: Time Limit Exceeded):
import re

N, Q = map(int, input().split())
S = input()
P = []
for _ in range(Q):
	l, r = map(int, input().split())
	P.append((l, r))
for p in P:
	#print(p)
	s = S[p[0] - 1:p[1]]
	ac = re.findall("AC", s)
	print(len(ac))
	#print(s)
	#print(ac)

Fixed submission:
N, Q = map(int, input().split())
S = input()

# S         * A C * A C C
# sumlist   0 0 1 1 1 2 2
sumlist = [0]
for i in range(1, len(S)):
	sumlist.append(sumlist[-1])
	if S[i - 1] == "A" and S[i] == "C":
		sumlist[-1] += 1

query = []
for i in range(Q):
	l, r = map(int, input().split())
	query.append(dict(l=l-1, r=r-1))

for q in query:
	print(sumlist[q["r"]] - sumlist[q["l"]])
Buggy python submission (verdict: Time Limit Exceeded):
input()
S = list(input())
count = 0
limit = 10**9 + 7
for mask in range(1, 2 << len(S)-1):
	temp = {}
	for i, v in enumerate(S):
		if 0 != mask & (1 << i):
			if v in temp:
				break
			temp[v] = True
	else:
		count += 1
		if limit <= count:
			break
print(count)


Fixed submission:
N = int(input())
S = input()

mod = 10**9+7
R = 1
for w in set(S):
	#print(w, S.count(w))
	R *= S.count(w) + 1
	R %= mod
print(R - 1)

Buggy python submission (verdict: Time Limit Exceeded):
input()
S = list(input())
count = 0
for mask in range(1, 2 << len(S)-1):
	temp = {}
	for i, v in enumerate(S):
		if 0 != mask & (1 << i):
			if v in temp:
				break
			temp[v] = True
	else:
		count += 1
print(count)


Fixed submission:
N = int(input())
S = input()

mod = 10**9+7
R = 1
for w in set(S):
	#print(w, S.count(w))
	R *= S.count(w) + 1
	R %= mod
print(R - 1)

Buggy python submission (verdict: Time Limit Exceeded):
input()
S = list(input())
count = 0
for mask in range(1, 2 << len(S)-1):
	temp = []
	for i, v in enumerate(S):
		if 0 != mask & (1 << i):
			temp.append(v)
	if len(temp) == len(set(temp)):
		count += 1
print(count)


Fixed submission:
N = int(input())
S = input()

mod = 10**9+7
R = 1
for w in set(S):
	#print(w, S.count(w))
	R *= S.count(w) + 1
	R %= mod
print(R - 1)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

x = 0

for n in range(A, B + 1):
	#print("{:010b}".format(x))
	x ^= n

#print(x, "{:b}".format(x))
print(x)


Fixed submission:
A, B = map(int, input().split())

r = 0
def F(n):
	ec = (n + 1) // 2
	r = ec % 2
	if not n % 2:
		r ^= n
	return r
"""
def F2(n):
	r = 0
	for i in range(n + 1):
		r ^= i
	return r
"""
#print("{:04b}".format(F2(4)))
print(F(A - 1) ^ F(B))
Buggy python submission (verdict: Runtime Error):
import sys

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)

# エントリーポイント
def main():
    N = parse(int)
    H = (0, *map(int, next(args).split()))

    c = 0
    debug(H)
    for h in range(100):
        for n in range(1, N + 1):
            if H[n - 1] - h <= 0 and 0 < H[n] - h:
                c += 1
    print(c)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()


Fixed submission:
N = int(input())
H = list(map(int, input().split()))

h = [0] + H
c = 0
for i in range(1, 100 + 1):
	for j in range(1, N + 1):
		if h[j - 1] < i and i <= h[j]:
			c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
    for j in range(max(i - k, 0), i):
        np = dp[j] + abs(h[i] - h[j])
        if np < dp[i]:
            dp[i] = np 

print(dp[n - 1])


Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 18

h = H
dp = [0] * N

for n in range(1, N):
	l, r = max(0, n - K), n
	dp[n] = min([dpl + abs(hl - h[r]) for dpl, hl in zip(dp[l:r], h[l:r])])
	#print(dp)
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
    for j in range(max(i - k, 0), i):
      	np = dp[j] + abs(h[i] - h[j])
        dp[i] = dp[i] if dp[i] < np else np 

print(dp[n - 1])

Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 18

h = H
dp = [0] * N

for n in range(1, N):
	l, r = max(0, n - K), n
	dp[n] = min([dpl + abs(hl - h[r]) for dpl, hl in zip(dp[l:r], h[l:r])])
	#print(dp)
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 12
dp = [0] * N
dp[0] = 0

for n in range(1, N):
	dp[n] = dp[n - 1] + abs(H[n] - H[n - 1])
	for i in range(2, K + 1):
		if 0 <= n - i:
			dp[n] = min(dp[n], dp[n - i] + abs(H[n] - H[n - i]))
print(dp[-1])


Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 18

h = H
dp = [0] * N

for n in range(1, N):
	l, r = max(0, n - K), n
	dp[n] = min([dpl + abs(hl - h[r]) for dpl, hl in zip(dp[l:r], h[l:r])])
	#print(dp)
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 18

h = H + [0] * K
dp = [INF] * (N + K)
dp[0] = 0

for n in range(N):
	for k in range(1, K + 1):
		l, r = n, n + k
		dp[r] = min(dp[r], dp[l] + abs(h[l] - h[r]))
print(dp[N - 1])


Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 18

h = H
dp = [0] * N

for n in range(1, N):
	l, r = max(0, n - K), n
	dp[n] = min([dpl + abs(hl - h[r]) for dpl, hl in zip(dp[l:r], h[l:r])])
	#print(dp)
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 18

dp = [0] + [INF] * (N - 1)

for n in range(N):
	for k in range(1, K + 1):
		if N <= n + k:
			break
		dp[n + k] = min(dp[n + k], dp[n] + abs(H[n] - H[n + k]))
		#print(dp)
print(dp[N - 1])


Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 18

h = H
dp = [0] * N

for n in range(1, N):
	l, r = max(0, n - K), n
	dp[n] = min([dpl + abs(hl - h[r]) for dpl, hl in zip(dp[l:r], h[l:r])])
	#print(dp)
print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
def main():
	S, T = input(), input()

	Z = 20 # 3010
	dp = [[0] * Z for _ in range(Z)]
	for i in range(len(S)):
		for j in range(len(T)):
			if S[i] == T[j]:
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])

	#for line in dp:
	#	print(line)
	#print(dp[len(S)][len(T)])
	i, j, result = len(S), len(T), ""
	while 0 < i and 0 < j:
		if dp[i][j] == dp[i - 1][j]:
			i -= 1
		elif dp[i][j] == dp[i][j - 1]:
			j -= 1
		else:
			result = S[i - 1] + result
			i -= 1
			j -= 1
	print(result)

main()


Fixed submission:
def main():
	S, T = input(), input()

	Z = 3010
	dp = [[0] * Z for _ in range(Z)]
	for i in range(len(S)):
		for j in range(len(T)):
			if S[i] == T[j]:
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])

	#for line in dp:
	#	print(line)
	#print(dp[len(S)][len(T)])
	i, j, result = len(S), len(T), ""
	while 0 < i and 0 < j:
		if dp[i][j] == dp[i - 1][j]:
			i -= 1
		elif dp[i][j] == dp[i][j - 1]:
			j -= 1
		else:
			result = S[i - 1] + result
			i -= 1
			j -= 1
	print(result)

main()
Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())

def solve(a):
	l = {}
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	else:
		if count:
			l[2] = count

	for n in range(3, a // 2 + 1, 2):
		if a == 1:
			return l
		if a < n:
			l[a] = 1
			return l

		count = 0
		while 0 == a % n:
			a //= n
			count += 1
		else:
			if count:
				l[n] = count
	return l

l = solve(P)
#print(l)

keys = sorted(l, reverse=True)
r = 1
for key in keys:
	if N <= l[key]:
		r *= key ** (l[key] // N)
print(r)


Fixed submission:
N, P = map(int, input().split())

def solve(a):
	l = {}
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	else:
		if count:
			l[2] = count

	for n in range(3, int(a ** 0.5) + 1, 2):
		if a == 1:
			return l

		count = 0
		while 0 == a % n:
			a //= n
			count += 1
		else:
			if count:
				l[n] = count
	else:
		if 1 != a:
			l[a] = 1
	return l

l = solve(P)
#print(l)

keys = sorted(l, reverse=True)
r = 1
for key in keys:
	if N <= l[key]:
		r *= key ** (l[key] // N)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())

def solve(a):
	l = {}
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	else:
		if count:
			l[2] = count

	for n in range(3, a + 1, 2):
		if a == 1:
			return l

		count = 0
		while 0 == a % n:
			a //= n
			count += 1
		else:
			if count:
				l[n] = count
	return l

l = solve(P)
#print(l)

keys = sorted(l, reverse=True)
r = 1
for key in keys:
	if N <= l[key]:
		r *= key ** (l[key] // N)
print(r)


Fixed submission:
N, P = map(int, input().split())

def solve(a):
	l = {}
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	else:
		if count:
			l[2] = count

	for n in range(3, int(a ** 0.5) + 1, 2):
		if a == 1:
			return l

		count = 0
		while 0 == a % n:
			a //= n
			count += 1
		else:
			if count:
				l[n] = count
	else:
		if 1 != a:
			l[a] = 1
	return l

l = solve(P)
#print(l)

keys = sorted(l, reverse=True)
r = 1
for key in keys:
	if N <= l[key]:
		r *= key ** (l[key] // N)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, P = map(int, input().split())

def solve(a):
	l = {}
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	else:
		if count:
			l[2] = count

	for n in range(3, a + 1, 2):
		if a == 1:
			return l

		count = 0
		while 0 == a % n:
			a //= n
			count += 1
		else:
			if count:
				l[n] = count
	return l

l = solve(P)
#print(l)

keys = sorted(l, reverse=True)
r = 1
for key in keys:
	if N <= l[key]:
		r *= key ** (l[key] // N)
print(r)


Fixed submission:
N, P = map(int, input().split())

def solve(a):
	l = {}
	count = 0
	while 0 == a % 2:
		a //= 2
		count += 1
	else:
		if count:
			l[2] = count

	for n in range(3, int(a ** 0.5) + 1, 2):
		if a == 1:
			return l

		count = 0
		while 0 == a % n:
			a //= n
			count += 1
		else:
			if count:
				l[n] = count
	else:
		if 1 != a:
			l[a] = 1
	return l

l = solve(P)
#print(l)

keys = sorted(l, reverse=True)
r = 1
for key in keys:
	if N <= l[key]:
		r *= key ** (l[key] // N)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

c = 0
for i in range(357, N + 1):
	if (set(str(i)) == {"3", "5", "7"}):
		c += 1
print(c)


Fixed submission:
S = input()

def solve(s, n=0, tight=True, value=""):
	if n == len(s):
		while value and value[0] == "0":
			value = value[1:]
		if set("753") == set(value):
			#print(value)
			return 1
		return 0
	hi = int(s[n]) if tight else 9
	c = 0
	for i in range(hi + 1):
		if i in [7, 5, 3, 0]:
			c += solve(s, n + 1, tight and not(i < hi), value + str(i))
	return c

print(solve(S))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

group = [[] for _ in range(N + 1)]
for p, y in PY:
	group[p] += [y]

for g in group:
	g.sort()

for p, y in PY:
	print("{:06d}{:06d}".format(p, group[p].index(y) + 1))


Fixed submission:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

cs = {}
for p, y in PY:
	if not p in cs:
		cs[p] = [y]
	else:
		cs[p] += [y]

csm = {}
for k, v in cs.items():
	v.sort()
	csm[k] = {}
	for i, p in enumerate(v):
		csm[k][p] = i + 1

for p, y in PY:
	print("{:06d}{:06d}".format(p, csm[p][y]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

cs = {}
for p, y in PY:
	if not p in cs:
		cs[p] = [y]
	else:
		cs[p] += [y]

for v in cs.values():
	v.sort()

for p, y in PY:
	print("{:06d}{:06d}".format(p, cs[p].index(y) + 1))


Fixed submission:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

cs = {}
for p, y in PY:
	if not p in cs:
		cs[p] = [y]
	else:
		cs[p] += [y]

csm = {}
for k, v in cs.items():
	v.sort()
	csm[k] = {}
	for i, p in enumerate(v):
		csm[k][p] = i + 1

for p, y in PY:
	print("{:06d}{:06d}".format(p, csm[p][y]))