Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        part = xs[i:i + k]
        length = abs(part[0] - part[-1])
        dist = min(abs(part[0]) + length, abs(part[-1]) + length)
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())


Fixed submission:
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        length = abs(xs[i] - xs[i + k - 1])
        dist = min(abs(xs[i]) + length, abs(xs[i + k - 1]) + length)
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        part = xs[i:i + k]
        length = abs(part[0] - part[-1])
        dist = min(abs(part[0]) + length, abs(part[-1]) + length)
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())


Fixed submission:
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        length = abs(xs[i] - xs[i + k - 1])
        dist = min(abs(xs[i]) + length, abs(xs[i + k - 1]) + length)
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        part = xs[i:i + k]
        dist = min(abs(part[0]) + abs(part[0] - part[-1]), abs(part[-1]) + abs(part[0] - part[-1]))
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())


Fixed submission:
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        length = abs(xs[i] - xs[i + k - 1])
        dist = min(abs(xs[i]) + length, abs(xs[i + k - 1]) + length)
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    dists = []
    for i in range(n - k + 1):
        part = xs[i:i + k]
        dist = min(abs(part[0]) + abs(part[0] - part[-1]), abs(part[-1]) + abs(part[0] - part[-1]))
        dists.append(dist)
    return min(dists)


if __name__ == "__main__":
    print(solve())


Fixed submission:
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        length = abs(xs[i] - xs[i + k - 1])
        dist = min(abs(xs[i]) + length, abs(xs[i + k - 1]) + length)
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())

Buggy python submission (verdict: Runtime Error):
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    dists = []
    for i in range(n - k):
        part = xs[i:i + k]
        dist = min(abs(part[0]) + abs(part[0] - part[-1]), abs(part[-1]) + abs(part[0] - part[-1]))
        dists.append(dist)
    return min(dists)


if __name__ == "__main__":
    print(solve())


Fixed submission:
def solve():
    n, k = map(int, input().split())
    xs = list(map(int, input().split()))
    min_dist = 10 ** 9
    for i in range(n - k + 1):
        length = abs(xs[i] - xs[i + k - 1])
        dist = min(abs(xs[i]) + length, abs(xs[i + k - 1]) + length)
        if dist < min_dist:
            min_dist = dist
    return min_dist


if __name__ == "__main__":
    print(solve())