One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. 

Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width w_{i} pixels and height h_{i} pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.

As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.

Print the minimum size of each made photo in pixels. 


-----Input-----

The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. 

Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers w_{i}, h_{i} (1 ≤ w_{i} ≤ 10, 1 ≤ h_{i} ≤ 1000) — the width and height in pixels of the corresponding rectangle.


-----Output-----

Print n space-separated numbers b_1, b_2, ..., b_{n}, where b_{i} — the total number of pixels on the minimum photo containing all friends expect for the i-th one.


-----Examples-----
Input
3
1 10
5 5
10 1

Output
75 110 60 
Input
3
2 1
1 2
2 1

Output
6 4 6

Difficulty: interview

Starter code:

Solutions:
n = int(input())
wihi = [list(map(int,input().split())) for i in range(n)]
W = 0
H = 1
H1 = 1
num = 0
for i in wihi:
    W += i[0]
    H = max(H,i[1])
for i in range(n):
    if num == 0:
        if wihi[i][1] == H:
            num = 1
        else:
            H1 = max(H1,wihi[i][1])
    else:
        H1 = max(H1,wihi[i][1])
if H1 == H:
    for i in wihi:
        print((W - i[0]) * (H),end=" ")
else:
    for i in wihi:
        if i[1] == H:
            print((W - i[0]) * (H1),end=" ")
        else:
            print((W - i[0]) * (H),end=" ")
    


ws = []
hs = []
a = int(input())

maxes = []
maxx = -1
for i in range(a):
    w, h = list(map(int, input().split(' ')))
    
    ws.append(w)
    hs.append(h)

hs2 = hs[:]
hs2.sort()
hs2.reverse()

fir = hs2[0]
sec = hs2[1]

t = sum(ws)
god = []
for i in range(a):
    if hs[i] == fir:
        god.append((t - ws[i]) * sec)
    else:
        god.append((t-ws[i])*fir)
print(' '.join([str(i) for i in god]))


n = int(input())
width = 0
height = [0,0,False]
men = []
for i in range(n):
	man = input().split(' ')
	man[0] = int(man[0])
	man[1] = int(man[1])
	men.append(list(man))
	width += man[0]
	if man[1] > height[0]:
		height[1] = height[0]
		height[0] = man[1]
	elif man[1] == height[0]:
		height[2] = True
	elif man[1] > height[1]:
		height[1] = man[1]
answ = []
for i in range(n):
	answ.append(str((width-men[i][0])*(height[1] if men[i][1] == height[0] and height[2] == False else height[0])))
print(" ".join(answ))

def main():
    n = int(input())
    height = [] 
    width = []
    for i in range(n):
        a, b = map(int, input().split())
        width.append(a)
        height.append(b)
    s_w = sum(width)
    m_h = max(height)
    a = height.index(m_h)
    height[a] = 0
    s_m = max(height)
    height[a] = m_h
    for i in range(n):
        if height[i] != m_h:
            print((s_w -width[i]) * m_h, end=' ')
        else:
            print(s_m * (s_w -width[i]), end=' ')
main()

#!/bin/env python3

from sys import stdin
from collections import namedtuple

Guy = namedtuple('Guy', ['w', 'h'])

maxh1 = 0
maxh2 = 0

guys = []

sumw = 0
stdin.readline()
for line in stdin:
    try:
        w, h = map(lambda s: int(s.strip()), line.lstrip().split(' ', 1))
    except:
        continue
    guys.append(Guy(w, h))
    sumw += w
    if h >= maxh1:
        maxh2 = maxh1
        maxh1 = h
    elif h > maxh2:
        maxh2 = h

for g in guys:
    sq = (sumw - g.w)*(maxh1 if g.h != maxh1 else maxh2)
    print (sq, end=' ')

print()


n = int(input())
wh = []
all_w = 0
max_h = 0
not_sorted = []
for i in range(n):
    current = list(map(int, input().split()))
    max_h = max(max_h, current[1])
    all_w += current[0]
    wh.append(current[::-1])
    not_sorted.append(current)
wh.sort()
for i in range(n):
    if not_sorted[i][1] == max_h:
        print((all_w-not_sorted[i][0])*wh[-2][0], end=" ")
    else:
        print((all_w-not_sorted[i][0])*max_h, end=" ")


__author__ = 'ruckus'

n = int(input())

w = [0 for i in range(n)]
h = [0 for i in range(n)]

max_w = 0
max_h = 0
premax_h = 0
in_w = []
in_h = []
for i in range(n):
    cur_w, cur_h = input().split()
    cur_h = int(cur_h)
    cur_w = int(cur_w)
    max_w += cur_w
    in_w.append(cur_w)
    in_h.append(cur_h)
max_h = max(in_h)
copy_in_h = in_h.copy()
copy_in_h.remove(max_h)
premax_h = max(copy_in_h)
for i in range(n):
    w[i] = max_w - in_w[i]
    if in_h[i] == max_h:
        h[i] = premax_h
    else:
        h[i] = max_h

for w, h in zip(w,h):
    print(w*h, end=' ')

class Struct:
	pass
	
def algorithm():
	try:	
		sum = 0
		count = int(input())
		max_1 = Struct()
		max_2 = Struct()
		max_1.height = 0
		max_1.id = 0
		max_2.height = 0
		max_2.id = 0
		
		if not (2 <= count <= 200000):
			return None
			
		arr = list()
		for i in range(0, count):
			param = input().split(' ')
			width = int(param[0])
			height = int(param[1])
			if (1 <= width <= 10) and (1 <= height <= 1000):
				if height >= max_1.height:
					max_2.height = max_1.height
					max_2.id = max_1.id
					max_1.height = height
					max_1.id = i
				elif height > max_2.height:
					max_2.height = height
					max_2.id = i
				sum += width
				arr.append(width)
			else:
				return None
		
		result = ''
		for i in range(0, count):
			w = sum - arr[i]
			if i == max_1.id:
				h = max_2.height
			else:
				h = max_1.height
			result += str(w * h)
			if i < count - 1: result += ' '
		print(result)
			
	except BaseException:
		return None
	
algorithm()

#!/usr/bin/env python3
# coding: utf-8

n = int(input())

friends = [
    tuple(map(int, input().split()))
    for _ in range(n)
]

w_sum = sum(friend[0] for friend in friends)
top_height_0, top_height_1 = sorted((friend[1] for friend in friends), reverse=True)[:2]

for friend in friends:
    print((w_sum - friend[0]) * (top_height_0 if friend[1] != top_height_0 else top_height_1), end=" ")


n = int(input())
sum,h,w,c=0,[],[],[]
for i in range(n):
    a,b = map (int,input().split ())
    w.append(a)
    h.append(b)
    c.append(b)
    sum+=a
c.sort()
for i in range(n):
    mh = c[n-1]
    if (h[i] == mh):
        mh = c[n-2]
    print((sum-w[i])*mh,end=' ')

import sys

__author__ = 'zumzoom'

n = int(sys.stdin.readline())
A = []
w = 0
h1, h2 = 0, 0
i1 = 0
for line in sys.stdin.readlines()[:n]:
    l = [int(x) for x in line.split()]
    A.append(l[0])
    w += l[0]
    if l[1] > h1:
        h2 = h1
        h1 = l[1]
        i1 = len(A) - 1
    elif l[1] > h2:
        h2 = l[1]

for i in range(n):
    if i == i1:
        print((w - A[i]) * h2, end=' ')
    else:
        print((w - A[i]) * h1, end=' ')


n = int(input())
w_fr = []
h_fr = []
c=0
b=0
itog = ""
d = 0

for i in range(n):
    w, h = map(int, input().split(" "))
    w_fr.append(w)
    h_fr.append(h)
    d += w
    
h_minus_max, h_max = sorted(h_fr)[-2:]

for i in range(n):
    b = d - w_fr[i]
    if h_max == h_fr[i]:
        itog += str(h_minus_max*b) + " "
    else:
        itog += str(h_max*b) + " "
    c=0
    b=0

print(itog[:-1])

#!/usr/bin/env python3
from sys import stdin

n = int(stdin.readline().strip())
w, h = list(), list()
w_sum = 0
h_max = 0
h_second = 0
for i in range(n):
    cur_w, cur_h = map(int, stdin.readline().strip().split())
    w.append(cur_w)
    w_sum += cur_w
    if cur_h <= h_max and cur_h > h_second:
        h_second = cur_h
    if cur_h > h_max:
        h_second = h_max
        h_max = cur_h
        h_max_index = i
        has_single_max = True
    elif cur_h == h_max:
        has_single_max = False

for i in range(n):
    print((w_sum - w[i]) * (h_max if not has_single_max or i != h_max_index else h_second), end=' ')


#import time
#start = time.time()

hwarr = []
l = int(input())
for i in range(l):
    hwarr.append(list(map(int, input().split())))

pixs = ''
sws = sum(hwarr[n][0] for n in range(l))
mhs = max(hwarr[n][1] for n in range(l))
for i in range(l):
    if hwarr[i][1] == mhs:
        mi = i
        break
narr = []
narr += hwarr; narr.pop(mi)
nmhs = max(narr[n][1] for n in range(l-1))

for i in range(l):
    sw = sws - hwarr[i][0]
    if i == mi:
        mh = nmhs
    else:
        mh = mhs
    pixs += str(sw*mh)+' '

print(pixs[:-1])

#stop = time.time()
#print(stop-start)


n = int(input()) #кол друзей
maxW = 0
widthes = []
heigthes = []
for i in range(n):
    w, h = map(int, input().split())
    maxW += w
    widthes.append(w)
    heigthes.append(h)
maxH = max(heigthes)
indexMaxH = heigthes.index(maxH)
for i in range(n):
    if i == indexMaxH:
        el = heigthes.pop(i)
        maxH2 = max(heigthes)
        heigthes.insert(i,el)
        print((maxW - widthes[i]) * maxH2,end = " ")
    else:
        print((maxW - widthes[i]) * maxH,end = " ")

import sys

n = int(sys.stdin.readline())
width = {}
heights = []
for i in range(n):
    w, h = list(map(int, sys.stdin.readline().strip().split()))
    heights.append((h, i))
    width[i] = w
total_width = sum(width.values())

heights.sort(reverse=True)
for i in range(n):
    w = total_width - width[i]
    h = heights[0][0] if heights[0][1] != i else heights[1][0]
    sys.stdout.write(str(w*h) + ' ')


n=int(input())
w=[[] for i in range(n)]
h=[[] for i in range(n)]
h1=[[] for i in range(n)]
sum=0
for i in range(n):
    wi,hi=map(int,input().split())
    w[i]=wi
    h[i]=hi
    h1[i]=hi
    sum+=wi
m1=max(h)


h1.remove(m1)
m2=max(h1)


for i in range(n):
    s1=sum-w[i]
    if h[i]==m1:
        s2=m2
    else:
        s2=m1
       
    print(s1*s2,end=' ')

n = int(input())
ws, hs, ans = [], [], ''
for i in range(n):
    w,h = map(int,input().split())
    ws.append(w)
    hs.append(h)
const = tuple(hs)
sum_ws = sum(ws)
max_hs = (max(hs), hs.index(max(hs)))
for i in range(n):
    if i == max_hs[1]:
        hs[i] = 0
        ans += str((sum_ws-ws[i])*max(hs)) + ' '
        hs = list(const)
        max_hs = (max(hs), hs.index(max(hs)))
    else:
        ans += str((sum_ws-ws[i])*max_hs[0]) + ' '
print(ans[:-1])

n = int(input())
w = [0] * (n)
h = [0] * (n)
for i in range(n):
    w[i], h[i] = map(int, input().split())
s = sum(w)
temp = sorted(h)
m1, m2 = temp[-1], temp[-2]
for i in range(n):
    a = s - w[i]
    b = m1
    if h[i] == m1:
        b = m2
    print(a*b, end=' ')

st=int(input())
summa=0
q=[]
w=[]
ish=[]
for i in range(st):
    z,x=map(int,input().split())
    q.append(z)
    w.append(x)
    ish.append(x)
summa=sum(q)
w.sort()
for i in range(st):
    qw=w[st-1]
    if ish[i]==qw:
        qw=w[st-2]
    print((summa-q[i])*qw,end=' ')

n = int(input())
i=0
w=[]*n
h=[]*n
i=0
while (i<n):
    pair = input().split()
    w.append(int(pair[0]))
    h.append(int(pair[1]))
    i+=1
W=0
for x in w :
    W+=x
h_sorted = sorted(h)
for x in range(0,n):
    W_new = W-w[x]
    if(h[x]==h_sorted[-1]):
        h_new = h_sorted[-2]
    else:
        h_new = h_sorted[-1]
    b= h_new * W_new 
    print(b, end=" ")



	

    


def main():
    n = int(input())
    ww, hh = [0] * n, [0] * n
    for i in range(n):
        w, h = map(int, input().split())
        ww[i], hh[i] = w, h
    hi = sorted(range(n), key=hh.__getitem__)
    width = sum(ww)
    height = hh[hi[-1]]
    for i in hi[:-1]:
        ww[i] = (width - ww[i]) * height
    i = hi[-1]
    ww[i] = (width - ww[i]) * hh[hi[-2]]

    print(' '.join(map(str, ww)))


def __starting_point():
    main()
__starting_point()

def main():
    n = int(input())
    ww, hh = [0] * n, [0] * n
    for i in range(n):
        w, h = map(int, input().split())
        ww[i], hh[i] = w, h
    idx = max(range(n), key=hh.__getitem__)
    mx0 = hh[idx]
    hh[idx] = 1
    mx1 = max(hh)
    width = sum(ww)
    for i, w in enumerate(ww):
        if i == idx:
            ww[i] = (width - ww[i]) * mx1
        else:
            ww[i] = (width - ww[i]) * mx0
    print(' '.join(map(str, ww)))


def __starting_point():
    main()
__starting_point()