Buggy python submission (verdict: Runtime Error):
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))


Fixed submission:
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if (n//2)+1<s:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))

Buggy python submission (verdict: Runtime Error):
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if s==1:return n
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))

Fixed submission:
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if (n//2)+1<s:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))

Buggy python submission (verdict: Runtime Error):
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if s==1:return n
    for b in range(2,1+int(n_root//1)):
        if fun(b,n)==s:
            return b
    for i in range(1+int(n_root//1),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b<=n_root or b<=1:continue
            if n//b>=b or n//b<1:continue
            return b
    return -1
print(main(n,n_root,s))


Fixed submission:
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if (n//2)+1<s:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=int(input())
rootn=0
while rootn**2<=n:
    rootn+=1

    
def fun(b,n):
    b=int(b)
    n=int(n)
    if n<b:return n
    elif n>=b:
        return fun(b,n//b)+n%b
def main(n,s):
    if n==s:return n+1
    for b in range(2,rootn):
        if fun(b,n)==s:return int(b)
    
    for p in reversed(range(1,rootn)):
        b=1+(n-s)//p
        if fun(b,n)==s:return int(b)
        b=2+(n-s)//p
        if fun(b,n)==s:return int(b)
    return -1

x=main(n,s)
print(x)
#http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf

Fixed submission:
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if (n//2)+1<s:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=int(input())
rootn=0
while rootn**2<=n:
    rootn+=1

    
def fun(b,n):
    if n<b:return n
    elif n>=b:
        return fun(b,n//b)+n%b
def main(n,s):
    if n==s:return n+1
    for b in range(2,rootn):
        if fun(b,n)==s:return int(b)
    
    for p in reversed(range(1,rootn)):
        b=1+(n-s)//p
        if fun(b,n)==s:return int(b)
        b=2+(n-s)//p
        if fun(b,n)==s:return int(b)
    return -1

x=main(n,s)
print(x)
#http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf

Fixed submission:
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if (n//2)+1<s:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=int(input())
rootn=0
while rootn**2<=n:
    rootn+=1

    
def fun(b,n):
    if n<b:return n
    elif n>=b:
        return fun(b,n//b)+n%b
def main(n,s):
    if n==s:return n+1
    for b in range(2,rootn):
        if fun(b,n)==s:return int(b)
    
    for p in range(1,rootn):
        if (n-s)%p==0:
            b=1+(n-s)/p
            if fun(b,n)==s:return int(b)
    return -1

x=main(n,s)
print(x)
#http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf

Fixed submission:
#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if (n//2)+1<s:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))