Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        min_max_list = [0] * n
        min_max_dict = {A[1]: 2}
        max_value = A[1]
        score = A[0]
        value_list = [A[1]]
        for num, a in enumerate(A[2:]):
            score += max_value
            min_max_dict[max_value] -= 1
            if a in min_max_dict:
                min_max_dict[a] += 2
            else:
                min_max_dict[a] = 2
                value_list.append(a)
            if min_max_dict[max_value] == 0:
                del(value_list[0])
                max_value = value_list[0]
    print(score)


Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)

Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        min_max_list = [0] * n
        min_max_dict = {A[1]: 2}
        max_value = A[1]
        score = A[0]
        value_list = [A[1]]
        for num, a in enumerate(A[2:]):
            score += max_value
            min_max_dict[max_value] -= 1
            if a in min_max_dict:
                min_max_dict[a] += 2
            else:
                min_max_dict[a] = 2
                value_list.append(a)
            if min_max_dict[max_value] == 0:
                value_list.remove()
                max_value = value_list[0]
    print(score)


Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        min_max_list = [0] * n
        min_max_dict = {A[1]: 2}
        max_value = A[1]
        score = A[0]
        for num, a in enumerate(A[2:]):
            score += max_value
            min_max_dict[max_value] -= 1
            if a in min_max_dict:
                min_max_dict[a] += 2
            else:
                min_max_dict[a] = 2
            if min_max_dict[max_value] == 0:
                del(min_max_dict[max_value])
                max_value = max(min_max_dict.keys())
    print(score)


Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        min_max_list = [0] * n
        min_max_dict = {A[1]: 2}
        max_value = A[1]
        score = A[0]
        for num, a in enumerate(A[2:]):
            score += max_value
            min_max_dict[max_value] -= 1
            if a in min_max_dict:
                min_max_dict[a] += 2
            else:
                min_max_dict[a] = 2
            if min_max_dict[max_value] == 0:
                del(min_max_dict[max_value])
                max_value = max(min_max_dict.keys())
    print(score)


Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        min_max_list = [A[1], A[1]]
        score = A[0]
        for a in A[2:]:
            arg_max_index = min_max_list.index(max(min_max_list))
            score += min_max_list[arg_max_index]
            min_max_list[arg_max_index] = a
            min_max_list.insert(arg_max_index, a)
    print(score)


Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        value_list = A[:2]
        min_max_list = [A[1], A[1]]
        score = A[0]
        for a in A[2:]:
            arg_max_index = min_max_list.index(max(min_max_list))
            score += min_max_list[arg_max_index]
            value_list.insert(arg_max_index + 1, a)
            min_max_list[arg_max_index] = a
            min_max_list.insert(arg_max_index, a)
    print(score)


Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)

Buggy python submission (verdict: Time Limit Exceeded):
def arg_max(target_list):
    max_value = max(target_list)
    for num, i in enumerate(target_list):
        if i == max_value:
            return num
    return -1


if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        value_list = A[:2]
        min_max_list = [A[1], A[1]]
        score = A[0]
        for a in A[2:]:
            arg_max_index = arg_max(min_max_list)
            score += min_max_list[arg_max_index]
            value_list.insert(arg_max_index + 1, a)
            min_max_list[arg_max_index] = a
            min_max_list.insert(arg_max_index, a)
    print(score)


Fixed submission:
if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)