ZhenlongDai/ACPR huggingface dataset:
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
num = list(input())
num = list(map(int, num))
length = len(num)

ans = 0














for i in reversed(range(length)):
    digit = num[i]
    if digit < 5:
        ans += digit
    elif i > 0 and digit == 5 and num[i-1] < 5:
        ans += digit
    else:
        ans += (10 - digit)
        if i > 0:
            num[i-1] += 1
        else:
            ans += 1

print(ans)

Failing test case input:
476640020082194381531155118436783393866726953614433851622190777875571135215042541028243752681838573

Expected output:
259


Actual output:
260


Fixed submission (verdict: Accepted):
num = list(input())
num = list(map(int, num))
length = len(num)

ans = 0














for i in reversed(range(1, length)):
    digit = num[i]
    if digit < 5:
        ans += digit
    elif i > 0 and digit == 5 and num[i-1] < 5:
        ans += digit
    else:
        ans += (10 - digit)
        if i > 0:
            num[i-1] += 1
        else:
            ans += 1

digit = num[0]
if digit <= 5:
    ans += digit
else:
    ans += (11 - digit)

print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = ("0"+input())[::-1]

ans = 0
carry = 0
for i in range(len(N)-1):
    n = int(N[i])
    nextn = int(N[i+1])
    if carry == 1:
        carry = 0
        n += 1

    if n <=4:
        ans += n
    elif n >= 6:
        ans += 10-n
        carry = 1
    else: 
        if nextn <= 4:
            ans += n
        else:
            ans += 10-n
            carry = 1

print(ans)
    

Failing test case input:
7080342512965218976697912729659556758411438217421806030246142237833070455171621700559274830690093

Expected output:
231


Actual output:
230


Fixed submission (verdict: Accepted):
N = ("00"+input())[::-1]

ans = 0
carry = 0
for i in range(len(N)-1):
    n = int(N[i])
    nextn = int(N[i+1])
    if carry == 1:
        carry = 0
        n += 1

    if n <=4:
        ans += n
    elif n >= 6:
        ans += 10-n
        carry = 1
    else: 
        if nextn <= 4:
            ans += n
        else:
            ans += 10-n
            carry = 1

print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

Num_str = list(input().rstrip())
L = len(Num_str)
Num = []
S = 0
for n in reversed(Num_str):
    Num.append(int(n))
    S += int(n)

up = False
for n in Num:
    if up:
        n += 1
    if n == 10:
        delta = -10
    else:
        delta = 1 + (10-n) - n
    if delta <= 0:
        up = True
        S += delta
    else:
        up = False

print(S)

Failing test case input:
44874368240813931601507894871005901840929477958271152805300186433850175802887919720408971684778327

Expected output:
214


Actual output:
215


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

Num_str = list(input().rstrip())
L = len(Num_str)
Num = []

for n in reversed(Num_str):
    Num.append(int(n))

S = 0
up = False
for i, n in enumerate(Num):
    if up:
        n += 1
    if n < 5:
        S += n
        up = False
    elif n == 5:
        S += 5
        up = (i != L-1 and Num[i+1] >= 5)
    else:
        S += 10 - n
        up = True
if up:
    S += 1
print(S)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    cnt = 0
    s = 0
    y = ""
    a = ""
    for i in input()[::-1]:
        a += i
        k = int(i)
        if k + s <= 5:
            cnt += k + s
            y += str(k + s)
            s = 0
        else:
            cnt += 10 - k - s
            y += "0"
            s = 1
    if s == 1:
        y += "1"
    print(cnt + s)

if __name__ == '__main__':
    main()

Failing test case input:
150055108885121808313787958638442791484986468806888946459869089639622515098569

Expected output:
173


Actual output:
178


Fixed submission (verdict: Accepted):
def main():
    n = input()[::-1] + "0"
    s = 0
    cnt = 0
    for i, ni in enumerate(n[:-1]):
        k = int(ni) + s
        if k < 5 or k == 5 and int(n[i + 1]) < 5:
            cnt += k
            s = 0
        else:
            cnt += 10 - k
            s = 1
    cnt += s
    print(cnt)

if __name__ == '__main__':
    main()

Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



n = list(map(int, list(input())))[::-1] + [0]
sum1 = sum(n)
for i in range(len(n)-1):
    if n[i] > 5 or (n[i]==5 and n[i+1]==5):
        n[i] = 10-n[i]
        n[i+1] += 1
print(min(sum1, sum(n)))


Failing test case input:
35777234074262543307164356835532933969592337023223887910148926519144342235064759911912928955956958

Expected output:
249


Actual output:
251


Fixed submission (verdict: Accepted):



n = list(map(int, list(input())))[::-1] + [0]
sum1 = sum(n)
for i in range(len(n)-1):
    if n[i] > 5 or (n[i]==5 and n[i+1]>4):
        n[i] = 10-n[i]
        n[i+1] += 1
print(min(sum1, sum(n)))
Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=list(input())
for i in range(len(n)):
  n[i]=int(n[i])
n.reverse()
n.append(0)
ans=0
l=[]
for i in range(len(n)-1):
  if n[i]<5 or (n[i]==5 and n[i+1]<5):
    ans+=n[i]
  else:
    ans+=10-n[i]
    n[i+1]+=1
    n[i+1]%=10
ans+=n[-1]
print(ans)

Failing test case input:
17585258772958880378227301741112541508654587486939615295198240373899123309969708142159

Expected output:
195


Actual output:
194


Fixed submission (verdict: Accepted):
n=list(input())
for i in range(len(n)):
  n[i]=int(n[i])
n.reverse()
n.append(0)
ans=0
l=[]
for i in range(len(n)-1):
  if n[i]<5 or (n[i]==5 and n[i+1]<5):
    ans+=n[i]
  else:
    ans+=10-n[i]
    n[i+1]+=1
ans+=n[-1]
print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



N = input()

n_list = []
for i in range(len(N)):
    n_list.append(int(N[-(i+1)]))
n_list.append(0)

counter = 0
for i in range(len(N)+1):
    if n_list[i]<=4:
        counter += n_list[i]
        n_list[i] = 0
    else:
        counter += 10-n_list[i]
        n_list[i] = 0
        n_list[i+1] += 1
    
    

print(counter)


Failing test case input:
2437310229098626998007661836613375259098033385451088851860969041914808128874149347856593652256916

Expected output:
227


Actual output:
230


Fixed submission (verdict: Accepted):



N = input()

n_list = []
for i in range(len(N)):
    n_list.append(int(N[-(i+1)]))
n_list.append(0)

counter = 0
for i in range(len(N)+1):
    if (n_list[i]<=4) or ((n_list[i]==5)and(n_list[i+1]<=4)):
        counter += n_list[i]
        n_list[i] = 0
    else:
        counter += 10-n_list[i]
        n_list[i] = 0
        n_list[i+1] += 1
    
    

print(counter)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=input()
m=list(n)
l=[int(i) for i in m]
l.reverse()
l.append(0)
k=l
ans=0
for i in range(len(l)):
  if k[i]<5:
    ans+=k[i]
  elif k[i]==5:
    if k[i+1]>5:
      k[i+1]+=1
    ans+=5
  else:
    ans+=10-k[i]
    k[i+1]+=1
print(ans)

Failing test case input:
30635919304419657545615271990396525521219360923496828845301606010256650094809182113049943540395907

Expected output:
235


Actual output:
236


Fixed submission (verdict: Accepted):
n=input()
m=list(n)
l=[int(i) for i in m]
l.reverse()
l.append(0)
k=l
ans=0
for i in range(len(l)):
  if k[i]<5:
    ans+=k[i]
  elif k[i]==5:
    if k[i+1]>=5:
      k[i+1]+=1
    ans+=5
  else:
    ans+=10-k[i]
    k[i+1]+=1
print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()[::-1]
ans=0

array = list(map(int, S))
L=len(array)
for i,n in enumerate(array):
    if n<= 5 :
        ans+=n
    elif n > 5:
        ans+= 10-n
        if i <L-1:
            array[i+1] +=1
        else:
            ans +=1
                
print( ans)




Failing test case input:
5546942814324687075141309522425105538838500139873310026540574752128213118200118915575693717113458

Expected output:
239


Actual output:
246


Fixed submission (verdict: Accepted):
S=input()[::-1]
ans=0

array = list(map(int, S))
L=len(array)
for i,n in enumerate(array):
    if n< 5 :
        ans+=n
    elif n > 5:
        ans+= 10-n
        if i <L-1:
            array[i+1] +=1
        else:
            ans +=1
    else:
        ans+=5
        if i < L-1:
            if array[i+1] >=5:
                array[i+1] +=1
                
print( ans)

Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = input()
L=len(N)

DP=[[N]*2 for _ in range(L+1)]
DP[0][0]=0
DP[0][1]=0

for i,n in enumerate(N,1):
    DP[i][0]= min(DP[i-1][0]+int(n),DP[i-1][1]+10-int(n))
    DP[i][1] = min(DP[i-1][0]+int(n)+1,DP[i-1][1]+9-int(n))


print(DP[L][0])


Failing test case input:
6594725398989083813179380483407851617655078876891663245779952920630989972209938915593954710304

Expected output:
209


Actual output:
208


Fixed submission (verdict: Accepted):
N = input()
L=len(N)

DP=[[N]*2 for _ in range(L+1)]
DP[0][0]=0
DP[0][1]=1

for i,n in enumerate(N,1):
    DP[i][0]= min(DP[i-1][0]+int(n),DP[i-1][1]+10-int(n))
    DP[i][1] = min(DP[i-1][0]+int(n)+1,DP[i-1][1]+9-int(n))

print(DP[L][0])

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(str(N))

ans = 0
over = 0
for i in reversed(range(len(S))):
    n = int(S[i]) + over
    if n == 10:
        continue
    over = 0
    if n < 5:
        ans += n
    if n > 5:
        ans += 10-n
        over = 1
    if n == 5:
        ans += 5
        if i > 0 and S[i-1] == '9':
            over = 1


print(ans+over)

Failing test case input:
4912348381192936627119618783919496472041216851183734613912841142109117820269637981

Expected output:
186


Actual output:
188


Fixed submission (verdict: Accepted):
S = input().strip()

num = list(map(int, list(S)))
num.reverse()
num.append(0)

ans = 0
for i in range(len(S)):
    n = num[i]
    if n < 5:
        ans += n
    if n > 5:
        ans += 10-n
        num[i+1] += 1
    if n == 5:
        ans += 5
        if num[i+1] >= 5:
            num[i+1] += 1


print(ans+num[-1])
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()

ans = 0
bef = 0

for i in s[::-1]:
    v = int(i)
    if v+bef>=5:
        ans += 10-(v+bef)
        bef = 1
    else:
        ans += (v+bef)
        bef = 0

ans += (v+bef)
print(ans)

Failing test case input:
59780288599954127141313605773466941891755476883497379054811633671558402370098935074618932935686296

Expected output:
242


Actual output:
250


Fixed submission (verdict: Accepted):
s = input()[::-1]
size = len(s)
s += "4"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += bef
print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input().strip()

num = list(map(int, list(S)))
num.reverse()
num.append(0)


ans = 0
for i in range(len(S)):
    n = num[i]
    if n < 5:
        ans += n
    if n > 5:
        ans += 10-n
        num[i+1] += 1
    if n == 5:
        ans += 5
        num[i+1] += 1


print(ans+num[-1])


Failing test case input:
39600134577901141883606686981207904060108845904698684748394380675335719575971326497

Expected output:
188


Actual output:
190


Fixed submission (verdict: Accepted):
S = input().strip()

num = list(map(int, list(S)))
num.reverse()
num.append(0)

ans = 0
for i in range(len(S)):
    n = num[i]
    if n < 5:
        ans += n
    if n > 5:
        ans += 10-n
        num[i+1] += 1
    if n == 5:
        ans += 5
        if num[i+1] >= 5:
            num[i+1] += 1


print(ans+num[-1])

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):






n = input()

flag = 0
count = 0
for i in range(len(n) - 1, -1, -1):
    c = n[i]
    v = int(c) + flag
    flag = 0
    if v < 5:
        count += v
    elif v == 5:
        if i != 0 and int(n[i-1]) >= 5:
            flag = 1
        count += 5
    else:
        count += 10 - v
        flag = 1
print(count)


Failing test case input:
5611346845600646183996858808900892200270421755353756467910334005328034484620981788522922872185664

Expected output:
232


Actual output:
231


Fixed submission (verdict: Accepted):






n = input()

flag = 0
count = 0
for i in range(len(n) - 1, -1, -1):
    c = n[i]
    v = int(c) + flag

    if v == 10:
        v = 0
        flag = 1
    else:
        flag = 0
    if v < 5:
        count += v
    elif v == 5:
        if i != 0 and int(n[i-1]) >= 5:
            flag = 1
        count += 5
    else:
        count += 10 - v
        flag = 1
print(count + flag)
Problem: p02775
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()
ans = 0
flag = False 
flag2 = False 
for k in range(len(S)):
  n = int(S[-k-1])
  if flag2:
    if n < 5:
      flag = False
    else:
      flag = True
  if flag:
    n += 1
  if n == 5:
    ans += 5
    flag2 = True
  elif n < 5:
    ans += n
    flag2 = False
    flag = False
  else:
    ans += 10-n
    flag2 = False
    flag = True
if flag:
  ans += 1
print(ans)

Failing test case input:
49224978387411527145119125246083342825372500666944406655945446482844169005959392618821385714802117

Expected output:
260


Actual output:
261


Fixed submission (verdict: Accepted):
S = input()
ans = 0
flag = False 
flag2 = False 
for k in range(len(S)):
  n = int(S[-k-1])
  if flag2:
    if n < 5:
      flag = False
    else:
      flag = True
  if flag:
    n += 1
  if n == 5:
    ans += 5
    flag2 = True
    flag = False
  elif n < 5:
    ans += n
    flag2 = False
    flag = False
  else:
    ans += 10-n
    flag2 = False
    flag = True
if flag:
  ans += 1
print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
A = [int(N[i]) for i in range(len(N))]
A.reverse()
A.append(0)

ans = 0

for i in range(len(A)):
    if A[i] > 5:
        ans = ans + (10 - A[i])
        A[i+1] = A[i+1] + 1
    else:
        ans = ans + A[i]

print(ans)

Failing test case input:
85935701773254562628410719372396848335402648590418634844101760809881540580187751784321748296967820

Expected output:
243


Actual output:
247


Fixed submission (verdict: Accepted):
N = input()
A = [int(N[i]) for i in range(len(N))]
A.reverse()
A.append(0)

ans = 0

for i in range(len(A)):
    if A[i] > 5 or (A[i] == 5 and A[i+1] >= 5):
        ans = ans + (10 - A[i])
        A[i+1] = A[i+1] + 1
    else:
        ans = ans + A[i]

print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = ("00"+input())[::-1]

ans = 0
carry = 0
for i in range(len(N)-1):
    n = int(N[i])
    nextn = int(N[i+1])
    if carry == 1:
        carry = 0
        n += 1

    if n <=4:
        ans += n
    elif n >= 6:
        ans += 10-n
        carry = 1
    else: 
        if nextn <= 6:
            ans += n
        else:
            ans += 10-n
            carry = 1

print(ans)
    

Failing test case input:
30635919304419657545615271990396525521219360923496828845301606010256650094809182113049943540395907

Expected output:
235


Actual output:
238


Fixed submission (verdict: Accepted):
N = ("00"+input())[::-1]

ans = 0
carry = 0
for i in range(len(N)-1):
    n = int(N[i])
    nextn = int(N[i+1])
    if carry == 1:
        carry = 0
        n += 1

    if n <=4:
        ans += n
    elif n >= 6:
        ans += 10-n
        carry = 1
    else: 
        if nextn <= 4:
            ans += n
        else:
            ans += 10-n
            carry = 1

print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def solve(*args: str) -> str:
    n = int(args[0])

    count = 0
    for i in map(int, reversed(str(n))):
        if 10-i < i:
            count += 1

        count += min(int(i), 10-int(i))

    return str(count)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Failing test case input:
5611346845600646183996858808900892200270421755353756467910334005328034484620981788522922872185664

Expected output:
232


Actual output:
278


Fixed submission (verdict: Accepted):



def solve(*args: str) -> str:
    N = list(map(int, args[0]))

    a, b = 0, 1
    for n in N:
        a, b = min(b+(10-n), a+n), min(b+(9-n), a+n+1)
    return str(a)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = [int(x) for x in input()]
    dp0 = 0
    dp1 = 1
    for n in N:
        
        a = min(dp0 + n, dp1 + 10 - n)
        
        b = min(dp0 + n + 1, dp1 + 10 - (n+1))
        dp0, dp1 = a, b
    print(min(dp0, dp1))


if __name__ == '__main__':
    main()

Failing test case input:
114221239522324956168750334540425616495902276340082784749801719775664246832920129455

Expected output:
212


Actual output:
211


Fixed submission (verdict: Accepted):
def main():
    N = [int(x) for x in input()]
    dp0 = 0
    dp1 = 1
    for n in N:
        
        a = min(dp0 + n, dp1 + 10 - n)
        
        b = min(dp0 + n + 1, dp1 + 10 - (n+1))
        dp0, dp1 = a, b
        
    print(dp0)
 
 
if __name__ == '__main__':
    main()

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = str(input())
L = len(N)
ans = 0
dp = [[0,0] for _ in range(L)]
s = list(N)
a = int(s[0])
dp[0] = [a,11-a]
for i in range(1,L):
    n = int(s[i])
    dp[i][0] = min(dp[i-1][0],dp[i-1][1]) + n
    dp[i][1] = min(dp[i-1][0],dp[i-1][1]) + 10 - n
dp[-1][1] += 1
print(min(dp[-1]))

Failing test case input:
4217674205198499013544622357181745300880835522557823898487644827176128280660448923472605251124383

Expected output:
255


Actual output:
251


Fixed submission (verdict: Accepted):
N = str(input())
L = len(N)
ans = 0
dp = [[0,0] for _ in range(L)]
s = list(map(int,N))
dp[0] = [s[0],11-s[0]]
for i in range(1,L):
    n = s[i]
    dp[i][0] = min(dp[i-1][0]+n,dp[i-1][1]+n)
    dp[i][1] = min(dp[i-1][1]+9-n,dp[i-1][0]+11-n)
print(min(dp[-1]))
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
if __name__ == "__main__":
    n = '0' + input()

    ans = 0
    flag = 0

    for i in range(len(n)-1, 0, -1):
        if int(n[i]) + flag == 10:
            flag = 1
        elif int(n[i]) + flag > 5 or (int(n[i-1]) == 9 and int(n[i]) + flag == 5):
            ans += 10 - int(n[i])
            flag = 1
        else:
            ans += int(n[i]) + flag
            flag = 0

    if flag == 1:
        ans += 1

    print(ans)


Failing test case input:
43549534976396172158928666287087986381342729034793554625113780207037832016125442496361918536881010

Expected output:
245


Actual output:
262


Fixed submission (verdict: Accepted):
if __name__ == "__main__":
    n = '0' + input()

    ans = 0
    flag = 0

    for i in range(len(n)-1, 0, -1):
        if int(n[i]) + flag == 10:
            flag = 1
        elif int(n[i]) + flag > 5 or (int(n[i]) + flag == 5 and int(n[i-1]) > 4):
            ans += 10 - int(n[i]) - flag
            flag = 1
        else:
            ans += int(n[i]) + flag
            flag = 0

    if flag == 1:
        ans += 1

    print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()

result = 0
carry = 0
for c in N[::-1]:
    t = int(c) + carry
    if t <= 11 - t:
        result += t
        carry = 0
    else:
        result += 10 - t
        carry = 1
result += carry
print(result)


Failing test case input:
17585258772958880378227301741112541508654587486939615295198240373899123309969708142159

Expected output:
195


Actual output:
200


Fixed submission (verdict: Accepted):
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()[::-1]
size = len(s)
s += "9"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += bef
print(ans)

Failing test case input:
476640020082194381531155118436783393866726953614433851622190777875571135215042541028243752681838573

Expected output:
259


Actual output:
260


Fixed submission (verdict: Accepted):
s = input()[::-1]
size = len(s)
s += "4"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += bef
print(ans)
Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())

ans = 0
n_dig = len(str(n)) 

carry = 0
for i in range(n_dig):
    d = n % 10
    n 

    if carry + d <= 5:
        ans += d + carry
        carry = 0  
    else:
        ans += 10 - d - carry
        carry = 1

print(ans + carry)


Failing test case input:
374494794680584068005832434968266656004164287419917270505890324452002309527820721404

Expected output:
205


Actual output:
336


Fixed submission (verdict: Accepted):
n = "0" + input()

ans = 0
n_dig = len(n) 

carry = 0
d_next = int(n[n_dig - 1])

for i in range(n_dig - 1, 0, -1):  
    d = d_next
    d_next = int(n[i - 1])

    if carry + d <= 4 or (carry + d == 5 and d_next <= 4):
        ans += d + carry
        carry = 0  
    else:
        ans += 10 - d - carry
        carry = 1

print(ans + carry)

Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    s = input().strip()
    carry = 0
    result = 0
    for i in range(len(s) - 1, -1, -1):
        carry, x = divmod(ord(s[i]) - ord("0") + carry, 10)
        if x > 5 or (x == 5 and i > 0 and s[i - 1] >= "5"):
            carry += 1
            result += 10 - x
        else:
            result += x
    print(result)


main()


Failing test case input:
680012228010389890839609002199814367568170173937333389479731967501701054297811299047014210608

Expected output:
179


Actual output:
178


Fixed submission (verdict: Accepted):
def main():
    s = input().strip()
    carry = 0
    result = 0
    for i in range(len(s) - 1, -1, -1):
        carry, x = divmod(ord(s[i]) - ord("0") + carry, 10)
        if x > 5 or (x == 5 and i > 0 and s[i - 1] >= "5"):
            carry += 1
            result += 10 - x
        else:
            result += x
    result += carry
    print(result)


main()

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()[::-1]
size = len(s)
s += "9"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += (v1+bef)
print(ans)

Failing test case input:
116383069457164511975110145081426291202103544489399693747546860529356171946237452235

Expected output:
222


Actual output:
223


Fixed submission (verdict: Accepted):
s = input()[::-1]
size = len(s)
s += "4"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += bef
print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(map(int, input()))
n = n[::-1]


b0 = [0]*(len(n)+1)
b1 = [0]*(len(n)+1)

for i in range(0, len(n)):
  num = n[i]
  b0[i+1] = min(b0[i]+num, b1[i]+num+1)
  b1[i+1] = min(b0[i]+10-num, b1[i]+10-(num+1))

print(min(b0[-1], b1[-1]+1))

Failing test case input:
2437310229098626998007661836613375259098033385451088851860969041914808128874149347856593652256916

Expected output:
227


Actual output:
226


Fixed submission (verdict: Accepted):
n = [0] + list(map(int, input())) + [0]
n = n[::-1]


b0 = [0]*len(n)
b1 = [0]*len(n)
b1[0] = 1
for i in range(1, len(n)):
  num = n[i]
  b0[i] = min(b0[i-1]+num, b1[i-1]+num+1)
  b1[i] = min(b0[i-1]+10-num, b1[i-1]+10-(num+1))

print(min(b0[-1], b1[-1]))

Problem: p02775
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s=[int(i) for i in input()]
n=len(s)
ans=0
f=0
for i in range(n-1,-1,-1):
  j=s[i]+f
  if j<5:
    ans+=j
    f=0
  elif j>5:
    ans+=10-j
    f=1
  elif s[i-1]>=5:
    ans+=10-j
    f=1
  else:
    ans+=j
    f=0
print(ans+f)

Failing test case input:
49224978387411527145119125246083342825372500666944406655945446482844169005959392618821385714802117

Expected output:
260


Actual output:
261


Fixed submission (verdict: Accepted):
s=[int(i) for i in input()]
n=len(s)
ans=0
f=0
for i in range(n-1,-1,-1):
  j=s[i]+f
  if j<5:
    ans+=j
    f=0
  elif j>5:
    ans+=10-j
    f=1
  elif i and s[i-1]>=5:
    ans+=10-j
    f=1
  else:
    ans+=j
    f=0
print(ans+f)

Problem: p02775
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=input()
inf=float("inf")
dp=[[inf]*(len(N)+1) for i in range(2)]
dp[0][0]=0
for i in range(len(N)):
   tmp=int(N[-1-i])
   dp[0][i+1]=min(dp[0][i],dp[1][i])+tmp
   dp[1][i+1]=min(dp[0][i]+11,dp[1][i]+9)-tmp
   print(dp[0][i+1],dp[1][i+1])
print(min(dp[0][-1],dp[1][-1]))

Failing test case input:
21859110864590199198540714463744578129645949823640150386511332904564103343275159478837648186452280

Expected output:
248


Actual output:
0 11
8 3
5 10
7 14
12 13
16 18
22 21
29 22
23 30
31 26
30 31
36 34
41 36
39 42
47 42
50 43
50 45
49 50
58 50
55 54
55 62
60 61
67 63
65 70
68 73
72 75
75 80
78 83
78 89
79 88
83 86
89 88
93 92
96 97
96 106
105 98
100 105
103 108
106 111
107 116
108 117
113 114
119 117
125 118
121 124
121 132
126 127
127 135
127 138
131 134
137 136
139 142
141 148
149 144
153 144
148 149
157 149
154 153
157 158
163 161
170 161
163 168
164 173
172 167
174 169
174 173
177 178
181 183
188 185
188 191
194 193
197 198
201 203
202 211
209 206
206 215
210 213
215 216
223 217
226 217
218 225
227 220
229 220
221 228
221 232
230 223
228 227
231 232
237 235
243 236
236 245
237 246
238 247
247 240
245 244
252 245
246 253
248 255
248


Fixed submission (verdict: Accepted):
N=input()
inf=float("inf")
dp=[[inf]*(len(N)+1) for i in range(2)]
dp[0][0]=0
for i in range(len(N)):
   tmp=int(N[-1-i])
   dp[0][i+1]=min(dp[0][i],dp[1][i])+tmp
   dp[1][i+1]=min(dp[0][i]+11,dp[1][i]+9)-tmp
print(min(dp[0][-1],dp[1][-1]))
Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = input()

pay = 0
turi = 0

pls = 0
for i in n[::-1]:
  val = int(i)
  if val + pls <= 5:
    pay += val + pls
    pls = 0
  else:
    turi += 10 - (val + pls)
    pls = 1
pay += pls

ans = pay + turi
print(ans)

Failing test case input:
49224978387411527145119125246083342825372500666944406655945446482844169005959392618821385714802117

Expected output:
260


Actual output:
261


Fixed submission (verdict: Accepted):
n = "0" + input()
n = list(map(int, list(n)))
n.reverse()

pay = 0
turi = 0

pls = 0
for i in range(len(n)):
  val = n[i] + pls
  pls = 0
  if val < 5:
    pay += val
  elif val == 5:
    pay += val
    if n[i + 1] >= 5:
      pls = 1
  else:
    turi += 10 - val
    pls = 1

ans = pay + turi
print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = list(input())
N = [int(n) for n in N]
len_N = len(N)
ans = 0

for i in reversed(range(len_N)):
    num = int(N[i])
    if num == 10:
        N[i-1] += 1
    elif num >5:
        ans += (10-num)
        N[i-1] += 1
    else:
        ans += num



if N[0] == 10:
    ans += 1

print(ans)

Failing test case input:
112971229910948442277742063793860536302679259212406616014111988669828741066875057785985507004364571

Expected output:
225


Actual output:
230


Fixed submission (verdict: Accepted):

N = list(input())
N = [int(n) for n in N]
N.insert(0, 0)
len_N = len(N)
ans = 0

for i in reversed(range(len_N)):
    num = int(N[i])
    if num == 10:
        N[i-1] += 1
    
    elif num==5:
        if int(N[i-1])>=5:
            ans += 5
            N[i-1] += 1
        else:
            ans += 5
    
    elif num >5:
        ans += (10-num)
        N[i-1] += 1
    else:
        ans += num

print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n = input()[::-1] + "0"
    s = 0
    cnt = 0
    for i, ni in enumerate(n[:-1]):
        k = int(ni) + s
        if k < 5 or k == 5 and int(n[i + 1]) <= 5:
            cnt += k
            s = 0
        else:
            cnt += 10 - k
            s = 1
    cnt += s
    print(cnt)

if __name__ == '__main__':
    main()

Failing test case input:
3029165028855265861064957503518699141718370197384262165027208857833010479

Expected output:
171


Actual output:
172


Fixed submission (verdict: Accepted):
def main():
    n = input()[::-1] + "0"
    s = 0
    cnt = 0
    for i, ni in enumerate(n[:-1]):
        k = int(ni) + s
        if k < 5 or k == 5 and int(n[i + 1]) < 5:
            cnt += k
            s = 0
        else:
            cnt += 10 - k
            s = 1
    cnt += s
    print(cnt)

if __name__ == '__main__':
    main()
Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, p = list(map(int, input().split()))

if n == 1 :
    print(p)
elif p == 1 :
    print(1)
elif n >= 50:
    print(1)
else:
    ans = 1
    count = 2
    tmp = count**n
    while (tmp) < p:
        if(p % tmp == 0):
            ans *= count
            p /= tmp
        count += 1
        tmp = count**n
    print(ans)

Failing test case input:
2 243501193440

Expected output:
12


Actual output:
6


Fixed submission (verdict: Accepted):
n, p = list(map(int, input().split()))

if n == 1 :
    print(p)
elif p == 1 :
    print(1)
elif n >= 40:
    print(1)
else:
    ans = 1
    count = 2
    tmp = count**n
    while (tmp) <= p:
        if(p % tmp == 0):
            ans *= count
            p = int(p/tmp)
            count -= 1
        count += 1
        tmp = count**n
    print(ans)

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N,P = list(map(int,input().split()))

i = 2
l = []
while i*i <= P:
    while P%i == 0:
        P /= i
        l.append(i)
    i += 1
if P > 1:
    l.append(int(P))

n = list(set(l))
c = [math.floor(l.count(i)/N) for i in n]
res = 1
for m in [n_*c_ for n_,c_ in zip(n,c)]:
    if m > 0:
        res = res * m

print(res)

Failing test case input:
1 86266567854

Expected output:
86266567854


Actual output:
57511045236


Fixed submission (verdict: Accepted):
import math

N,P = list(map(int,input().split()))

i = 2
l = []
while i*i <= P:
    while P%i == 0:
        P /= i
        l.append(i)
    i += 1
if P > 1:
    l.append(int(P))
if len(l) == 0:
    l.append(1)

n = list(set(l))
c = [math.floor(l.count(i)/N) for i in n]
res = 1
for m in [n_**c_ for n_,c_ in zip(n,c)]:
    if m > 0:
        res *= m

print(res)

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def prime_decomposition(n):
    i = 2
    table=[]
    while i*i<=n:
        count=0
        while n%i==0:
            n/= i
            count+=1
        table.append([int(i),count])
        i += 1
    if n > 1:
        table.append([int(n),1])
    return table
N,P=map(int,input().split())
ans=1
for A in prime_decomposition(P):
    if A[1]>=N:
        ans*=A[0]*int(A[1]/N)
print(ans)

Failing test case input:
1 839883532662

Expected output:
839883532662


Actual output:
51844662510


Fixed submission (verdict: Accepted):
def prime_decomposition(n):
    i = 2
    table=[]
    while i*i<=n:
        count=0
        while n%i==0:
            n/= i
            count+=1
        table.append([int(i),count])
        i += 1
    if n > 1:
        table.append([int(n),1])
    return table
N,P=map(int,input().split())
ans=1
for A in prime_decomposition(P):
    if A[1]>=N:
        ans*=A[0]**int(A[1]/N)
print(ans)
Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,P = map(int,input().split())
r = round(P**(1/N))
for i in range(r,0,-1):
    if P%i==0:
        print(i)
        exit()

Failing test case input:
2 243501193440

Expected output:
12


Actual output:
446169


Fixed submission (verdict: Accepted):
N,P = map(int,input().split())
r = round(P**(1/N))
for i in range(r,0,-1):
    if P%(i**N)==0:
        print(i)
        exit()

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def caddi2018b_c():
    from collections import Counter
    def prime_decomposition(num):
        i = 2
        table = []
        while i * i <= num:
            while num % i == 0:
                num /= i
                table.append(i)
            i += 1
        if num > 1:
            table.append(int(num))
        return table

    n, p = map(int, input().split())
    ans = 1
    factors = Counter(prime_decomposition(p))
    for val in factors:
        if factors[val] >= n:
            ans *= val
    print(ans)


caddi2018b_c()

Failing test case input:
1 154441711652

Expected output:
154441711652


Actual output:
77220855826


Fixed submission (verdict: Accepted):
def caddi2018b_c():
    from collections import Counter
    def prime_decomposition(num):
        i = 2
        table = []
        while i * i <= num:
            while num % i == 0:
                num /= i
                table.append(i)
            i += 1
        if num > 1:
            table.append(int(num))
        return table

    n, p = map(int, input().split())
    ans = 1
    factors = Counter(prime_decomposition(p))
    for val in factors:
        ans *= val ** (factors[val] 
    print(ans)


caddi2018b_c()

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,p = map(int,input().split())
a = []
i = 2
while (p>1) and (i < int(p**0.5) + 1):
    c = 0
    while p%i == 0:
        p = p/i
        c += 1
    a.append([i,c])
    i += 1

c = 1
for i in range(len(a)):
  if a[i][1] >= n:
  	c = c* a[i][0] * int(a[i][1]/n)
    
print(c)

Failing test case input:
1 243501193440

Expected output:
243501193440


Actual output:
170550


Fixed submission (verdict: Accepted):
n,p = map(int,input().split())
a = []
i = 2
k = p

if n == 1:
  c = p
else:
  while (p>1) and (i < int(k**0.5) + 4):
      c = 0
      while p%i == 0:
          p = p/i
          c += 1
      a.append([i,c])
      i += 1
  if p>1:
      a.append([p,1])
  c = 1

  for i in range(len(a)):
    if a[i][1] >= n:
      k = a[i][0] ** int(a[i][1]/n)
      c = c* k

print(c)
Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,P = list(map(int,input().split()))
mylist = []
roop  = int((10**12)**(1/N))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


if N ==1:
    print(P)
else:
    Primelis = primes(roop)
    for i in Primelis:
        if P%(i**N)==0:
            mylist.append(i)
    ans = 1
    L = len(mylist)
    for i in range(L):
        ans = ans*mylist[i]
    print(ans)

Failing test case input:
2 243501193440

Expected output:
12


Actual output:
6


Fixed submission (verdict: Accepted):
N,P = list(map(int,input().split()))
mylist = []
roop  = int((10**12)**(1/N))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

flag = 0
tmp = 1
if N ==1:
    print(P)
else:
    Primelis = primes(roop)
    for i in Primelis:
        flag = 0
        tmp = 1
        while flag==0:
            if P%(i**N)==0:
                P = P/(i**N)
                tmp = tmp*i
            else:
                mylist.append(tmp)
                flag = 1
    ans = 1
    L = len(mylist)
    for i in range(L):
        ans = ans*mylist[i]
    print(ans)

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N, P = map(int, input().split())
max_value = math.floor(math.sqrt(P))
ans = 1

if N == 1:
    ans = P
else:
    for i in range(2, max_value):
        mod = i ** N
        if P % mod == 0:
            ans *= i
            P /= mod

print(ans)


Failing test case input:
2 243501193440

Expected output:
12


Actual output:
6


Fixed submission (verdict: Accepted):
import math

N, P = map(int, input().split())
max_value = round(pow(P, 1/N)) + 1 
ans = 1

if N == 1:
    ans = P
else:
    for i in range(1, max_value):
        mod = i ** N
        if P % mod == 0:
            ans = i

print(ans)
Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,P = map(int, input().split())

if P == 1 or N == 2:
    print(1)
elif N == 1:
    print(P)
else:
    import math

    sq_P = math.floor(math.sqrt(P))
    prim = []
    P_tmp=P

    for i in range(2,sq_P):
        r=0
        if P_tmp%i == 0:
            r+=1
            P_tmp=P/i
            while P_tmp%i==0:
                r+=1
                P_tmp=P_tmp/i
            prim.append([i,r])

    ans = 1
    for i in range(len(prim)):
        if prim[i][1]>=N:
            ans = ans * prim[i][0]

    print(ans)

Failing test case input:
4 972439611840

Expected output:
206

Actual output:
42436


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

if P == 1 :
    print(1)
elif N == 1:
    print(P)
else:
    import math

    sq_P = math.floor(math.sqrt(P))
    prim = []
    P_tmp=P

    for i in range(2,sq_P):
        r=0
        if P_tmp%i == 0:
            r+=1
            P_tmp=P_tmp/i
            while P_tmp%i==0:
                r+=1
                P_tmp=P_tmp/i
            prim.append([i,r])

    ans = 1
    for i in range(len(prim)):
        if prim[i][1]>=N:
            ans = ans * prim[i][0]**math.floor(prim[i][1]/N)

    print(ans)

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N, P = map(int, input().split())
max_value = math.floor(math.sqrt(P))
ans = 1

if N == 1:
    ans = P
else:
    for i in range(2, max_value):
        mod = i ** N
        if P % mod == 0:
            ans *= i
            P /= mod
        if i > math.floor(math.sqrt(P)):
            break

print(ans)


Failing test case input:
2 243501193440

Expected output:
12


Actual output:
6


Fixed submission (verdict: Accepted):
import math

N, P = map(int, input().split())
max_value = round(pow(P, 1/N)) + 1 
ans = 1

if N == 1:
    ans = P
else:
    for i in range(1, max_value):
        mod = i ** N
        if P % mod == 0:
            ans = i

print(ans)

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,p = map(int,input().split())
N = round(p**(1/n))
if n==1:
    print("p")
else:
    for i in range(N,0,-1):
        if p%(i**n)==0:
            print(i)
            exit()

Failing test case input:
1 84537270514

Expected output:
84537270514


Actual output:
p


Fixed submission (verdict: Accepted):
n,p = map(int,input().split())
N = round(p**(1/n))
for i in range(N,0,-1):
    if p%(i**n)==0:
        print(i)
        exit()
Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, P = map(int, input().split())
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
prime = prime_decomposition(P)
now = -1
count = 0
res = 1
for i in range(len(prime)):
    if now != prime[-i-1]:
        count = 0
        now = prime[-i-1]
    count += 1
    if count == N:
        res *= prime[-i-1]
print(int(res))

Failing test case input:
1 154441711652

Expected output:
154441711652


Actual output:
77220855826


Fixed submission (verdict: Accepted):
N, P = map(int, input().split())
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
prime = prime_decomposition(P)
now = -1
count = 0
res = 1
for i in range(len(prime)):
    if now != prime[-i-1]:
        count = 0
        now = prime[-i-1]
    count += 1
    if count == N:
        res *= prime[-i-1]
        count = 0
print(int(res))

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def prime_decomposition(n):
    i = 2
    dic = {}
    while i * i <= n:
        while n % i == 0:
            n /= i
            if i in dic:
                dic[i] += 1
            else:
                dic[i] = 1
        i += 1
    if n > 1:
        
        dic[int(n)] = 1
        
    return dic

N, P = map(int, input().split())
d = prime_decomposition(P)

ret = 1
for k, v in d.items():
    if v >= N:
        ret *= k
print(ret)

Failing test case input:
1 4295973496

Expected output:
4295973496


Actual output:
1073993374


Fixed submission (verdict: Accepted):
def prime_decomposition(n):
    i = 2
    dic = {}
    while i * i <= n:
        while n % i == 0:
            n /= i
            if i in dic:
                dic[i] += 1
            else:
                dic[i] = 1
        i += 1
    if n > 1:
        dic[int(n)] = 1
    return dic

N, P = map(int, input().split())
d = prime_decomposition(P)
ret = 1
for k, v in d.items():
    if v >= N:
        ret *= k ** (v
print(ret)
Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import math

def primeFact(P):
    s = math.floor(math.sqrt(P))
    result = {}

    for i in range(2, s):
        if P % i == 0:
            r = 0
            while P % i == 0:
                r += 1
                P = P / i
            result[i] = r

    if P > s:
        result[P] = 1
    return result

def gcd(N, fact):
    gcd = 1
    for key in fact.keys():
        if fact[key] >= N:
            gcd *= key * (int(fact[key] / N))
    return int(gcd)

if __name__ == "__main__":
    N, P = map(int, input().split())
    fact = primeFact(P)
    print(gcd(N, fact))

Failing test case input:
1 234686228571

Expected output:
234686228571


Actual output:
156457485714


Fixed submission (verdict: Accepted):

import math

def primeFact(P):
    s = math.floor(math.sqrt(P))
    result = {}

    for i in range(2, s + 1):
        if P % i == 0:
            r = 0
            while P % i == 0:
                r += 1
                P = P 
            result[i] = r

    if P > s:
        result[P] = 1
    return result

def gcd(N, fact):
    gcd = 1
    for key in fact.keys():
        if fact[key] >= N:
            gcd *= key ** (fact[key] 
    return int(gcd)

if __name__ == "__main__":
    N, P = map(int, input().split())
    fact = primeFact(P)
    print(gcd(N, fact))

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, p = map(int, input().split())
import math


def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 

    
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

PS = primes(1000000)
def factorint(x):
  d = {}
  for k in PS:
    if(x % k== 0):
      m = 1
      while(x % (k**m) == 0):
        m += 1
      d[k] = m - 1
      x = x / (k ** (m - 1))
      if x == 1:
        break
  return d

fac = factorint(p)
result = 1
for i,j in fac.items():
  result *= i **math.floor(j/n)
print(result)

Failing test case input:
1 1472895801034

Expected output:
1472895801034


Actual output:
1418998


Fixed submission (verdict: Accepted):
n, p = map(int, input().split())
import math


def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 

    
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

PS = primes(1000000)
def factorint(x):
  d = {}
  for k in PS:
    if(x % k== 0):
      m = 1
      while(x % (k**m) == 0):
        m += 1
      d[k] = m - 1
      x = x / (k ** (m - 1))
      if x == 1:
        break
  return d

fac = factorint(p)
result = 1
for i,j in fac.items():
  result *= i **math.floor(j/n)
if n == 1:
  result = p
print(result)
Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    li = []
    m = int(p ** (1 / n))
    for i in range(1, m + 1):
        if p % (i ** n) == 0:
            li.append(i)
            p 

    ans = 1
    for i in li:
        ans *= i
    print(ans)


Failing test case input:
2 243501193440

Expected output:
12


Actual output:
1728


Fixed submission (verdict: Accepted):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    m = int((p + 1) ** (1 / n))
    while m ** n > p:
        m -= 1
    for i in reversed(range(1, m + 1)):
        if p % (i ** n) == 0:
            print(i)
            break

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
a = list(map(int,input().split()))

b = []
co = 0
su = 1
s = prime_decomposition(a[1])
c = collections.Counter(s)
ss = c.most_common()
sss = c.values()
i = 0
for i in range(len(ss)):
    if ss[i][1] >= a[0]:
        su *= int(ss[i][0])

print(su)


Failing test case input:
1 972439611840

Expected output:
972439611840


Actual output:
3090


Fixed submission (verdict: Accepted):
import collections
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
a = list(map(int,input().split()))

b = []
co = 0
su = 1
s = prime_decomposition(a[1])
c = collections.Counter(s)
ss = c.most_common()
i = 0
for i in range(len(ss)):
    if ss[i][1] >= a[0]:
        su *= int(ss[i][0])**(ss[i][1]

print(su)

Problem: p03194
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def read():
    N, P = list(map(int, input().strip().split()))
    return N, P


def solve(N, P):
    for v in range(1000, 1, -1):
        if P % (v**N) == 0:
            return v
    return 1


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Failing test case input:
1 5252044774

Expected output:
5252044774


Actual output:
2


Fixed submission (verdict: Accepted):
import math


def read():
    N, P = list(map(int, input().strip().split()))
    return N, P


def solve(N, P):
    
    if N >= 40:
        return 1
    
    v3 = math.floor(P**(1/N)) + 1
    for v in range(v3, 0, -1):
        if P % (v**N) == 0:
            return v
    return 1


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))