Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
class SegmentTree:
    seg_len = 1
    node = []
    def __init__(self, n):
        while self.seg_len < n:
            self.seg_len <<= 1
        self.node = [ 0 for _ in range(self.seg_len*2) ]

    def add(self, idx, v):
        idx += self.seg_len
        self.node[idx] += v
        while True:
            idx //= 2
            if idx == 0:
                break
            self.node[idx] = self.node[idx*2] + self.node[idx*2+1]

    def sum(self, l, r):
        l += self.seg_len
        r += self.seg_len
        ret = 0
        while l < r:
            if l & 1 == 1:
                ret += self.node[l]
                l += 1
            if r & 1 == 1:
                ret += self.node[r-1]
                r -= 1
            l //= 2; r //= 2;
        return ret


n, k = map(int, input().split())
p = [ int(x) for x in input().split() ]

seg_tree = SegmentTree(n)
for i in range(n):
    seg_tree.add(i, (1+p[i])/2)

ans = 0
for i in range(n-k+1):
    ans = max(ans, seg_tree.sum(i, i+k))

print(ans)

Fixed submission:
n, k = map(int, input().split())
p = [ int(x) for x in input().split() ]
s = [ 0 ]

for key, v in enumerate(p):
    t = (v+1)*v//2/v
    s.append(s[key] + t)

ans = -1

for i in range(n-k+1):
    v = s[i+k]-s[i]
    ans = max(ans, v)

print(ans)

Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

template <class T>
struct BIT {
  std::vector<T> bit;
  BIT(int n) : bit(n+1, 0) {}
  void add(int x, const T &w) {
    for (int i = x; i < bit.size()-1; i |= (i+1)) {
      bit[i] += w;
    }
  }
  T sum(int r) {
    T ret = 0;
    for (int i = r-1; i >= 0; i = (i & (i+1)) - 1) {
      ret += bit[i];
    }
    return ret;
  }
  T sum(int l, int r) { return sum(r) - sum(l); }
};

int main() {
  int n, k; cin >> n >> k;
  BIT<double> tree(n);
  for (int i = 0; i < n; i++) {
    int p; cin >> p;
    tree.add(i, (1 + p) / 2.0);
  }
  double ans = 0.0;
  for (int i = 0; i + k <= n; i++) {
    ans = max(ans, tree.sum(i, i+k));
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
n, k = map(int, input().split())
p = [ int(x) for x in input().split() ]
s = [ 0 ]

for key, v in enumerate(p):
    t = (v+1)*v//2/v
    s.append(s[key] + t)

ans = -1

for i in range(n-k+1):
    v = s[i+k]-s[i]
    ans = max(ans, v)

print(ans)
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end(), greater<int>());

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i < k) {
      ans++;
    } else {
      ans += h[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#!/usr/bin/env python3

n, k = map(int, input().split())
h = sorted(map(int, input().split()), reverse=True)

print(sum(h[k:]))
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
A = map(int, raw_input().split())
 
MOD = 10 ** 9 + 7

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x/gcd(x, y)*y
 
l = A[0]
for a in A:
    l = lcm(l, a)
 
res = 0

for a in A:
    res = (res + l // a) % MOD

print(res)



Fixed submission:
N = input()
A = map(int, raw_input().split())
 
MOD = 10 ** 9 + 7

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x/gcd(x, y)*y
 
l = A[0]
for a in A:
    l = lcm(l, a)
 
res = 0
for a in A:
    res = (res + (l * pow(a, MOD - 2, MOD)) % MOD) % MOD
 
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
A = map(int, raw_input().split())
 
MOD = 10 ** 9 + 7

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x/gcd(x, y)*y
 
l = A[0]
for a in A:
    l = lcm(l, a)
 
res = 0

for a in A:
    res = (res + l / a) % MOD

print(res)



Fixed submission:
N = input()
A = map(int, raw_input().split())
 
MOD = 10 ** 9 + 7

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x/gcd(x, y)*y
 
l = A[0]
for a in A:
    l = lcm(l, a)
 
res = 0
for a in A:
    res = (res + (l * pow(a, MOD - 2, MOD)) % MOD) % MOD
 
print(res)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

MOD = int(1e9)+7

def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a%b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m+x%m) % m


n, k = map(int, input().split())

maxf = 2*n + 10
f = [1 for _ in range(maxf)]
invf = [1 for _ in range(maxf)]

for i in range(1, maxf):
    f[i] = (i * f[i - 1]) % MOD
 
invf[maxf-1] = pow(f[maxf - 1], MOD-2, MOD)
for i in range(maxf-1, 0, -1):
    invf[i-1] = (i*invf[i]) % MOD
 
def comb(a, b):
    if b > a:
        return 0
    return (((f[a]*invf[b]) % MOD) * invf[a-b]) % MOD

a = [ int(x) for x in input().split() ]
a.sort(reverse=True)

ans = 0

for i, v in enumerate(a):
    ans += v*comb(n-i-1, k-1)
    ans %= MOD
    ans -= v*comb(i, k-1)
    ans %= MOD
    
print(ans)



Fixed submission:
N = input()
A = map(int, raw_input().split())
 
MOD = 10 ** 9 + 7

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x/gcd(x, y)*y
 
l = A[0]
for a in A:
    l = lcm(l, a)
 
res = 0
for a in A:
    res = (res + (l * pow(a, MOD - 2, MOD)) % MOD) % MOD
 
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a%b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m+x%m) % m


def mod_comb(n, k, mod):
    mul, div = 1, 1
    for i in range(k):
        mul *= (n-i)
        div *= (i+1)
        mul %= mod
        div %= mod
    return mul * mod_inverse(div, mod) % mod


n, k = map(int, input().split())
a = [ int(x) for x in input().split() ]
a.sort(reverse=True)

mod = int(1e9)+7
ans = 0

for i, v in enumerate(a):
    ans += v*mod_comb(n-i-1, k-1, mod)
    ans %= mod
    ans -= v*mod_comb(i, k-1, mod)
    ans %= mod
    
print(ans)


Fixed submission:
#!/usr/bin/env python3

MOD = int(1e9)+7

def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a%b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m+x%m) % m


n, k = map(int, input().split())

maxf = 2*n + 10
f = [1 for _ in range(maxf)]
invf = [1 for _ in range(maxf)]

for i in range(1, maxf):
    f[i] = (i * f[i - 1]) % MOD
 
invf[maxf-1] = pow(f[maxf - 1], MOD-2, MOD)
for i in range(maxf-1, 0, -1):
    invf[i-1] = (i*invf[i]) % MOD
 
def comb(a, b):
    if b > a:
        return 0
    return (((f[a]*invf[b]) % MOD) * invf[a-b]) % MOD

a = [ int(x) for x in input().split() ]
a.sort(reverse=True)

ans = 0

for i, v in enumerate(a):
    ans += v*comb(n-i-1, k-1)
    ans %= MOD
    ans -= v*comb(i, k-1)
    ans %= MOD
    
print(ans)
Buggy python submission (verdict: Runtime Error):
#include <iostream>

using namespace std;

bool is_prime(long long x) {
  for (long long i = 2; i*i <= x; i++) {
    if (x % i == 0) { return false; }
  }
  return x != 1;
}

int main() {
  int x; cin >> x;

  for (int i = x; ; i++) {
    if (is_prime(i)) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#!/usr/bin/env python3

def is_prime(x):
    i = 2
    while i*i <= x:
        if x%i == 0: return False
        i += 1
    return x != 1

x = int(input())

while True:
    if is_prime(x):
        print(x)
        break
    x += 1
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input.split())
if a < 10 and b < 10:
  print(a*b)
else:
  print(-1)

Fixed submission:
a, b = map(int, input().split())
if a < 10 and b < 10:
  print(a*b)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret, p = [], 2

    while p*p <= n:
        if n % p != 0:
            p += 1
            continue

        exp_v = 0
        while n%p == 0:
            exp += 1
            n //= p
        ret.append( [ret, exp_v] )

        p += 1

    if n != 1: ret.append( [n, 1] )

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)

Fixed submission:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1

    if n != 1: ret[n] = 1

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p

    if n != 1: ret[n] = 1

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)


Fixed submission:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1

    if n != 1: ret[n] = 1

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)
Buggy python submission (verdict: Runtime Error):
s = input()
is_ok = True
for i in range(len(s)):
    if i % 2 == 0 and s[i] == "L":
        is_ok = False
        break
    if i % 2 == 1 and s[i] == "R":
        is_ok = False
        break
print("Yes" is_ok else "No")

Fixed submission:
s = input()
is_ok = True
for i in range(len(s)):
    if i % 2 == 0 and s[i] == "L":
        is_ok = False
        break
    if i % 2 == 1 and s[i] == "R":
        is_ok = False
        break
print("Yes" if is_ok else "No")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()
ret = ""

ini = s[0]
ret += ini

is_renzoku = False

for key, v in enumerate(s):
    if key == 0:
        continue
    if v != ini and k != 0:
        is_renzoku = True
        if v == "R":
            ret += "L"
        else:
            ret += "R"
    else:
        if is_renzoku:
            k -= 1
        is_renzoku = False
        ret += v

ans = 0
for key, v in enumerate(ret):
    if key == 0: continue
    if v == ret[key-1]: ans += 1

print(ans)


Fixed submission:
n, k = map(int, input().split())
s = input()
ret = ""

ini = s[0]
ret += ini

is_renzoku = False

for key, v in enumerate(s):
    if key == 0:
        continue
    if v != ini and k != 0:
        is_renzoku = True
        if v == "R":
            ret += "L"
        else:
            ret += "R"
    else:
        if is_renzoku:
            k -= 1
        is_renzoku = False
        ret += v

ans = 0
for key, v in enumerate(ret):
    if key == 0: continue
    if v == ret[key-1]: ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()
ret = ""

ini = s[0]
ret += ini

is_renzoku = False

for key, v in enumerate(s):
    if key == 0:
        continue
    if v != ini and k != 0:
        is_renzoku = True
        if v == "R":
            ret += "L"
        else:
            ret += "R"
    else:
        if is_renzoku:
            k -= 1
        is_renzoku = False
        ret += v

ans = 0
for key, v in enumerate(ret):
    if key == 0: continue
    if v == ret[key-1]: ans += 1

print(ans)


Fixed submission:
n, k = map(int, input().split())
s = input()
ret = ""

ini = s[0]
ret += ini

is_renzoku = False

for key, v in enumerate(s):
    if key == 0:
        continue
    if v != ini and k != 0:
        is_renzoku = True
        if v == "R":
            ret += "L"
        else:
            ret += "R"
    else:
        if is_renzoku:
            k -= 1
        is_renzoku = False
        ret += v

ans = 0
for key, v in enumerate(ret):
    if key == 0: continue
    if v == ret[key-1]: ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
def main(): 
    n = int(input())
    a = [ int(x) for x in input().split() ]

    d = {}
    for aa in a:
        d[aa] = d.get(aa, 0) + 1

    if d.get(0, 0) == n:
        print("Yes")
        return 0
    L = sorted(list(d.items()))
    if n % 3 == 0 and len(L) == 2 and (L[0][0] == 0 and L[0][1] == n//3) and L[1][1] == n//3*2:
        print("Yes")
        return 0
    
    if n % 3 == 0 and len(L) == 3 and L[0][1] == n//3 and L[1][1] == n//3 and :[2][1] == n//3 and L[0][0]^L[1][0]^L[2][0] == 0:
        print("Yes")
        return 0

    print("No")

main()


Fixed submission:
def main(): 
    n = int(input())
    a = [ int(x) for x in input().split() ]

    d = {}
    for aa in a:
        d[aa] = d.get(aa, 0) + 1

    if d.get(0, 0) == n:
        print("Yes")
        return 0
    L = sorted(list(d.items()))
    if n % 3 == 0 and len(L) == 2 and (L[0][0] == 0 and L[0][1] == n//3) and L[1][1] == n//3*2:
        print("Yes")
        return 0
    
    if n % 3 == 0 and len(L) == 3 and L[0][1] == n//3 and L[1][1] == n//3 and L[2][1] == n//3 and L[0][0]^L[1][0]^L[2][0] == 0:
        print("Yes")
        return 0

    print("No")

main()
Buggy python submission (verdict: Runtime Error):
s = input()
d = {}
for ss in s:
    d[ss] = d.get(ss, 0) + 1

print("Yes" if len(d) == 2 and d.items()[0][1] == 2 else "No")

Fixed submission:
s = input()
d = {}
for ss in s:
    d[ss] = d.get(ss, 0) + 1

print("Yes" if len(d) == 2 and list(d.items())[0][1] == 2 else "No")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

n, m = map(int, input().split())
a = [ -int(x) for x in input().split() ]
bc = []
heapq.heapify(a)

for _ in range(m):
    b, c = map(int, input().split())
    bc += [ (b, c) ]

bc.sort(key=lambda x: -x[1])
min_a = min(a)

for b, c in bc:
    if c < min_a:
        min_a = c
        continue
    for _ in range(b):
        heapq.heappush(a, -c)

ans = 0
for i in range(n):
    t = (-heapq.heappop(a))
    ans += t
print(ans)



Fixed submission:
n, m = map(int, input().split())
a = sorted([ int(x) for x in input().split() ], reverse=True)
bc = []

for _ in range(m):
    b, c = map(int, input().split())
    bc += [ (b, c) ]

bc.sort(key=lambda x: -x[1])
i, j, cnt, ans = 0, 0, 0, 0

while cnt < n:
    if j < m and a[i] < bc[j][1]:
        b, c = bc[j]
        ans += c * min(n-cnt, b)
        j += 1
        cnt += b
    else:
        ans += a[i]
        i += 1
        cnt += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ba, xa, bx = 0, 0, 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        ba += 1
    if s[0] == "B" and s[-1] != "A":
        bx += 1
    if s[0] != "B" and s[-1] == "A":
        xa += 1

if xa == 0 and bx == 0:
    ans += max(0, ba-1)
else:
    ans += ba
    ans += min(xa, bx)

print(ans)

Fixed submission:
n = int(input())
ans, ba, xa, bx = 0, 0, 0, 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        ba += 1
    if s[0] == "B" and s[-1] != "A":
        bx += 1
    if s[0] != "B" and s[-1] == "A":
        xa += 1

if xa == 0 and bx == 0:
    ans += max(0, ba-1)
else:
    ans += ba
    ans += min(xa, bx)

print(ans)
Buggy python submission (verdict: Runtime Error):
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = input()
t = input()
sr -= 1; sc -= 1
 
L=0; R=w-1; U=0; D=h-1;
is_drop = False
for i in range(n)[::-1]:
    if t[i] == 'U': D = min(D+1, h-1)
    if t[i] == 'D': U = max(U-1, 0)
    if t[i] == 'L': R = min(R+1, w-1)
    if t[i] == 'R': L = max(L-1, 0)
    if s[i] == 'U': U++
    if s[i] == 'D': D--
    if s[i] == 'L': L++
    if s[i] == 'R': R--
    if R < L or D < U: is_drop = True
    if (not L <= sc <= R) or (not U <= sr <= D):  is_drop = True

print( "NO" if is_drop else "YES" )


Fixed submission:
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = input()
t = input()
sr -= 1; sc -= 1
 
L=0; R=w-1; U=0; D=h-1;
is_drop = False
for i in range(n)[::-1]:
    if t[i] == 'U': D = min(D+1, h-1)
    if t[i] == 'D': U = max(U-1, 0)
    if t[i] == 'L': R = min(R+1, w-1)
    if t[i] == 'R': L = max(L-1, 0)
    if s[i] == 'U': U += 1
    if s[i] == 'D': D -= 1
    if s[i] == 'L': L += 1
    if s[i] == 'R': R -= 1
    if R < L or D < U: is_drop = True
if (not L <= sc <= R) or (not U <= sr <= D):  is_drop = True

print( "NO" if is_drop else "YES" )
Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

bc = []

for b in B:
    for c in C:
        bc.append(b+c)

bc.sort(reverse=True)
t = min(len(bc), 3333)
bc = bc[:t]
cnt = 0
cand = []

for a in A:
    cnt = 0
    for i in bc:
        cnt += 1
        cand += [a + i]
        if cnt == 3000:
            break

cand.sort(reverse=True)
cnt = 0
for i in cand:
    print(i)
    cnt += 1
    if cnt == k:
        break


Fixed submission:
x, y, z, k = map(int, input().split())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

bc = []

for b in B:
    for c in C:
        bc.append(b+c)

bc.sort(reverse=True)
t = min(len(bc), 3333)
bc = bc[:t]
cnt = 0
cand = []

for a in A:
    cnt = 0
    for i in bc:
        cnt += 1
        cand += [a + i]
        if cnt == 3000:
            break

cand.sort(reverse=True)
cnt = 0
for i in cand:
    print(i)
    cnt += 1
    if cnt == k:
        break

Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

bc = []

for b in B:
    for c in C:
        bc.append(b+c)

bc.sort(reverse=True)
cnt = 0
cand = []

for a in A:
    cnt = 0
    for i in bc:
        cnt += 1
        cand += [a + i]
        if cnt == 3000:
            break

cand.sort(reverse=True)
cnt = 0
for i in cand:
    print(i)
    cnt += 1
    if cnt == k:
        break


Fixed submission:
x, y, z, k = map(int, input().split())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

bc = []

for b in B:
    for c in C:
        bc.append(b+c)

bc.sort(reverse=True)
t = min(len(bc), 3333)
bc = bc[:t]
cnt = 0
cand = []

for a in A:
    cnt = 0
    for i in bc:
        cnt += 1
        cand += [a + i]
        if cnt == 3000:
            break

cand.sort(reverse=True)
cnt = 0
for i in cand:
    print(i)
    cnt += 1
    if cnt == k:
        break
Buggy python submission (verdict: Time Limit Exceeded):
n, lim_w = map(int, input().split())
w, v = [], []

for _ in range(n):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

# dp[i][j] := i番目までの品物を見たとき, 重さの総和がj以下となるように選んだときの価値の総和の最大値
dp = [ [0]*(lim_w+1) for _ in range(n+1) ]

for i in range(n):
    for j in range(lim_w+1):
        if j < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i])

print(dp[n][lim_w])


Fixed submission:
n, lim_w = map(int, input().split())
w, v = [], []

for _ in range(n):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

# dp[i][j] := i番目までの品物を見たとき, 重さの総和がj以下となるように選んだときの価値の総和の最大値
dp = [ [0]*(lim_w+1) for _ in range(n+1) ]

for i in range(n):
    for j in range(lim_w+1):
        if j < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i])

print(dp[n][lim_w])
Buggy python submission (verdict: Runtime Error):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while True:
        t = g**n
        if t > p: break
        if p%t == 0:
            ans = max(ans, g)
        g += 1
    print(ans)



Fixed submission:
def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1
    if n != 1: ret[n] = 1
    return ret

n, p = map(int, input().split())

primes = prime_factor(p)
ans = 1

for p, e in primes.items():
    ans *= max(1, p**(e//n))

print(ans)

Buggy python submission (verdict: Runtime Error):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while g**n <= p:
        if p % (g**n) == 0:
            ans = max(ans, g)
        g += 1
    print(ans)



Fixed submission:
def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1
    if n != 1: ret[n] = 1
    return ret

n, p = map(int, input().split())

primes = prime_factor(p)
ans = 1

for p, e in primes.items():
    ans *= max(1, p**(e//n))

print(ans)

Buggy python submission (verdict: Runtime Error):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while pow(g, n) <= p:
        if p % pow(g, n) == 0:
            ans = max(ans, g)
        g += 1
    print(ans)



Fixed submission:
def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1
    if n != 1: ret[n] = 1
    return ret

n, p = map(int, input().split())

primes = prime_factor(p)
ans = 1

for p, e in primes.items():
    ans *= max(1, p**(e//n))

print(ans)

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

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while pow(g, n) <= p:
        if p % pow(g, n) == 0:
            ans = max(ans, g)
        g += 1
    print(ans)



Fixed submission:
def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1
    if n != 1: ret[n] = 1
    return ret

n, p = map(int, input().split())

primes = prime_factor(p)
ans = 1

for p, e in primes.items():
    ans *= max(1, p**(e//n))

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
L = []
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L[-1] += len(L) 

print(sum(L))

Fixed submission:
S = input()
L = [0]
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L[-1] += len(L)-1 

print(sum(L))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
L = []
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L = [ j+1 for j in L ]

print(sum(L))

Fixed submission:
S = input()
L = [0]
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L[-1] += len(L)-1 

print(sum(L))