Problem p02924 (python)

Fixed submission:
N = int(input())
print((N-1)*N//2)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
N = int(input())
candi =int((N+1)/2*N -N)
def f(count,i):
    if i == 2:
        return count +1
    nex_num = (i//2) + 1
    count += (i%nex_num) 
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    return f(count,nex_num)

def f2(count,i):
    if i == 1:
        return count
    nex_num = (i+1)//2
    count += (i%nex_num)
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    return f2(count,nex_num)

if N%2 == 0:
    nex_num = N
    count = f(0,nex_num)
else:
    nex_num = N
    count = f2(0,nex_num)
print(count)
'''
if candi > count:
    print(candi)
else:
    print(count)
'''

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
N = int(input())
candi =int((N+1)/2*N -N)
def f(count,i):
    if i == 2:
        return count +1
    nex_num = (i//2) + 1
    count += (i%nex_num) 
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    return f(count,nex_num)

def f2(count,i):
    if i == 0:
        return count
    nex_num = (i+1)//2
    count += (i%nex_num)
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    return f2(count,nex_num)

if N%2 == 0:
    nex_num = N
    count = f(0,nex_num)
else:
    nex_num = N
    count = f2(0,nex_num)
if candi > count:
    print(candi)
else:
    print(count)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
N = int(input())
candi =int((N+1)/2*N -N)
def f(count,i):
    nex_num = (i//2) + 1
    count += (i%nex_num) 
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 2:
        return count +1
    return f(count,nex_num)

def f2(count,i):
    nex_num = (i+1)//2
    count += (i%nex_num)
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 0:
        return count
    return f2(count,nex_num)

if N%2 == 0:
    nex_num = N
    count = f(0,nex_num)
else:
    nex_num = N
    count = f2(0,nex_num)
if candi > count:
    print(candi)
else:
    print(count)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
N = int(input())
candi =int((N+1)/2*N -N)
def f(count,i):
    nex_num = (i//2) + 1
    count += (i%nex_num) 
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 2:
        return count +1
    return f(count,nex_num)

def f2(count,i):
    nex_num = (i+1)//2
    count += (i%nex_num) 
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 1:
        return count
    return f2(count,nex_num)

if N%2 == 0:
    nex_num = N
    count = f(0,nex_num)
else:
    nex_num = N
    count = f2(0,nex_num)
if candi > count:
    print(candi)
else:
    print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
candi =int((N+1)/2*N -N)
import sys
sys.setrecursionlimit(1000000000)
def f(count,i):
    nex_num = (i//2) + 1
    count += (i%nex_num) #next_numを割るところに使う
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 2:
        return count +1
    return f(count,nex_num)

def f2(count,i):
    nex_num = (i+1)//2
    count += (i%nex_num) #next_numを割るところに使う
    middle_sum = int((i-1 + nex_num )/2*(i -nex_num))
    count += middle_sum
    nex_num = nex_num -1
    if nex_num == 1:
        return count
    return f2(count,nex_num)

if N%2 == 0:
    nex_num = N
    count = f(0,nex_num)
else:
    nex_num = N
    count = f2(0,nex_num)
if candi > count:
    print(candi)
else:
    print(count)