Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
def main():
    
    arg = getInput(input())
    ans = process(arg)
    print(ans)
    
def process(arg):
    ans = 0
    ensyu = arg[0][0]
    kensu = arg[0][1]
    aida = list()
    for x in range(arg[0][1]):
        mae = arg[1][x-1]
        b = arg[1][x]
        if x == 0:
            w = b + arg[1][kensu-1]
        else:
            w = b - mae
        aida.append(w)

    m = max(aida)
    for y in aida:
        if y != m:
            ans = ans + y
    return ans

def getInput(input):
    k , n = map(int , input().split())
    al = list(map(int , input().split()))

    return [[k,n],al]

if __name__ == '__main__':
    main()


def main():
    arg = getInput(1)
    
    ans = process(arg)
    print(ans)
    
def process(arg):
    ans = 0
    print(arg)
    ensyu = arg[0][0]
    kensu = arg[0][1]
    aida = list()
    for x in range(arg[0][1]):
        mae = arg[1][x-1]
        b = arg[1][x]
        if x == 0:
            w = b + arg[1][kensu-1]
        else:
            w = b - mae
        aida.append(w)

    print(aida)
    m = max(aida)
    for y in aida:
        if y != m:
            ans = ans + y
    return ans

def getInput(input):
    
    n = 2
    
    ret = None
    ret2 = None
    if n == 1:
        pass
        
        
        
        .split()
        
        .split('T')
    else:
        for x in range(n):
            
            if x == 1:
                
                ret = list(map(int, '20 3'.split()))
            else:
                # ret2 = list(map(int, input[x].split()))
                ret2 = list(map(int, '5 10 15'.split()))

    return [ret, ret2]

if __name__ == '__main__':
    main()


def main():
    
    arg = getInput(input())
    ans = process(arg)
    print(ans)
    
def process(arg):
    ans = 0
    ensyu = arg[0][0]
    kensu = arg[0][1]
    aida = list()
    for x in range(arg[0][1]):
        mae = arg[1][x-1]
        b = arg[1][x]
        if x == 0:
            w = b + arg[1][kensu-1]
        else:
            w = b - mae
        aida.append(w)

    m = max(aida)
    for y in aida:
        if y != m:
            ans = ans + y
    return ans

def getInput(input):
    
    n = 2
    
    ret = None
    ret2 = None
    if n == 1:
        pass
        
        
        
        .split()
        
        .split('T')
    else:
        for x in range(n):
            
            ret = list(map(int, input[x].split()))

    return ret

if __name__ == '__main__':
    main()


def main():
    
    arg = getInput(input())
    ans = process(arg)
    print(ans)
    
def process(arg):
    ans = 0
    ensyu = arg[0][0]
    kensu = arg[0][1]
    aida = list()
    for x in range(arg[0][1]):
        mae = arg[1][x-1]
        b = arg[1][x]
        if x == 0:
            w = b + arg[1][kensu-1]
        else:
            w = b - mae
        aida.append(w)

    m = max(aida)
    for y in aida:
        if y != m:
            ans = ans + y
    return ans

def getInput(input):
    
    n = 2
    
    ret = None
    ret2 = None
    if n == 1:
        pass
        
        
        
        .split()
        
        .split('T')
    else:
        for x in range(n):
            
            if x == 1:
                ret = list(map(int, input[x].split()))
                
            else:
                ret2 = list(map(int, input[x].split()))
                # ret2 = list(map(int, '5 10 15'.split()))

    return [ret, ret2]

if __name__ == '__main__':
    main()


def main():
    arg = getInput(1)
    
    ans = process(arg)
    print(ans)
    
def process(arg):
    ans = 0
    ensyu = arg[0][0]
    kensu = arg[0][1]
    aida = list()
    for x in range(arg[0][1]):
        mae = arg[1][x-1]
        b = arg[1][x]
        if x == 0:
            w = b + arg[1][kensu-1]
        else:
            w = b - mae
        aida.append(w)

    m = max(aida)
    for y in aida:
        if y != m:
            ans = ans + y
    return ans

def getInput(input):
    
    n = 2
    
    ret = None
    ret2 = None
    if n == 1:
        pass
        
        
        
        .split()
        
        .split('T')
    else:
        for x in range(n):
            
            if x == 1:
                
                ret = list(map(int, '20 3'.split()))
            else:
                # ret2 = list(map(int, input[x].split()))
                ret2 = list(map(int, '5 10 15'.split()))

    return [ret, ret2]

if __name__ == '__main__':
    main()


def main():
    input1 = input()
    input2 = input()
    k , n = map(int , input1.split())
    al = list(map(int , input2.split()))
    arg = [[k,n],al]
    ans = process(arg)
    print(ans)
    
def process(arg):
    ans = 0
    ensyu = arg[0][0]
    kensu = arg[0][1]
    aida = list()
    for x in range(arg[0][1]):
        mae = arg[1][x-1]
        b = arg[1][x]
        if x == 0:
            
            w = b + ensyu - arg[1][kensu-1]
        else:
            w = b - mae
        aida.append(w)

    m = max(aida)
    flg = False
    for y in aida:
        if flg == True or y != m :
            ans = ans + y
        else:
            flg = True
    return ans

def getInput(input):

    return 

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted