Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    friendliness = [int(x) for x in input().split()]
    friendliness.sort(reversed=True)
    ans = 0
    for i in range(n):
        ans += friendliness[i // 2 + 1]
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque


def main():
    n = int(input())  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)
    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    counter = 0
    while friendliness:
        ans += edges.popleft()
        counter += 1
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)
    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    while friendliness:
        ans += edges.pop()
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
        edges = deque(sorted(edges))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque


def main():
    n = int(input())  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)
    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    counter = 0
    while friendliness:
        ans += edges.popleft()
        counter += 1
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)
    edges = []
    popped1 = friendliness.pop()
    popped2 = friendliness.pop()
    edges.append((popped1, popped2))
    edges.append((popped2, popped1))
    ans = popped1
    while friendliness:
        popped = friendliness.pop()
        tmp_data = (-1, -1)  # max_comfort, edge_index
        for i, edge in enumerate(edges):
            x = min(edge)
            if x > tmp_data[0]:
                tmp_data = (x, i)
        ans += tmp_data[0]
        edge_tmp = edges[tmp_data[1]]
        edges[tmp_data[1]] = (edge_tmp[0], popped)
        edges.append((popped, edge_tmp[1]))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque


def main():
    n = int(input())  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)
    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    counter = 0
    while friendliness:
        ans += edges.popleft()
        counter += 1
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)
    edges = []
    popped1 = friendliness.pop()
    popped2 = friendliness.pop()
    edges.append((popped1, popped2))
    edges.append((popped2, popped1))
    ans = popped1
    while friendliness:
        popped = friendliness.pop()
        tmp_data = (-1, -1)  # max_comfort, edge_index
        for i, edge in enumerate(edges):
            x = min(edge)
            if x > tmp_data[0]:
                tmp_data = (x, i)
        ans += tmp_data[0]
        edge_tmp = edges[tmp_data[1]]
        edges[tmp_data[1]] = (0, 0)
        edges.append((edge_tmp[0], popped))
        edges.append((popped, edge_tmp[1]))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque


def main():
    n = int(input())  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)
    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    counter = 0
    while friendliness:
        ans += edges.popleft()
        counter += 1
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
    print(ans)


if __name__ == '__main__':
    main()