Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03162 (python)

Fixed submission:
import sys
def 解():
    input = sys.stdin.readline
    N = int(input())
    dp = [int(_) for  _ in input().split()]
    for _ in range(N-1):
        a,b,c = [int(_) for  _ in input().split()]
        dp = [max(dp[1]+a,dp[2]+a),max(dp[0]+b,dp[2]+b),max(dp[0]+c,dp[1]+c)]
    print(max(dp))
解()

Buggy submission (verdict: Runtime Error):
mport sys
def 解():
    input = sys.stdin.readline
    N = int(input())
    dp = [int(_) for  _ in input().split()]
    for _ in range(N-1):
        a,b,c = [int(_) for  _ in input().split()]
        dp = [max(dp[1]+a,dp[2]+a),max(dp[0]+b,dp[2]+b),max(dp[0]+c,dp[1]+c)]
    print(max(dp))
解()
Problem p03165 (python)

Fixed submission:
def 解():
    sS = input().rstrip()
    sT = input().rstrip()
    iS = len(sS)
    iT = len(sT)

    dp = [[0]*(iT+1) for _ in range(iS+1)]
    for i in range(iS):
        for j in range(iT):
            if sS[i] == sT[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
    iC = dp[iS][iT]
    aR = [""]*iC
    i = iS
    j = iT
    while 0 < i and 0 < j:
        if sS[i-1] == sT[j-1]:
            aR[dp[i][j]-1]=sS[i-1]
            i -= 1
            j -= 1
        else:
            if dp[i][j] == dp[i][j-1] :
                j -= 1
            elif dp[i][j] == dp[i-1][j] :
                i -= 1
            else:
                break

    print("".join(aR))
    exit()

    def findS(i,j):
        iC = dp[i][j]
        if iC == 0 or aR[iC-1] != "":
            return False
        if dp[i][j] == dp[i-1][j] + 1 == dp[i][j-1] +1 :
            t = dp[i][j]
            aR[t-1] = sS[i-1]
            findS(i-1,j-1)
        else:
            findS(i-1,j)
            findS(i,j-1)
    findS(i,j)
    print("".join(aR))
解()

Buggy submission (verdict: Runtime Error):

def 解():
    sS = input().rstrip()
    sT = input().rstrip()
    iS = len(sS)
    iT = len(sT)

    dp = [[0]*(iT+1) for _ in range(iS+1)]
    for i in range(iS):
        for j in range(iT):
            if sS[i] == sT[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
    iC = dp[iS][iT]
    aR = [""]*iC
    i = iS
    j = iT
    Q = []

    def findS(i,j):
        iC = dp[i][j]
        if iC == 0 or aR[iC-1] != "":
            return False
        if dp[i][j] == dp[i-1][j] + 1 == dp[i][j-1] +1 :
            t = dp[i][j]
            aR[t-1] = sS[i-1]
            findS(i-1,j-1)
        else:
            findS(i-1,j)
            findS(i,j-1)
    findS(i,j)
    print("".join(aR))
解()
Problem p03241 (python)

Fixed submission:
iN,iM = [int(_) for _ in input().split()]

if iM % iN == 0:
    print(iM // iN)
else:
    aRet = []
    for i in range(1,iM//iN + 1):
        if iM % i == 0:
            aRet.append(i)
    print(aRet[-1])

Buggy submission (verdict: Runtime Error):
iN,iM = [int(_) for _ in input().split()]
iD = iM // iN
if iM % iN == 0:
    print(iD)
else:
    aD = []
    for i in range(1,int(iM**0.5)+1):
        if iM % i == 0:
            if iD > i : aD.append(i)
            j = iM//i
            if iD > j :aD.append(j)
    print(max(aD))

Buggy submission (verdict: Runtime Error):
import itertools
iN,iM = [int(_) for _ in input().split()]

if iM % iN == 0:
    print(iM // iN)
else:
    for i in range( 1 , min(iM // iN + 1,int(iM ** 0.5)+1) ):
        if iM % i == 0:
            aRet.append( i )
    print( aRet[-1] )
Problem p03282 (python)

Fixed submission:

sS = input().rstrip()
iK = int(input())

for i in range(iK):
    if sS[i] != "1" :
        print(sS[i])
        exit()
print(sS[i])

Buggy submission (verdict: Runtime Error):
sS = input().rstrip()
#iK = int(input())
if sS[0] == "1":
    if iK !=1:
        print(sS[1])
    else:
        print(sS[0])
else:
    print(sS[0])
Problem p03296 (python)

Fixed submission:
iN = int(input())
aS = [int(x) for x in input().rstrip().split()]

#はぁ こんなのを一発で通れるようなものも書けないのか.. つらい

#つけたしつけたしで条件追加しててやっててつらい



iCounter = 0
if iN == 2:
    if aS[0] == aS[1]:
        iCounter += 1
else:
    for i in range(1,iN-1):
        if aS[i] == aS[i-1]:
            if aS[i] == aS[i+1]:
                if aS[i] < 10000:
                    aS[i] += 1
                else:
                    aS[i] -= 1
                iCounter += 1
            else:
                iU = max(aS[i],aS[i+1])
                if iU < 10000:
                    iU += 1
                else:
                    iU -= 1
                    if iU == min(aS[1],aS[i+1]):
                        iU -= 1
                aS[i] = iU
                iCounter += 1
    if aS[iN-2] == aS[iN-1] :
        iCounter += 1
print(iCounter)

Buggy submission (verdict: Runtime Error):
iN = int(input())
aS = map(int,input().split())

iCounter = 0
for i in range(1,iN-1):
  if aS[i] == aS[i-1]:
    if aS[i] == aS[i+1]:
      aS[i] += 1
      iCounter += 1
    else:
      iU = max(aS[i],aS[i+1])
      if iU < 10000:
        iU += 1
      else:
        while iU not in aS[i:i+2]:
          iU -= 1
      aS[i] = iU
      iCounter += 1
print(iCounter)
Problem p03297 (python)

Fixed submission:
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]

def fGcd(iX,iY):
    while iY:
        iX,iY= iY,iX%iY
    return iX

#これものすごくわりきってるけど通るのか？

def fFunc(iA,iB,iC,iD):
    if iA < iB or iD < iB:
        return False
    elif iC >= iB :
        return True
    elif iC < iA % iB :
        return False
    elif iB -iC - 1 < fGcd(iB,iD) :
        return True
    else:
        return False

for eR in aR:
    if fFunc(*eR) :
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]
#わからんから解説見た。解説見たけどgcdの下りが自分で導出できんかったのでとりあえ
ずバカループでなんとかしてみた。これで通るかな。
def fFunc(iA,iB,iC,iD):
    if iA < iB or iD < iB:
        return False
    if iC >= iB :
        return True
    iJ = iA % iB
    iK = iD % iB
    i = 1
    while True:
        j = iJ + i * iK
        if iB <= j:
            return True
        else:
            if iC < j:
                return False
        if iK == 0:
            return True
        i += 1
    return True

for eR in aR:
    if fFunc(*eR) :
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]
#わからんから解説見た。解説見たけどgcdの下りが自分で導出できんかったのでとりあえ
ずバカループでなんとかしてみた。これで通るかな。
def f調1(iA,iB,iC,iD):
    if iA < iB or iD < iB:
        return False
    if iC >= iB :
        return True
    iJ = iA % iB
    iK = iD % iB
    i = 1
    while True:
        j = iJ + i * iK
        if iB <= j:
            return True
        else:
            if iC < j:
                return False
        if iK == 0:
            return True
        i += 1
    return True

for eR in aR:
    if f調1(*eR) :
        print("Yes")
    else:
        print("No")
Problem p03353 (python)

Fixed submission:
def 解():
    sS = input().rstrip()
    dsS = set()
    for s in sS:
        if s not in dsS:
            dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
    for s in sorted(list(dsS)):
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s :
                if i != 0 and i != iL-1:
                    if sS[i-1] != s or sS[i+1] != s:
                        indexes.append(i)
                else:
                    indexes.append(i)
        if iK < iL :
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            if iK <= len(aS) :
                print(aS[iK - iC -1])
                exit()
            else:
                iC += len(aS)
        else:
            for i in indexes:
                for j in range(1,iL -i+1):
                    sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            iLS = len(aS)
            if iC + iLS < iK:
                iC += iLS
                continue
            else:
                print(aS[iK -iC-1])
                exit()
解()

Buggy submission (verdict: Runtime Error):
def 解():
    sS = input().rstrip()
    dsS = set()
    for s in sS:
        if s not in dsS:
            dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
    for s in sorted(list(dsS)):
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s:
                indexes.append(i)
        if iK < iL // len(indexes) + 1:
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            print(aS[iK -1])
            exit()
        for i in indexes:
            for j in range(1,iL -i+1):
                sDic.add(sS[i:i+j])
        aS = sorted(list(sDic))
        iLS = len(aS)
        if iC + iLS < iK:
            iC += iLS
            continue
        else:
            print(aS[iK -iC-1])
            exit()
解()

Buggy submission (verdict: Runtime Error):
def 解():
    sS = input().rstrip()
    dsS = set()
    for s in sS:
        if s not in dsS:
            dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
    for s in sorted(list(dsS)):
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s:
                indexes.append(i)
        if iK < iL // len(indexes):
            for i in indexes:
                for j in range(1,iK+1):
                    sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            print(aS[iK -1])
            exit()
        for i in indexes:
            for j in range(1,iL -i+1):
                sDic.add(sS[i:i+j])
        aS = sorted(list(sDic))
        iLS = len(aS)
        if iC + iLS < iK:
            iC += iLS
            continue
        else:
            print(aS[iK -iC-1])
            exit()
解()
Problem p03557 (python)

Fixed submission:
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aA = sorted([int(_) for _ in input().split()])
    aB = sorted([int(_) for _ in input().split()])
    aC = sorted([int(_) for _ in input().split()])

    aBA =[0]*iN
    iIndex = iN-1
    for i in range(iN-1,-1,-1):
        iB = aB[i]
        while aA[iIndex] >= iB:
            iIndex -= 1
            if iIndex < 0:
                break
        if iIndex >= 0 :
            aBA[i] = iIndex + 1
        else:
            break
    aAcBA=[0]*iN
    aAcBA[0]=aBA[0]
    for i in range(1,iN):
        aAcBA[i]=aAcBA[i-1]+aBA[i]
    iAns = 0
    iIndex = iN-1
    for i in range(iN-1,-1,-1):
        iC = aC[i]
        while aB[iIndex] >= iC:
            iIndex -= 1
            if iIndex < 0:
                break
        if iIndex >= 0 :
            iAns += aAcBA[iIndex]
        else:
            break
    print(iAns)
解()

Buggy submission (verdict: Runtime Error):

import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aA = sorted([int(_) for _ in input().split()])
    aB = sorted([int(_) for _ in input().split()])
    aC = sorted([int(_) for _ in input().split()])

    #解法どおり書くとどれくらいでできるのか計測

    idxA = 0
    idxC = iN-1
    iAns = 0
    for idxB in range(iN):

        iB = aB[idxB]
        while idxA < iN and aA[idxA] < iB:
            idxA += 1
        idxA -= 1
        while 0 <= idxC  and aC[idxC] > iB:
            idxC -= 1
        idxC += 1
        if aA[idxA] >= iB or aC[idxC] <= iB:
            break
        else:
            iAns += (idxA + 1 )* (iN - idxC  )
    print(iAns)
解()
Problem p03599 (python)

Fixed submission:

def 解():
    iA,iB,iC,iD,iE,iF = [int(_) for _ in input().split()]
    #結局全検索
    d = {}
    def searchAll(d,bF): # bF=0 Eにちかづける
        iMaxA = iF // 100*iA
        for i in range(iMaxA+1):
            iMaxB = (iF - 100*iA*i) // iB
            for j in range(iMaxB + 1):
                if i==0 and j==0:
                    continue
                iAB = 100*iA*i + 100*iB*j
                iUlim = iAB * iE //100
                if bF:
                    iUlim = min(iUlim,iF-iAB)
                else:
                    if iUlim > iF - iAB:
                        continue
                iMaxC = iUlim //iC
                for k in range(iMaxC+1):
                    l = (iUlim - iC*k ) //iD
                    iCD = iC*k +iD*l
                    if iUlim -iCD == 0:
                        print(iAB +iCD,iCD)
                        exit()
                    else:
                        iKey = iUlim-iCD
                        if not iKey in d:
                            d[iKey] = (iAB +iCD,iCD)
        return d
    d = searchAll(d,0)
    if not d:
        d = searchAll(d,1)
    iMin = min(d.keys())
    print(" ".join(map(str,d[iMin])))

解()

Buggy submission (verdict: Runtime Error):
def 解():
    iA,iB,iC,iD,iE,iF = [int(_) for _ in input().split()]
    #とりあえず全検索
    d = {}
    iMaxA = iF // 100*iA
    for i in range(iMaxA+1):
        iMaxB = (iF - 100*iA*i) // iB
        for j in range(iMaxB + 1):
            if i==0 and j==0:
                continue
            iAB = 100*iA*i + 100*iB*j
            iUlim = iAB * iE // 100
            if iAB + iUlim > iF :
                continue
            iMaxC = iUlim //iC
            for k in range(iMaxC+1):
                l = (iUlim - iC*k ) //iD
                iCD = iC*k +iD*l
                #if iCD > iF-iAB:
                #   continue
                if iUlim -iCD == 0:
                    print(iAB +iCD,iCD)
                    exit()
                else:
                    iKey = iUlim-iCD
                    if not iKey in d:
                        d[iKey] = (iAB +iCD,iCD)
    iMin = min(d.keys())
    print(" ".join(map(str,d[iMin])))
解()
Problem p03625 (python)

Fixed submission:
def 解():
    iN = int(input())
    aA = reversed(sorted([int(_) for _ in input().split()]))
    iC = 0
    d = {}
    for a in aA:
        if a in d:
            if d[a] == 3:
                print(a*a)
                exit()
            elif iC and iC != a:
                print(iC * a)
                exit()
            else:
                iC = a
                d[a] += 1
        else:
            d[a] = 1
    print(0)
解()

Buggy submission (verdict: Runtime Error):

def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    aA = reversed(sorted(aA))
    d = {}
    for a in aA:
        if a in d:
            if d[a] == 3:
                print(a*a)
                exit()
            elif iC and iC != a:
                print(iC * a)
                exit()
            else:
                iC = a
                d[a] += 1
        else:
            d[a] = 1
    print(0)
解()
Problem p03633 (python)

Fixed submission:
import sys
def 解():
    iN = int(sys.stdin.readline())
    aT = [int(_) for _ in sys.stdin.readlines()]
    #公倍数を求めるだけ
    def fgcd(a,b):
        while b:
            a,b = b, a%b
        return a

    lcm = aT[0]
    for a in aT[1:]:
        lcm = lcm * a // fgcd(lcm,a)
    print(lcm)
解()

Buggy submission (verdict: Runtime Error):

import sys
def 解():
    iN = int(sys.stdin.readline())
    aT = [int(_) for _ in sys.stdin.readlines()]

    #公倍数を求めるだけ

    def fgcd(a,b):
        while b:
            a,b = b, a%b
        return a

    lcm = aT[0] * aT[1] // fgcd(aT[0],aT[1])
    for a in aT[2:]:
        lcm = lcm * a // fgcd(lcm,a)
    print(lcm)
解()
Problem p03695 (python)

Fixed submission:
import sys
iN = int(input())
aA = [int(_)//400 for _ in input().split()]

aCol = [0]*(4800//400 +1)
for a in aA:
    aCol[a] += 1
iMin = 0
for i in range(8):
    if aCol[i]:
        iMin += 1
iMax = iMin + sum(aCol[8:])
if iMin == 0:
    iMin = 1
print(iMin,iMax)

Buggy submission (verdict: Runtime Error):

import sys
iN = int(input())
aA = [int(_) for _ in input().split()]

aCol = [0]*(4800//400)
for a in aA:
    aCol[a//400] += 1
iMin = 0
for i in range(8):
    if aCol[i]:
        iMin += 1
iMax = iMin + sum(aCol[8:])
print(iMin,iMax)
Problem p03739 (python)

Fixed submission:
#結局これもパターン全列挙(2パターン)か。
#判別しようと無駄な努力をしてしまった。
def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    def buildDiff(bF):
        iC = 0
        iS = 0
        for a in aA:
            iS += a
            if bF:
                if iS >= 0:
                    iC += iS + 1
                    iS = -1
                bF = 0
            else:
                if iS <= 0:
                    iC += -1 * iS + 1
                    iS = 1
                bF = 1
        return iC
    print(min(buildDiff(1),buildDiff(0)))
解()

Buggy submission (verdict: Runtime Error):
def 解()
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    iL = len(aA)


    iStart = 0
    if sum(aA[0::2]) < sum(aA[2::2]):
        iStart = 1


    iC = 0
    aD = [0]*iL
    if 0 % 2 == iStart :
        if aA[0] < 0:
            aA[0] = 1
            iC += -1 * aA[0] + 1
    else:
        if 0 < aA[0] :
            aA[0] = -1
            iC += aA[0] + 1

    aD[0] = aA[0]
    for i in range(1,iL):
        aD[i] = aD[i-1]+aA[i]
        if i % 2 == iStart:
            if aD[i] <= 0:
                iC += -1*aD[i] +1
                aD[i] = 1
        else:
            if aD[i] >= 0:
                iC += aD[i] +1
                aD[i] = -1
    print(iC)
解()
Problem p03828 (python)

Fixed submission:

def 解():
    iN = int(input())
    iD = 10**9 + 7


    if iN < 3:
        print(iN)
        exit()

    d素={2:1}
    for i in range(2,iN + 1):
        b素 = 1
        for j in range(2,int(i**0.5)+2):
            if i % j == 0:
                b素 = 0
                break
        if b素 :
            d素[i]=1
    for i in range(2,iN+1):
        for i素 in d素:
            while i % i素 == 0:
                d素[i素]+=1
                i //= i素
    iAns = 1
    for i素,num in d素.items():
        iAns *= num
        iAns %= iD
    print(iAns)
解()

Buggy submission (verdict: Runtime Error):
def 解():
    iN = int(input())
    iD = 10**9 + 7


    if iN < 3:
        print(iN)
        exit()

    d素={2:1}
    for i in range(2,iN + 1):
        b素 = 1
        for j in range(2,int(i**0.5)+2):
            if i % j == 0:
                b素 = 0
                break
        if b素 :
            d素[i]=1
    for i in range(2,iN+1):
        for i素 in d素:
            while i % i素 == 0:
                d素[i素]+=1
                i //= i素
           if i == 0:
                break
    iAns = 1
    for i素,num in d素.items():
        iAns *= num
        iAns %= iD
    print(iAns)
解()
Problem p04000 (python)

Fixed submission:
import sys
iH,iW,iN = [int(_) for _ in input().split()]
aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

iMax = (iH - 2) * (iW -2)
#print (iMax)

dC={}
for i in range(10):
    dC[i]=0

#愚直 無理 つらい
#for i in range(1,iH -1):
#   for j in range(1,iW-1):
#       tmp = 0
#       for a in aD:
#           if j<= a[1] <=j+2 and i<= a[0] <= i+2:
#               tmp +=1
#       dC[tmp] +=1
dM = {}
for a in aD:
    y=a[0]
    x=a[1]
    for aP in [(y-2,x-2),(y-2,x-1),(y-2,x),(y-1,x-2),(y-1,x-1),(y-1,x),(y,x-2),(y,x-1),(y,x)]:
        if 0< aP[0]<iH-1 and 0 < aP[1] < iW-1:
            iP = aP[0]*iW + aP[1]
            if iP in dM:
                dM[iP] += 1
            else:
                dM[iP] = 1
for i in dM:
    dC[dM[i]]+=1

iAllBM=0
for i in range(1,10):
    iAllBM+=dC[i]
dC[0] = iMax -iAllBM

for i in range(10):
    print(dC[i])

Buggy submission (verdict: Runtime Error):
import sys
def 解()
    iH,iW,iN = [int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    iMax = (iH - 2) * (iW -2)
    #print (iMax)

    dC={}
    for i in range(10):
        dC[i]=0

    #愚直 無理 つらい
    #for i in range(1,iH -1):
    #   for j in range(1,iW-1):
    #       tmp = 0
    #       for a in aD:
    #           if j<= a[1] <=j+2 and i<= a[0] <= i+2:
    #               tmp +=1
    #       dC[tmp] +=1

    #なんというか、面倒くさくなって解法みても
    #面倒くさがらずやれとしか書いてなくてつらい
    dM = {}
    for a in aD:
        y=a[0]
        x=a[1]
        for aP in [(y-2,x-2),(y-2,x-1),(y-2,x),(y-1,x-2),(y-1,x-1),(y-1,x),(y,x-2),(y,x-1),(y,x)]:
            if 0< aP[0]<iH-1 and 0 < aP[1] < iW-1:
                iP = aP[0]*iW + aP[1]
                if iP in dM: #もう最初から足したったらええんや
                    dM[iP] += 1
                else:
                    dM[iP] = 1
    for i in dM:
        dC[dM[i]]+=1

    iAllBM=0
    for i in range(1,10):
        iAllBM+=dC[i]
    dC[0] = iMax -iAllBM #点のないマス0は引き算で出せる

    for i in range(10):
        print(dC[i])
解()
Problem p04014 (python)

Fixed submission:
n = int(input())
s = int(input())
rtn = -1* int( -1 * (n**0.5))
def f(b,n):
    if n<b:
        return n
    return f(b,n//b) + n % b
if n < s or (n // 2)+1 < s < n :
    print("-1")
elif s == n:
    print(n+1)
elif s == n//2 +1:
    if n % 2 == 1:
        print(n//2 + 1)
    else:
        print("-1")
elif (n//3) + 2 < s <= n//2:
    print(n-s+1)
else:
    for b in range(2,rtn+1):
        if f(b,n) == s:
            print(b)
            exit()
    for p in range(rtn,0,-1):
        if (n-s) % p == 0:
            b = (n-s)//p + 1
            if f(b,n) == s:
                print(b)
                exit()
    print(n-s+1)

Buggy submission (verdict: Runtime Error):

def f(b,n):
    if n<b:
        return n
    return f(b,n//b) + n % b

if n < s or (n // 2)+1 < s < n :
    print("-1")
elif s == n:
    print(n+1)
elif s == n//2 +1:
    if n % 2 == 1:
        print(n//2 + 1)
    else:
        print("-1")
elif (n//3) + 2 < s <= n//2:
    print(n-s+1)
elif s == 1:
    def check(n,b):
        if n == 1:
            return b
        else:
            if n % b !=0 :
                return 0
            else:
                return check(n // b,b)
    for b in range(2,rtn):
        r = check(n,b)
        if r:
            print(r)
            exit()
    print(n)
else:
    x = n // s
    if s - (n //(x+1))  <= x:
        x = x + 1
    if 5 < n/(x -1) - n/x :
        for b in range(n//x, n//(x-1)):
            if f(b,n) == s:
                print(b)
                exit()
        for i in range(x-1,2,-1):
            for b in range(n//i + (n//x)//(n//i), n//i + (n//x)//(n//i)  + (2*n//x - n//(x+1))//(x-i)):
                if f(b,n) == s:
                    print(b)
                    exit()
    else:
        for b in range(2,(n//3)+3):
            if f(b,n) == s:
                print(b)
                exit()
    print(n-s+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = int(input())

def f(b,n) :
    r = 0
    i = 1
    while n:
        j = n % b
        r += j
        n = (n-j)//b
    return r


if n < s or (n // 2)+1 < s < n :
    print("-1")
elif (n//3) + 2 < s < n//2:
    print(n-s+1)
elif s == n:
    print(n+1)
elif s == 1:
    def check(n,b):
        while 1 < n :
            if n % b != 0:
                break
            n //= b
        if n == 1:
            return b
        return 0
    for b in range(2,int(n**0.5)+2):
        r = check(n,b)
        if r:
            print(r)
            exit()
    print(n)
else:

    x = n // s
    xd = n % s
    if s - xd < x:
        x = x + 1
    if 3 < n/(x -1) - n/x :
        for b in range(n//(x-1),(n//x)+1):
            if f(b,n) == s:
                print(b)
                exit()
    for b in range(2,(n//2)+2):
        if f(b,n) == s:
            print(b)
            exit()
    print(n-s+1)
Problem p04032 (python)

Fixed submission:
sS = input().rstrip()
iL = len(sS)
if iL == 2:
    if sS[0] == sS[1]:
        print ("1 2")
    else:
        print("-1 -1")
    exit()
for i in range(iL-2):
    if sS[i] == sS[i+1] or sS[i] == sS[i+2]:
        print(i+1,i+3) #あぁ..
        exit()
print("-1 -1")

Buggy submission (verdict: Runtime Error):
sS = input().rstrip()
iL = len(sS)
for i in range(iL-1):
    if sS[i] == sS[i+1] :
        print(i+1,i+2)
        exit()
if sS[0] == sS[2]:
    print("1 3")
    exit()
print("-1 -1")

Buggy submission (verdict: Runtime Error):
sS = input().rstrip()
iL = len(sS)
if iL == 2:
    print("-1 -1")
    exit()
for i in range(iL-1):
    if sS[i] == sS[i+1] or sS[i] == sS[i+2]:
        print(i+1,i+3) #あぁ..
        exit()
print("-1 -1")