Buggy python submission (verdict: Time Limit Exceeded):
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
new=[]
plusold=0
result=0
for i in range(num):
    if len(new)==0:
        new.append(sample[i])
    elif len(new)<=2:
        new.append(sample[i])
        result+=sample[i-1]
    else:
        plus=new[len(new)-1]
        point=len(new)
        for j in range(len(new)-1):
            if plus<new[j] and plus<new[j+1]:
                plus=min([new[j],new[j+1]])
                point=j+1
                if plus==plusold:
                    break
        result+=plus
        plusold=plus
        if point==len(new):
            new.append(sample[i])
        else:
            new.insert(point,sample[i])
print(result)


Fixed submission:
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
result=0
for i in range(2,num+1):
    if i%2==0:
        y=i/2-1
        result+=sample[int(y)]
    else:
        y=(i+1)/2-1
        result+=sample[int(y)]
print(result)

Buggy python submission (verdict: Runtime Error):
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
new=[]
pluss=[]
result=0
for i in range(num):
    if len(new)==0:
        new.append(sample[i])
    elif len(new)<=2:
        new.append(sample[i])
        result+=sample[i-1]
    else:
        plus=new[len(new)-1]
        point=len(new)
        for j in range(len(new)-1):
            if plus<new[j] and plus<new[j+1]:
                plus=min([new[j],new[j+1]])
                point=j+1
                if plus==pluss[len(pluss)-1]:
                    break
        result+=plus
        pluss.append(plus)
        if point==len(new):
            new.append(sample[i])
        else:
            new.insert(point,sample[i])
print(result)


Fixed submission:
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
result=0
for i in range(2,num+1):
    if i%2==0:
        y=i/2-1
        result+=sample[int(y)]
    else:
        y=(i+1)/2-1
        result+=sample[int(y)]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
new=[]
result=0
for i in range(num):
    if len(new)==0:
        new.append(sample[i])
    elif len(new)<=2:
        new.append(sample[i])
        result+=sample[i-1]
    else:
        plus=new[len(new)-1]
        point=len(new)
        for j in range(len(new)-1):
            if plus<new[j] and plus<new[j+1]:
                plus=min([new[j],new[j+1]])
                point=j+1
        result+=plus
        if point==len(new):
            new.append(sample[i])
        else:
            new.insert(point,sample[i])
print(result)


Fixed submission:
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
result=0
for i in range(2,num+1):
    if i%2==0:
        y=i/2-1
        result+=sample[int(y)]
    else:
        y=(i+1)/2-1
        result+=sample[int(y)]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
new=[]
result=0
for i in range(num):
    if len(new)==0:
        new.append(sample[i])
    elif len(new)<=2:
        new.append(sample[i])
        result+=sample[i-1]
    else:
        plus=new[len(new)-1]
        point=len(new)
        for j in range(len(new)-1):
            if plus<new[j] and plus<new[j+1]:
                plus=min([new[j],new[j+1]])
                point=j+1
        result+=plus
        if point==len(new):
            new.append(sample[i])
        elif point==len(new)-1:
            new.append(new[len(new)-1])
            new[len(new)-1]=sample[i]
        else:
            new.append(new[len(new)-1])
            for k in range(len(new)-1,point,-1):
                new[k]=new[k-1]
            new[point]=sample[i]
print(result)


Fixed submission:
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
result=0
for i in range(2,num+1):
    if i%2==0:
        y=i/2-1
        result+=sample[int(y)]
    else:
        y=(i+1)/2-1
        result+=sample[int(y)]
print(result)