from queue import PriorityQueue

def pair_join(q, n):
    r=0
    while n>1:
        a = q.get()
        b = q.get()
        q.put(a+b)
        r += a+b
        n -= 1
    return r

def main():
    n = int(input())
    size = 0
    minq = PriorityQueue()
    maxq = PriorityQueue()
    for i in range(0,n):
        v = int(input())
        if v>0:
            size += 1
            minq.put(v)
            maxq.put(-v)

    print(f'{pair_join(minq, size)} {-pair_join(maxq, size)}')

if __name__ == '__main__': 
    main()