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

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Data structures

Implementation


Solutions:
n = int(input())
wh = [tuple(map(int, input().split())) for i in range(n)]
W = sum([kappa[0] for kappa in wh])
pref = [wh[0][1]]
for i in range(1, n):
	pref.append(max(pref[-1], wh[i][1]))
suff = [0] * (n - 1) + [wh[n - 1][1]]
for i in range(n - 2, -1, -1):
	suff[i] = max(suff[i + 1], wh[i][1])
print(' '.join([str((W - wh[i][0]) * max(pref[i - 1] if i - 1 >= 0 else 0, suff[i + 1] if i + 1 < n else 0)) for i in range(n)]))


n = int(input())
width = []
heigth = []
sumw = 0
(h1, h2) = (0, 0)
for i in range(n):
	(w, h) = map(int, input().split())
	width.append(w)
	heigth.append(h)
	sumw += w
	if h > h1:
		h2 = h1
		h1 = h
	elif h > h2:
		h2 = h
for i in range(n):
	if heigth[i] != h1:
		print((sumw - width[i]) * h1, end=' ')
	else:
		print((sumw - width[i]) * h2, 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) + ' ')


mas = []
(sumW, maxH, numMaxH, prevMaxH) = (0, 0, 0, 0)
n = int(input())
for i in range(n):
	(w, h) = [int(j) for j in input().split()]
	sumW += w
	mas.append(w)
	if maxH < h:
		prevMaxH = maxH
		maxH = h
		numMaxH = i
	elif prevMaxH < h:
		prevMaxH = h
for i in range(n):
	if i == numMaxH:
		print((sumW - mas[i]) * prevMaxH, end=' ')
	else:
		print((sumW - mas[i]) * maxH, 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)
	idx = max(range(n), key=hh.__getitem__)
	mx0 = hh[idx]
	wmx = ww[idx]
	hh[idx] = 1
	mx1 = max(hh)
	width = sum(ww)
	for (i, w) in enumerate(ww):
		ww[i] = (width - ww[i]) * mx0
	ww[idx] = (width - wmx) * mx1
	print(' '.join(map(str, ww)))
main()


n = int(input())
w_sum = 0
h_max = -float('inf')
h_sub_max = -float('inf')
w = [0] * n
h = [0] * n
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
	w_sum += w[i]
	if h_max <= h[i]:
		h_sub_max = h_max
		h_max = h[i]
	elif h_sub_max < h[i]:
		h_sub_max = h[i]
for i in range(n):
	if h[i] == h_max:
		print((w_sum - w[i]) * h_sub_max, end=' ')
	else:
		print((w_sum - w[i]) * h_max, end=' ')
print()


import heapq
n = int(input())
w = []
h = []
high = []
for i in range(n):
	(x, y) = map(int, input().split())
	w.append(x)
	h.append(y)
	high.append(y)
	if len(high) > 2:
		high.sort()
		high.pop(0)
ans = []
s = sum(w)
for i in range(n):
	width = s - w[i]
	if high[1] != h[i]:
		height = high[1]
	else:
		height = high[0]
	ans.append(width * height)
print(' '.join(map(str, ans)))


n = int(input())
tot = 0
max1 = 0
a = []
max2 = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append([x, y])
	tot += x
arr = []
for _ in range(n):
	arr.append(a[_][1])
arr.sort()
max1 = arr[-1]
max2 = arr[-2]
for i in range(n):
	w = tot - a[i][0]
	h = max1
	if max1 == a[i][1]:
		h = max2
	print(w * h, end=' ')


n = int(input())
w = []
h = []
sum = 0
for i in range(n):
	(w1, h1) = map(int, input().split())
	w.append(w1)
	h.append(h1)
	sum += w1
a = sorted(h, reverse=True)
for i in range(n):
	if h[i] == a[0]:
		print((sum - w[i]) * a[1])
	else:
		print((sum - w[i]) * a[0])


import math
I = lambda : int(input())
tup = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))

def solve():
	n = I()
	width = []
	height = []
	for i in range(n):
		(w, h) = tup()
		width.append(w)
		height.append(h)
	total_width = sum(width)
	answer = []
	(h1, h2) = (0, 0)
	for i in range(n):
		if height[i] > h1:
			h2 = h1
			h1 = height[i]
		elif height[i] > h2:
			h2 = height[i]
	for i in range(n):
		wid = total_width - width[i]
		if height[i] != h1:
			answer.append(wid * h1)
		else:
			answer.append(wid * h2)
	print(*answer)
t = 1
while t:
	solve()
	t -= 1


(lst_w, lst_h) = ([], [])
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	lst_w.append(a)
	lst_h.append(b)
total_w = sum(lst_w)
sorted_h = sorted(lst_h)
for i in range(n):
	if lst_h[i] == sorted_h[n - 1]:
		print((total_w - lst_w[i]) * sorted_h[n - 2], end=' ')
	else:
		print((total_w - lst_w[i]) * sorted_h[n - 1], end=' ')


n = int(input())
W = []
H = []
sumw = []
maxh = []
s = 0
m = 0
for i in range(n):
	(w, h) = map(int, input().split())
	W.append(w)
	H.append(h)
	s += w
(h, I) = (0, 0)
for y in H:
	if y > h:
		(I, h) = (h, y)
	elif y > I:
		I = y
for i in range(n):
	sumw.append(s - W[i])
ans = []
for i in range(n):
	ans.append(sumw[i] * (I if H[i] == h else h))
print(' '.join((str(i) for i in ans)))


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
lst1 = []
lst2 = []
(s1, s2) = (0, 0)
c = 0
mx = 0
for i in range(num):
	(x, y) = zz()
	s1 += x
	s2 += y
	lst1.append(x)
	lst2.append(y)
	mx = max(mx, y)
lst3 = sorted(lst2)
for (i, j) in zip(lst1, lst2):
	w = s1 - i
	h = lst3[-1]
	if h == j:
		h = lst3[-2]
	print(h * w)


from collections import deque
from collections import Counter
from itertools import permutations
import heapq

def counterExample():
	arr = [1, 3, 4, 1, 2, 1, 1, 3, 4, 3, 5, 1, 2, 5, 3, 4, 5]
	counter = Counter(arr)
	top_three = counter.most_common(3)
	print(top_three)
q = deque()
import math

def main():
	n = int(input())
	wh = []
	for i in range(n):
		wh.append(tuple([int(i) for i in input().split()]))
	s = sum([i for (i, j) in wh])
	h = [j for (i, j) in wh]
	max1 = max(h)
	h.remove(max1)
	max2 = max(h)
	values = []
	for (w, h) in wh:
		sH = s - w
		if h == max1:
			values.append(sH * max2)
		else:
			values.append(sH * max1)
	print(' '.join([str(i) for i in values]))
main()


W = []
H = []
for h in range(int(input())):
	(w, h) = map(int, input().strip().split())
	W.append(w)
	H.append(h)
(first, second) = (0, min('inf'))
for i in H:
	if i > first:
		second = first
		first = i
	elif i > second:
		second = i
ans = []
sumW = sum(W)
for i in range(len(H)):
	if H[i] == first:
		ans.append(second * (sumW - W[i]))
	else:
		ans.append(first * (sumW - W[i]))
print(*ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
W = []
H = []
s = 0
n = I()
for i in range(n):
	(w, h) = R()
	s += w
	W += (w,)
	H += (h,)
p = sorted(H, reverse=True)[:2]
for i in range(n):
	print((s - W[i]) * (p[0] if p[0] != H[i] else p[1]))


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)

def output(answer):
	stdout.write(str(answer))
num = int(z())
lst_x = [0] * num
lst_y = [0] * num
s = 0
for i in range(num):
	(x, y) = zzz()
	s += x
	lst_x[i] = x
	lst_y[i] = y
lst = lst_y
lst_y = sorted(lst_y)
ans = []
for (i, j) in zip(lst_x, lst):
	w = s - i
	h = lst_y[-1]
	if h == j:
		h = lst_y[-2]
	print(w * h)


from math import *
n = int(input())
w = []
h = []
for i in range(0, n):
	a = list(map(int, input().split()))
	w.append(a[0])
	h.append(a[1])
W = sum(w)
H = max(h)
h2 = h
maxid = h2.index(H)
del h2[maxid]
H2 = max(h2)
h.insert(maxid, H)
for i in range(0, n):
	if H != h[i]:
		print(H * (W - w[i]), end=' ')
	else:
		print(H2 * (W - w[i]), end=' ')


n = int(input())
h = []
w = []
w_sum = 0
max1 = -111
for i in range(n):
	(t2, t1) = map(int, input().split())
	h.append(t1)
	w.append(t2)
	w_sum += t2
	if t1 > max1:
		max1 = t1
temp = -100
for i in range(n):
	sum1 = 0
	sum2 = max1
	sum1 = w_sum - w[i]
	if sum2 > h[i]:
		print(sum1 * sum2, end=' ')
	else:
		for j in range(n):
			if j != i:
				if temp < h[j]:
					temp = h[j]
				if temp == max1:
					break
		print(temp * sum1, end=' ')


n = int(input())
pics = []
W = 0
b = []
(H1, H2) = (-1, -1)
(h1, h2) = (0, 0)
for i in range(n):
	(w, h) = map(int, input().split())
	W += w
	if h > h1:
		H2 = H1
		h2 = h1
		h1 = h
		H1 = i
	elif h > h2:
		h2 = h
		H2 = i
	pics.append((w, h))
for i in range(n):
	Width = W - pics[i][0]
	if i == H1:
		Height = h2
	else:
		Height = h1
	b.append(Width * Height)
for num in b:
	print(num, end=' ')


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=' ')


n = int(input())
s = 0
width = []
height = []
first = -float('inf')
second = -float('inf')
for i in range(n):
	(w, h) = map(int, input().split())
	width.append(w)
	height.append(h)
	s += w
	if h > first:
		second = first
		first = h
	elif h > second:
		second = h
for i in range(n):
	if height[i] == first:
		print(second * (s - width[i]), end=' ')
	else:
		print(first * (s - width[i]), end=' ')


n = int(input())
w = []
h = []
for i in range(n):
	(a, b) = map(int, input().split())
	w.append(a)
	h.append(b)
sorth = sorted(h)
summ = sum(w)
lenh = len(h)
for i in range(n):
	k = summ - w[i]
	if sorth[lenh - 1] == h[i]:
		r = sorth[lenh - 2]
	else:
		r = sorth[lenh - 1]
	print(k * r, end=' ')


__author__ = 'aste'

def main():
	n = int(input())
	w = [0] * n
	h = [0] * n
	total_width = 0
	for i in range(0, n):
		(w[i], h[i]) = map(int, input().split())
		total_width += w[i]
	max_h_f = [0] * n
	max_h_b = [0] * n
	for i in range(1, n):
		max_h_f[i] = max(h[i - 1], max_h_f[i - 1])
	for i in range(n - 2, -1, -1):
		max_h_b[i] = max(h[i + 1], max_h_b[i + 1])
	for i in range(0, n):
		max_w = total_width - w[i]
		max_h = max(max_h_f[i], max_h_b[i])
		print(max_w * max_h, end=' ')
main()


n = int(input())
W = 0
w_list = []
h_max = 0
ind_max = 0
h_m = 0
for _ in range(n):
	(w, h) = map(int, input().split())
	w_list.append(w)
	W += w
	if h >= h_max:
		(h_max, h_m) = (h, h_max)
		ind_max = _
	elif h > h_m:
		h_m = h
for i in range(ind_max):
	print((W - w_list[i]) * h_max, end=' ')
print((W - w_list[ind_max]) * h_m, end=' ')
for i in range(ind_max + 1, n):
	print((W - w_list[i]) * h_max, end=' ')


n = int(input())
L = [list(map(int, input().split())) for i in range(n)]
L1 = sorted(L, key=lambda x: x[1])
su = 0
for x in L:
	su += x[0]
s = ''
for x in L:
	if L1[-1][1] == x[1]:
		s += str((su - x[0]) * L1[-2][1]) + ' '
	else:
		s += str((su - x[0]) * L1[-1][1]) + ' '
print(s)


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())
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=' ')


n = int(input())
ar = []
max1 = 0
max2 = 0
tw = 0
for i in range(n):
	(w, h) = map(int, input().split())
	tw += w
	if h >= max1:
		max2 = max1
		max1 = h
	if max2 < h and h < max1:
		max2 = max(max2, h)
	ar.append((w, h))
for i in range(n):
	if ar[i][1] == max1:
		print((tw - ar[i][0]) * max2, end=' ')
	else:
		print((tw - ar[i][0]) * max1, end=' ')


from queue import PriorityQueue
import sys
input = sys.stdin.readline

def main():
	q = PriorityQueue()
	N = int(input())
	widthsum = 0
	width = []
	height = []
	maxh = 0
	for i in range(N):
		(W, H) = list(map(int, input().split()))
		widthsum += W
		width.append(W)
		height.append(H)
		q.put((-H, H))
	maxh = q.queue[0][1]
	b = q.get()
	g = q.get()[1]
	for i in range(N):
		t = widthsum - width[i]
		if height[i] != maxh:
			print(maxh * t, end=' ')
		else:
			print(g * t, end=' ')
main()


n = int(input())
_list_ = [tuple(map(int, input().split())) for _ in range(n)]
width = [x[0] for x in _list_]
height = [x[1] for x in _list_]
max1 = max(height)
h = height.copy()
del h[h.index(max1)]
max2 = max(h)
s = sum(width)
for i in range(n):
	a = s - width[i]
	b = height[i]
	x = 0
	if b == max1:
		x = max2 * a
	else:
		x = max1 * a
	print(x, end=' ')


from collections import defaultdict as dc
import sys
import math
mod = 10 ** 9 + 7

def sinp():
	p = str(sys.stdin.readline())
	return p

def seive(n):
	p = [0] * (n + 1)
	for i in range(2, n):
		for j in range(2 * i, n + 1, i):
			p[i] = 1
	return p

def inp():
	p = int(sys.stdin.readline())
	return p

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def ind(a):
	return ord(a) - ord('A')

def digit(n):
	z = n
	p = 0
	q = 0
	while z:
		if z % 10 > p:
			q = p
			p = z % 10
		elif z % 10 > q:
			q = z % 10
		z = z // 10
	return (p, q)

def solve(t):
	n = inp()
	p = []
	w = 0
	h1 = 0
	h2 = 0
	for i in range(n):
		p.append(line())
		w += p[-1][0]
		if p[-1][1] > h1:
			h2 = h1
			h1 = p[-1][1]
		elif p[-1][1] > h2:
			h2 = p[-1][1]
	for i in range(n):
		if p[i][1] == h1:
			print((w - p[i][0]) * h2, end=' ')
		else:
			print((w - p[i][0]) * h1, end=' ')
	print()
t = 1
for _ in range(t):
	solve(t)


n = int(input())
total = 0
width = []
height = []
he = []
for i in range(0, n):
	(w, h) = [int(x) for x in input().split()]
	total += w
	width.append(w)
	height.append(h)
	he.append(h)
he.sort()
for i in range(0, n):
	if height[i] == he[n - 1]:
		print(he[n - 2] * (total - width[i]), end=' ')
	else:
		print(he[n - 1] * (total - width[i]), end=' ')


n = int(input())
w = [0] * n
h = [0] * n
s = 0
(W, H) = (0, 0)
(h1, h2) = (0, 0)
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
	W += w[i]
	H += h[i]
	if h[i] > h1:
		(h2, h1) = (h1, h[i])
	elif h1 >= h[i] > h2:
		h2 = h[i]
for i in range(n):
	d = h1 if h[i] != h1 else h2
	print((W - w[i]) * d, end=' ')


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=' ')


def read_data():
	n = int(input())
	data = []
	for i in range(0, n):
		data.append([int(x) for x in input().split(' ')])
	return data

def foo(data):
	width = []
	heights = []
	result = ''
	for row in data:
		width.append(row[0])
		heights.append(row[1])
	width = sum(width)
	heights.sort(reverse=True)
	for row in data:
		w = width - row[0]
		if row[1] == heights[0]:
			h = heights[1]
		else:
			h = heights[0]
		result += str(w * h) + ' '
	return result[:len(result) - 1]
print(foo(read_data()))


s = 0
L = []
M = []
for i in range(int(input())):
	(w, l) = map(int, input().split())
	L.append((w, l))
	s += w
	M.append(l)
M.sort(reverse=True)
for i in L:
	if i[1] != M[0]:
		print((s - i[0]) * M[0], end=' ')
	else:
		print((s - i[0]) * M[1], end=' ')


import sys
inputlist = sys.stdin.readlines()
number_of_friends = int(inputlist[0])
width_list = []
height_list = []
sum_of_widths = 0
for i in range(number_of_friends):
	(w, h) = list(map(int, inputlist[i + 1].strip().split(' ')))
	width_list.append(w)
	height_list.append(h)
	sum_of_widths = sum_of_widths + w
if height_list[0] > height_list[1]:
	(max, second_max) = (height_list[0], height_list[1])
else:
	(max, second_max) = (height_list[1], height_list[0])
for i in height_list[2:]:
	if i >= max:
		second_max = max
		max = i
	elif i > second_max:
		second_max = i
for i in range(number_of_friends):
	width = sum_of_widths - width_list[i]
	height = second_max if height_list[i] == max else max
	print(width * height, end=' ')


n = int(input())
(dim, w, h) = ([], [0 for _ in range(n)], [0 for _ in range(n)])
for _ in range(n):
	dim.append([int(i) for i in input().split()])
temp_w = 0
for i in range(1, n):
	temp_w += dim[i - 1][0]
	w[i] = temp_w
	h[i] = max(dim[i - 1][1], h[i - 1])
temp_w = 0
temp_h = -float('inf')
for i in range(n - 2, -1, -1):
	temp_w += dim[i + 1][0]
	temp_h = max(temp_h, dim[i + 1][1])
	w[i] += temp_w
	h[i] = max(h[i], temp_h)
print(*[w[i] * h[i] for i in range(n)])


n = int(input().rstrip())
w = [0] * n
h = [0] * n
for i in range(n):
	(w[i], h[i]) = [int(j) for j in input().split()]
suma = sum(w)
max1 = max(h)
max2 = 0
if h.count(max1) != 1:
	max2 = max1
else:
	for i in range(n):
		if h[i] != max1:
			max2 = max(max2, h[i])
for i in range(n):
	if h[i] == max1:
		print((suma - w[i]) * max2)
	else:
		print((suma - w[i]) * max1)


import math
import array as arr
inarr = lambda : map(int, input().split())
n = int(input())
a = []
b = []
s = 0
fir = -float('inf')
sec = -float('inf')
for _ in range(n):
	(w, h) = map(int, input().split())
	a.append(w)
	b.append(h)
	s += w
	if h > fir:
		sec = fir
		fir = h
	elif h > sec:
		sec = h
i = 0
while i < n:
	if b[i] == fir:
		print(sec * (s - a[i]), end=' ')
	else:
		print(fir * (s - a[i]), end=' ')
	i = i + 1


n = int(input())
l = []
sum = 0
for i in range(n):
	y = [int(x) for x in input().split()]
	l.append(y)
	sum += y[0]

def func(x):
	return x[1]
k = sorted(l, key=func, reverse=True)
max_h = k[0][1]
h = 0
w = 0
for i in range(n):
	if l[i][1] == max_h and len(l) > 1:
		h = k[1][1]
		w = sum - l[i][0]
	elif len(l) > 1:
		h = max_h
		w = sum - l[i][0]
	print(h * w)


n = int(input())
(W, H, H2) = (0, 0, 0)
data = []
for i in range(n):
	(wi, hi) = map(int, input().split())
	W += wi
	H = max(H, hi)
	data.append((wi, hi))
help = []
for i in range(n):
	help.append([data[i][1], True])
for i in range(n):
	if help[i][0] == H:
		help[i][1] = False
		break
for i in range(n):
	if help[i][1]:
		H2 = max(H2, help[i][0])
for i in range(n):
	if data[i][1] == H:
		print((W - data[i][0]) * H2, end=' ')
	else:
		print((W - data[i][0]) * H, end=' ')


def solve_(a):
	for (i, v) in enumerate(a):
		v.append(i)
	a.sort(key=lambda x: x[1], reverse=True)
	all_width = 0
	for item in a:
		all_width += item[0]
	for (i, v) in enumerate(a):
		h = a[0][1] if i > 0 else a[i + 1][1]
		width = all_width - v[0]
		total = width * h
		v.append(total)
	a.sort(key=lambda x: x[2])
	s = ''
	for (i, v) in enumerate(a):
		s = s + str(v[3]) + ' '
	return s.strip()

def solve(a):
	h1 = h2 = 0
	all_width = 0
	for item in a:
		all_width += item[0]
		h = item[1]
		if h >= h1:
			h2 = h1
			h1 = h
		elif h >= h2:
			h2 = h
	s = [0] * len(a)
	for (i, v) in enumerate(a):
		w = v[0]
		h = v[1]
		if h == h1:
			h = h2
		else:
			h = h1
		t = (all_width - w) * h
		s[i] = str(t)
	return ' '.join(s)

def main():
	t = int(input())
	a = []
	for _ in range(t):
		at = list(map(int, input().split()))
		a.append(at)
	print(solve(a))

def test():
	a = [[1, 10], [5, 5], [10, 1]]
	print(solve(a))
main()


n = int(input())
A = [0] * n
sums = 0
ans = 0
ans2 = -1
for i in range(n):
	(per1, per2) = map(int, input().split())
	sums += per1
	if per2 >= ans:
		ans2 = ans
		ans = per2
	elif per2 > ans2:
		ans2 = per2
	A[i] = [per1, per2]
for i in range(n):
	print((sums - A[i][0]) * (ans if A[i][1] != ans else ans2), end=' ')


n = int(input())
w = []
h = []
sw = 0
for i in range(n):
	st = input().split()
	w.append(int(st[0]))
	h.append(int(st[1]))
s = sum(w)
mh = h.index(max(h))
mm = max(h)
for i in range(n):
	sd = s - w[i]
	if i == mh:
		saveH = h.pop(i)
		m = max(h)
		h.insert(i, saveH)
		print(sd * m, end=' ')
		m = mm
	else:
		m = mm
		print(sd * m, end=' ')


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	(W, H) = ([], [])
	(tw, mh1, mh2) = (0, 0, 0)
	for x in range(n):
		(a, b) = map(int, input().split())
		W.append(a)
		H.append(b)
		tw += a
		if b > mh1:
			mh2 = max(mh1, mh2)
			mh1 = b
		elif b > mh2:
			mh2 = b
	ans = []
	for x in range(n):
		if H[x] != mh1:
			ans.append((tw - W[x]) * mh1)
		else:
			ans.append((tw - W[x]) * mh2)
	print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
mp = {}
for i in range(n):
	mp[i + 1] = list(map(int, input().split()))
	mp[i + 1].append(i + 1)
widthSum = 0
for i in list(mp.keys()):
	widthSum += mp[i][0]
keys = list(mp.values())
keys = list(sorted(keys, key=lambda x: x[1]))
for i in range(1, n + 1):
	if keys[-1][2] != i:
		calc = (widthSum - mp[i][0]) * keys[-1][1]
	else:
		calc = (widthSum - mp[i][0]) * keys[-2][1]
	print(calc, end=' ')
print()


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


s = 0
L = []
M = []
for i in range(int(input())):
	(w, l) = [int(x) for x in input().split()]
	L.append((w, l))
	s += w
	M.append(l)
M.sort()
M = M[::-1]
for i in L:
	if i[1] == M[0]:
		print(M[1] * (s - i[0]))
	else:
		print(M[0] * (s - i[0]))


n = int(input())
w = [0] * n
h = [0] * n
hh = [0] * n
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
	hh[i] = h[i]
ww = sum(w)
h.sort(reverse=True)
ans = []
for i in range(n):
	if hh[i] == h[0]:
		ans.append((ww - w[i]) * h[1])
	else:
		ans.append((ww - w[i]) * h[0])
print(*ans)


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])


from sys import stdin, stdout
from math import gcd, log2
import math
from collections import defaultdict
import sys
input = stdin.readline
print = stdout.write
n = int(input())
w = [0] * n
h = [0] * n
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
sumofwidth = sum(w)
maxheight = max(h)
countofmaxheight = h.count(maxheight)
secondmaxheight = 0
if countofmaxheight == 1:
	for i in range(n):
		if h[i] > secondmaxheight and h[i] < maxheight:
			secondmaxheight = h[i]
for i in range(n):
	a = sumofwidth - w[i]
	if h[i] == maxheight and countofmaxheight == 1:
		b = secondmaxheight
	else:
		b = maxheight
	print(str(a * b) + ' ')


(a, b) = ([], [])
for i in range(int(input())):
	(q, w) = map(int, input().split())
	a += [q]
	b += [w]
r = sorted(b)
e = sum(a)
l = []
for i in range(len(a)):
	l += [(e - a[i]) * (r[-1] if r[-1] != b[i] else r[-2])]
print(*l)


(h, w) = ([], [])
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	w.append(a)
	h.append(b)
maxh = max(h)
maxh2 = -1
if h.count(maxh) > 1:
	maxh2 = maxh
else:
	for i in h:
		if i < maxh:
			maxh2 = max(maxh2, i)
sumw = sum(w)
for i in range(n):
	W = sumw - w[i]
	if h[i] == maxh:
		H = maxh2
	else:
		H = maxh
	print(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=' ')


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]))


a = int(input())
w = []
h = []
for i in range(a):
	(x, y) = map(int, input().split())
	w.append(x)
	h.append(y)
sw = sum(w)
sh = [max(h), max(h[:h.index(max(h))] + h[h.index(max(h)) + 1:])]
for i in range(a):
	print((sw - w[i]) * sh[sh[0] == h[i]], end=' ')


import heapq
totalW = 0
w = []
h = []
hq = []
for item in range(int(input())):
	(currentW, currentH) = map(int, input().split())
	w.append(currentW)
	h.append(currentH)
	heapq.heappush(hq, currentH)
	totalW += currentW
result = []
largest = heapq.nlargest(2, hq)
for (i, item) in enumerate(w):
	if largest[0] == h[i]:
		hei = largest[1]
	else:
		hei = largest[0]
	result.append(str((totalW - item) * hei))
print(' '.join(result))


n = int(input())
r = lambda : list(map(int, input().split()))
arr = [r() for _ in range(n)]
x = arr[:]
x = list(enumerate(x))
x.sort(reverse=True, key=lambda x: x[1][1])
s = sum([i[0] for i in arr])
for (i, j) in enumerate(arr):
	w = s - j[0]
	if i == x[0][0]:
		print(w * x[1][1][1], end=' ')
	else:
		print(w * x[0][1][1], end=' ')


class Person:

	def __init__(self, w, h):
		self.h = h
		self.w = w
n = int(input())
p = []
for i in range(n):
	(w, h) = list(map(int, input().split()))
	p.append(Person(w, h))
s = 0
m1 = m2 = 0
for i in p:
	s += i.w
	if i.h > m1:
		m2 = m1
		m1 = i.h
	elif i.h > m2:
		m2 = i.h
for i in range(len(p)):
	h = m1
	if p[i].h == m1:
		h = m2
	print(h * (s - p[i].w), end=' ')


n = int(input())
w = []
h = []
for x in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	w.append(a)
	h.append(b)
sums = 0
for i in w:
	sums += i
maxm = -1
maxmm = -1
i = 0
while i < len(h):
	if h[i] >= maxm:
		maxmm = maxm
		maxm = h[i]
	if h[i] > maxmm and h[i] < maxm:
		maxmm = h[i]
	i += 1
strs = ''
for i in range(n):
	if h[i] == maxm:
		ans = (sums - w[i]) * maxmm
	else:
		ans = (sums - w[i]) * maxm
	strs += str(ans)
	strs += ' '
print(strs[:-1])


n = int(input())
w = [0] * (n + 1)
h = [0] * (n + 1)
sum = 0
maxl = [0] * (n + 1)
maxr = [0] * (n + 2)
for i in range(1, n + 1):
	(w[i], h[i]) = [int(x) for x in input().split()]
	sum += w[i]
	maxl[i] = max(maxl[i - 1], h[i])
for i in range(n, 0, -1):
	maxr[i] = max(maxr[i + 1], h[i])
for i in range(1, n + 1):
	print((sum - w[i]) * max(maxl[i - 1], maxr[i + 1]), end=' ')


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()


n = int(input())
W = H1 = H2 = 0
w = [0] * n
h = [0] * n
for i in range(n):
	(tmpW, tmpH) = [int(s) for s in input().split()]
	w[i] = tmpW
	h[i] = tmpH
	W += tmpW
	if H1 < tmpH:
		H2 = H1
		H1 = tmpH
	elif H2 < tmpH:
		H2 = tmpH
for i in range(n):
	localMax = H1 if H1 != h[i] else H2
	print((W - w[i]) * localMax, end=' ')


n = int(input())
heights = []
weights = []
sum_weights = 0
for i in range(n):
	(w, h) = [int(x) for x in input().split()]
	sum_weights += w
	weights.append(w)
	heights.append((h, i))
heights.sort(key=lambda x: x[0])
for i in range(n - 1):
	if heights[-1][1] == i:
		print((sum_weights - weights[i]) * heights[-2][0], end=' ')
	else:
		print((sum_weights - weights[i]) * heights[-1][0], end=' ')
if heights[-1][1] == n - 1:
	print((sum_weights - weights[n - 1]) * heights[-2][0])
else:
	print((sum_weights - weights[n - 1]) * heights[-1][0])


friends = []
n = int(input())
full_w = 0
max_h = 0
smax_h = 0
for i in range(n):
	(w, h) = input().split()
	(w, h) = (int(w), int(h))
	full_w += w
	if max_h < h:
		smax_h = max_h
		max_h = h
	else:
		smax_h = max(smax_h, h)
	friends.append((w, h))
answer = ''
for i in range(len(friends)):
	(cw, ch) = (friends[i][0], friends[i][1])
	w = full_w - cw
	h = max_h if max_h != ch else smax_h
	answer += str(w * h) + ' '
answer = answer[:-1]
print(answer)


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())
(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, h) = ([], [])
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	w.append(a)
	h.append(b)
s = 0
for i in w:
	s += i
sorted_h = sorted(h)
ans = []
for i in range(n):
	wi = s - w[i]
	tmp = sorted_h[-1]
	if h[i] == sorted_h[-1]:
		tmp = sorted_h[-2]
	ans.append(wi * tmp)
print(*ans)


n = int(input())
W = []
H = []
for i in range(n):
	(a, b) = map(int, input().split())
	W.append(a)
	H.append(b)
copy = H.copy()
copy.sort(reverse=True)
Wsum = sum(W)
for i in range(n):
	if H[i] != copy[0]:
		print((Wsum - W[i]) * copy[0], end=' ')
	else:
		print((Wsum - W[i]) * copy[1], end=' ')
print()


n = int(input())
ls = []
temp1 = 0
temp2 = []
for i in range(n):
	(w, h) = map(int, input().split())
	temp1 += w
	temp2.append(h)
	ls.append([w, h])
temp2.sort(reverse=True)
for i in range(n):
	if ls[i][1] != temp2[0]:
		print((temp1 - ls[i][0]) * temp2[0], end=' ')
	else:
		print((temp1 - ls[i][0]) * temp2[1], end=' ')
print()


n = int(input())
w = []
h = []
for _ in range(n):
	(wi, hi) = map(int, input().split(' '))
	w.append(wi)
	h.append(hi)
m1 = -1
m2 = -1
width = sum(w)
t1 = list(h)
t1.sort()
m1 = t1[-1]
m2 = t1[-2]
for i in range(n):
	if h[i] != m1:
		print((width - w[i]) * m1, end=' ')
	else:
		print((width - w[i]) * m2, end=' ')


n = int(input())
friends = []
Wob = 0
Hob = [0, 0]
for i in range(n):
	(w, h) = [int(j) for j in input().split()]
	friends.append([w, h])
	Wob += w
	if h > Hob[0]:
		Hob[1] = Hob[0]
		Hob[0] = h
	elif h > Hob[1]:
		Hob[1] = h
for f in friends:
	w = Wob - f[0]
	h = Hob[0]
	if f[1] == Hob[0]:
		h = Hob[1]
	print(w * h, end=' ')


n = int(input())
h0 = int(-1)
h1 = int(-1)
arr = []
sw = int(0)
cnt = int(0)
for _ in range(n):
	(w, h) = map(int, input().split())
	arr.append([w, h])
	sw += w
	if h0 < h:
		cnt = 0
		h0 = h
	elif h0 == h:
		cnt += 1
for x in arr:
	if x[1] != h0 and x[1] > h1:
		h1 = x[1]
if cnt > 0:
	h1 = h0
for i in range(len(arr)):
	if arr[i][1] == h0:
		print((sw - arr[i][0]) * h1, end=' ')
	else:
		print((sw - arr[i][0]) * h0, 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=' ')


n = int(input())
arr = []
hs = []
for _ in range(n):
	(w, h) = map(int, input().split())
	arr.append((w, h))
	hs.append(h)
hs.sort()
h_max = hs[-1]
w_sum = sum([i[0] for i in arr])
ans = []
for i in range(n):
	w = w_sum - arr[i][0]
	h = arr[i][1]
	if h == h_max:
		ans.append(w * hs[-2])
	else:
		ans.append(w * h_max)
print(*ans)


n1 = input()
n = int(n1)
w = list()
h = list()
w_sum = 0
h_max1 = 0
h_max2 = 0
for i in range(n):
	(wt1, ht1) = input().split()
	wt = int(wt1)
	ht = int(ht1)
	w.append(wt)
	h.append(ht)
	w_sum += wt
	if ht > h_max1:
		h_max2 = h_max1
		h_max1 = ht
	elif ht > h_max2:
		h_max2 = ht
for i in range(n):
	wt = w_sum - w[i]
	ht = h_max1
	if h[i] == h_max1:
		ht = h_max2
	a = wt * ht
	print(a, end=' ')


import sys
input = sys.stdin.readline
print = sys.stdout.write
n = int(input())
a = [0] * 10 ** 6
b = [0] * 10 ** 6
sm = 0
for x in range(n):
	el = input().split()
	a[x] = int(el[0])
	b[x] = int(el[1])
	sm += a[x]
ma = max(b)
ma2 = 0
flag = 0
flag2 = 0
for i in range(n):
	if b[i] == ma:
		flag += 1
		flag2 = i
if flag == 1:
	for i in range(n):
		if b[i] != ma:
			ma2 = max(ma2, b[i])
if flag == 1:
	for i in range(n):
		if i == flag2:
			print(str(ma2 * (sm - a[i])) + ' ')
		else:
			print(str(ma * (sm - a[i])) + ' ')
else:
	for i in range(n):
		print(str(ma * (sm - a[i])) + ' ')


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))


from sys import stdin
from heapq import heapify, heappush, heappop
n = int(stdin.readline())
a = [tuple(map(int, stdin.readline().split())) for _ in range(n)]
sumW = sum([v[0] for v in a])
pq = [(-a[i][1], i) for i in range(n)]
heapify(pq)
ret = []
for (i, (w, _)) in enumerate(a):
	(p1, p2) = (heappop(pq), None)
	if p1[1] == i:
		p2 = heappop(pq)
	maxH = -p2[0] if p2 else -p1[0]
	heappush(pq, p1)
	if p2:
		heappush(pq, p2)
	ret.append(maxH * (sumW - w))
print(*ret)


n = int(input())
A = []
B = []
C = []
for i in range(n):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
	C.append(b)
S = 0
for i in range(len(A)):
	S += A[i]
C.sort()
D = []
for i in range(n):
	t = S - A[i]
	if B[i] == C[-1]:
		V = t * C[-2]
	else:
		V = t * C[-1]
	D.append(V)
for i in range(len(D)):
	print(D[i], end=' ')


a = []
wSum = 0
for i in range(int(input())):
	a.append(list(map(int, input().split())))
	wSum += a[-1][0]
(h1, h2) = sorted(map(lambda x: x[1], a), reverse=True)[:2]
for (w, h) in a:
	print((wSum - w) * (h2 if h == h1 else h1), end=' ')


n = int(input())
wsum = 0
hli = []
li = []
mx = 0
mxc = 1
smx = 0
k = 0
for i in range(n):
	(w, h) = map(int, input().split())
	li.append([w, h])
	wsum += w
	if h > mx:
		smx = mx
		mx = h
	elif h == mx:
		mxc += 1
	if h > smx and h != mx:
		smx = h
	hli.append(h)
for i in range(n):
	w = li[i][0]
	h = li[i][1]
	tmp = wsum - w
	if mxc == 1 or mxc == 0:
		if h == mx:
			print(tmp * smx, end=' ')
		else:
			print(tmp * mx, end=' ')
	elif mxc > 1:
		print(tmp * mx, end=' ')


import os.path
from math import gcd, floor, ceil
from collections import *
from bisect import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = inp()
	(x, y) = ([], [])
	s = 0
	for i in range(n):
		(a, b) = mp()
		x.append(a)
		y.append(b)
		s += a
	prefix = [0]
	suffix = [0]
	for i in range(n):
		prefix.append(max(prefix[-1], y[i]))
		suffix.append(max(suffix[-1], y[n - i - 1]))
	suffix = suffix[::-1]
	ans = []
	for i in range(n):
		ans.append((s - x[i]) * max(prefix[i], suffix[i + 1]))
	print(*ans)
for _ in range(1):
	solve()


n = int(input())
(w, h, a) = ([], [], [])
for i in range(n):
	(x, y) = list(map(int, input().split()))
	w += [x]
	h += [y]
s = sum(w)
h1 = h.copy()
h1.sort()
for i in range(n):
	W = s - w[i]
	if h[i] == h1[n - 1]:
		H = h1[n - 2]
	else:
		H = h1[n - 1]
	a += [W * H]
for i in a:
	print(i, end=' ')


n = int(input())
a = []
he = []
h = []
sum = 0
for i in range(n):
	(p, q) = [int(x) for x in input().split()]
	a.append(p)
	he.append(q)
	sum = sum + p
	h.append(q)
h.sort()
i = 0
for i in range(n):
	if he[i] == h[n - 1]:
		print(h[n - 2] * (sum - a[i]))
	else:
		print(h[n - 1] * (sum - a[i]))


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=' ')


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		n = inp()
		w = 0
		h = []
		f = []
		for i in range(n):
			(x, y) = invr()
			f.append((x, y))
			w += x
			h.append(y)
		h.sort(reverse=True)
		ans = []
		for i in range(n):
			wi = w - f[i][0]
			if h[0] == f[i][1]:
				he = h[1]
			else:
				he = h[0]
			ans.append(wi * he)
		print(*ans, sep=' ')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
smW = 0
mxH1 = 0
mxH2 = 0
widths = []
heights = []
for i in range(n):
	(w, h) = map(int, input().split(' '))
	widths.append(w)
	heights.append(h)
	smW += w
	if h > mxH2 and h < mxH1:
		mxH2 = h
	elif h >= mxH1:
		mxH2 = mxH1
		mxH1 = h
for i in range(n):
	if heights[i] == mxH1:
		print((smW - widths[i]) * mxH2, end=' ')
	else:
		print((smW - widths[i]) * mxH1, end=' ')
print()


n = int(input())
a = []
b = []
ans = 0
h1 = 0
h2 = 0
for i in range(n):
	(x, y) = map(int, input().split())
	a += [x]
	b += [y]
	ans += x
	if y > h2:
		h2 = min(h1, y)
		h1 = max(h1, y)
for i in range(n):
	if b[i] == h1:
		print((ans - a[i]) * h2, end=' ')
	else:
		print((ans - a[i]) * h1, end=' ')


def main():
	from sys import stdin, stdout
	w = []
	h = []
	width_sum = 0
	maxim = -100
	for _ in range(int(stdin.readline())):
		(x, y) = map(int, stdin.readline().split())
		w.append(x)
		h.append(y)
		width_sum += x
		if y > maxim:
			maxim = y
			maxindex = _
	maxim1 = maxim
	maxim2 = max(h[:maxindex] + h[maxindex + 1:])
	for i in range(len(w)):
		if i == maxindex:
			stdout.write(str((width_sum - w[i]) * maxim2) + ' ')
		else:
			stdout.write(str((width_sum - w[i]) * maxim1) + ' ')
main()


n = int(input())
w = [0 for i in range(n)]
h = [0 for i in range(n)]
for i in range(n):
	(wi, hi) = map(int, input().split())
	w[i] = wi
	h[i] = hi
ws = sum(w)
h1 = sorted(h)
sh = h1[-1]
mh = h1[-2]
ans = []
for i in range(n):
	a = sh
	if h[i] == sh:
		a = mh
	ans.append((ws - w[i]) * a)
print(*ans)


import sys

def main():
	reader = (tuple(map(int, line.split())) for line in sys.stdin)
	next(reader)
	friends = []
	all_width = 0
	tallest1_high = 0
	tallest1_index = None
	tallest2_high = 0
	for (index, line) in enumerate(reader):
		(width, high) = line
		friends.append((width, high))
		all_width += width
		if high > tallest2_high:
			tallest2_high = high
		if tallest2_high > tallest1_high:
			help = tallest1_high
			tallest1_high = tallest2_high
			tallest2_high = help
			tallest1_index = index
	for (index, friend) in enumerate(friends):
		(width, high) = friend
		picture_width = all_width - width
		if index == tallest1_index:
			picture_high = tallest2_high
		else:
			picture_high = tallest1_high
		print(picture_width * picture_high, end=' ')
main()


(L, M) = ([], [])
(hm, hm1, s) = (0, 0, 0)
for i in range(int(input())):
	(w, h) = [int(x) for x in input().split()]
	s += w
	L.append([w, h])
	if h > hm:
		hm1 = hm
		hm = h
	elif h > hm1:
		hm1 = h
for i in L:
	if i[1] == hm:
		print(hm1 * (s - i[0]))
	else:
		print(hm * (s - i[0]))


n = int(input())
friends = []
for m in range(n):
	friends.append(list(map(int, input().split())))
photos = []
w = 0
h = []
for k in range(n):
	w += friends[k][0]
	h.append(friends[k][1])
h.sort()
for i in range(n):
	if friends[i][1] == h[len(h) - 1]:
		photos.append((w - friends[i][0]) * h[n - 2])
	else:
		photos.append((w - friends[i][0]) * h[n - 1])
print(*photos)


t = int(input())
width = list()
hieght = list()
width_sum = 0
second_max = 0
ans = list()
for i in range(t):
	(w, h) = map(int, input().split())
	width.append(w)
	hieght.append(h)
	width_sum += w
hieght_max = max(hieght)
for i in range(t):
	if hieght[i] > second_max and hieght[i] != hieght_max:
		second_max = hieght[i]
if hieght.count(hieght_max) > 1:
	for i in range(t):
		ans.append((width_sum - width[i]) * hieght_max)
else:
	for i in range(t):
		if hieght[i] == hieght_max:
			ans.append((width_sum - width[i]) * second_max)
		else:
			ans.append((width_sum - width[i]) * hieght_max)
print(*ans)


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()


n = int(input())
a = []
su = 0
(max1, max2) = [None, None]
for i in range(n):
	(x, y) = [int(t) for t in input().split()]
	a.append([x, y])
	su += x
	if max1 == None or y > a[max1][1]:
		(max1, max2) = [i, max1]
	elif max2 == None or y > a[max2][1]:
		max2 = i
print(' '.join([str((su - a[i][0]) * a[max2 if i == max1 else max1][1]) for i in range(n)]))


n = int(input())
sw = 0
ws = []
(m1, m1i) = (-1, -1)
(m2, m2i) = (-1, -1)
for i in range(n):
	(w, h) = map(int, input().split())
	ws.append(w)
	sw += w
	if h >= m1:
		(m2, m2i) = (m1, m1i)
		(m1, m1i) = (h, i)
	elif h >= m2:
		(m2, m2i) = (h, i)
for i in range(n):
	w = sw - ws[i]
	print((m2 if i == m1i else m1) * w, end=' ')


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=' ')


n = int(input())
ppl = []
w = []
h = []
for i in range(n):
	(wi, hi) = map(int, input().split(' '))
	ppl.append([wi, hi])
	w.append(wi)
	h.append(hi)
su = sum(w)
m1 = sorted(h)
for i in range(n):
	if h[i] == m1[-1]:
		hh = m1[-2]
	else:
		hh = m1[-1]
	ans = (su - w[i]) * hh
	print(ans, end=' ')


friends_w = []
friends_h = []
max_h = 0
max_h_2 = 0
total_w = 0
amount = int(input())
for i in range(amount):
	(w, h) = map(int, input().split())
	friends_w.append(w)
	friends_h.append(h)
	if max_h_2 < h:
		if max_h < h:
			max_h_2 = max_h
			max_h = h
		else:
			max_h_2 = h
	total_w += w
for i in range(amount):
	if friends_h[i] == max_h:
		print(max_h_2 * (total_w - friends_w[i]))
	else:
		print(max_h * (total_w - friends_w[i]))


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=' ')


width = []
height = []
s = 0
n = int(input())
for _ in range(n):
	(w, h) = map(int, input().split())
	width.append(w)
	s = s + w
	height.append(h)
req1 = []
req2 = []
a = s
k = sorted(height)
k.sort(reverse=True)
for i in width:
	a = a - i
	req1.append(a)
	a = s
for i in range(n):
	if height[i] != k[0]:
		req1[i] *= k[0]
	else:
		req1[i] *= k[1]
for i in range(n):
	print(req1[i], 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)))
main()


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])


n = int(input())
w = [0] * n
h = [0] * n
c = [x for x in range(n)]
ss = 0
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
	ss += w[i]
s = sorted(zip(h, c))
a = s[n - 1][1]
b = s[n - 2][1]
for i in range(n):
	vv = ss - w[i]
	if i == a:
		cc = h[b]
	else:
		cc = h[a]
	print(cc * vv, end=' ')


s = []
hh = []
sum_of_W = 0
h1 = -100
h2 = -100
n = int(input())
for _ in range(n):
	(w, h) = map(int, input().split())
	hh.append(h)
	h2 = max(h2, h)
	(h1, h2) = (max(h2, h1), min(h2, h1))
	sum_of_W += w
	s.append(w)
ans = []
for i in range(n):
	W = sum_of_W - s[i]
	if hh[i] == h1:
		ans.append(W * h2)
	else:
		ans.append(W * h1)
print(' '.join(map(str, ans)))


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def msi():
	return map(str, input().split())

def li():
	return list(mi())
n = ii()
(w, h) = ([], [])
for _ in range(n):
	(wi, hi) = mi()
	w.append(wi)
	h.append(hi)
summ = sum(w)
dp = [0] * n
rdp = [0] * n
curr_max = 0
for i in range(n):
	dp[i] = curr_max
	if h[i] > curr_max:
		curr_max = h[i]
curr_max = 0
for i in range(n - 1, -1, -1):
	rdp[i] = curr_max
	if h[i] > curr_max:
		curr_max = h[i]
res = []
for i in range(n):
	res.append((summ - w[i]) * max(dp[i], rdp[i]))
print(*res)


arr_w = []
N = int(input())
(max_h, i1) = (0, None)
(max2_h, i2) = (0, None)
for i in range(N):
	(w_i, h_i) = map(int, input().strip().split())
	arr_w.append(w_i)
	if h_i > max_h:
		(max2_h, i2) = (max_h, i1)
		(max_h, i1) = (h_i, i)
	elif h_i > max2_h:
		(max2_h, i2) = (h_i, i)
W = sum(arr_w)
res = []
for i in range(N):
	h = max_h if i != i1 else max2_h
	res.append(str((W - arr_w[i]) * h))
print(' '.join(res))


n = int(input())
arw = []
arh = []
for i in range(n):
	(w, h) = [int(j) for j in input().split()]
	arw.append(w)
	arh.append(h)
summ = 0
for i in range(n):
	summ += arw[i]
h_m = max(arh)
cnt = arh.count(h_m)
for i in range(n):
	w = summ - arw[i]
	if arh[i] == h_m and cnt == 1:
		b = []
		for j in range(n):
			b.append(arh[j])
		b.pop(i)
		h = max(b)
	else:
		h = h_m
	print(h * w)


R = lambda : map(int, input().split())
n = int(input())
arr = [list(R()) for i in range(n)]
top2 = sorted((x[1] for x in arr), reverse=True)[:2]
sw = sum((x[0] for x in arr))
for x in arr:
	h = top2[0] if top2[0] != x[1] else top2[1]
	print(h * (sw - x[0]), end=' ')


n = int(input())
(max1, max2) = (None, None)
people = []
sum_width = 0
for i in range(n):
	(w, h) = (int(x) for x in input().split())
	if max1 is None:
		max1 = i
	elif h > people[max1][1]:
		(max1, max2) = (i, max1)
	elif max2 is None or h > people[max2][1]:
		max2 = i
	people.append((w, h))
	sum_width += w
print(' '.join((str((sum_width - people[i][0]) * people[max2 if i == max1 else max1][1]) for i in range(n))))


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
w = 0
arr = []
ww = []
h = []
for _ in range(n):
	(a, b) = map(int, input().split())
	ww.append(a)
	w += a
	h.append(b)
	arr.append(b)
h.sort(reverse=True)
for i in range(n):
	if arr[i] == h[0]:
		print((w - ww[i]) * h[1], end=' ')
	else:
		print((w - ww[i]) * h[0], end=' ')


w = []
h = []
n = int(input())
for i in range(n):
	(h_, w_) = (int(i) for i in input().split(' '))
	w.append(w_)
	h.append(h_)
w_max = max(w)
w2 = w.copy()
w2.sort()
w_secmax = w2[-2]
h_sum = sum(h)
for i in range(n):
	if w[i] == w_max:
		print((h_sum - h[i]) * w_secmax, end=' ')
	else:
		print((h_sum - h[i]) * w_max, end=' ')


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
a = []
b = []
p = []
for _ in range(ii()):
	(x, y) = mi()
	a.append(x)
	b.append(y)
s = sum(a)
x = max(b)
y = b.index(x)
z = 0
if y:
	z = max(b[:y])
if y < len(b) - 1:
	z = max(z, max(b[y + 1:]))
for i in range(len(a)):
	if b[i] == x:
		p.append((s - a[i]) * z)
	else:
		p.append((s - a[i]) * x)
print(*p)


n = int(input())
total = 0
L = []
H = []
for i in range(n):
	(w, h) = [int(x) for x in input().split()]
	L.append((w, h))
	total += w
	H.append(h)
H.sort()
H = H[::-1]
for i in L:
	if i[1] == H[0]:
		print(H[1] * (total - i[0]))
	else:
		print(H[0] * (total - i[0]))


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=' ')


n = int(input())
w = [0] * n
h = [0] * n
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
sum_w = sum(w)
max_h = max(h[0], h[1])
max_h_2 = min(h[0], h[1])
for i in range(2, n):
	if h[i] >= max_h:
		max_h_2 = max_h
		max_h = h[i]
	elif h[i] >= max_h_2:
		max_h_2 = h[i]
for i in range(n):
	wi = sum_w - w[i]
	hi = max_h if h[i] != max_h else max_h_2
	print(wi * hi, end=' ')


n = int(input())
max = 0
max2 = 0
ww = []
wsum = 0
for i in range(n):
	(w, h) = map(int, input().split(' '))
	ww.append((w, h))
	wsum += w
	if h > max:
		max2 = max
		max = h
	elif h > max2:
		max2 = h
for i in range(n):
	w1 = wsum - ww[i][0]
	h1 = max if ww[i][1] != max else max2
	print(w1 * h1, end=' ')


n = int(input())
w = []
h = []
h1 = []
res = 0
for i in range(n):
	(x, y) = map(int, input().split())
	res += x
	h.append(y)
	h1.append(y)
	w.append(x)
h.sort()
for i in range(n):
	a = res - w[i]
	b = h[n - 1]
	if h[n - 1] == h1[i]:
		b = h[n - 2]
	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())
(w, h) = ([], [])
(h1, h2, s) = (0, 0, 0)
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	w.append(a)
	h.append(b)
	s += a
	if b > h1:
		h2 = h1
		h1 = b
	elif b > h2:
		h2 = b
for i in range(n):
	if h[i] != h1:
		print((s - w[i]) * h1, end=' ')
	else:
		print((s - w[i]) * h2, end=' ')


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
W = 0
d = defaultdict(int)
fmax = 0
smax = 0
H = []
l = []
for i in range(n):
	(a, b) = M()
	l.append([a, b])
	W += a
	if b >= fmax:
		smax = max(smax, fmax)
		fmax = b
	elif b > smax:
		smax = b
for i in range(n):
	if l[i][1] == fmax:
		p = smax
	else:
		p = fmax
	print((W - l[i][0]) * p, end=' ')


n = int(input())

def solve(n):
	w = []
	h = []
	for i in range(n):
		inp = input().split()
		w.append(int(inp[0]))
		h.append(int(inp[-1]))
	res = []
	sm = sum(w)
	h_mx = sorted(enumerate(h), reverse=True, key=lambda x: x[-1])
	for i in range(n):
		w_ = sm - w[i]
		if i == h_mx[0][0]:
			h_ = h_mx[1][1]
		else:
			h_ = h_mx[0][1]
		res.append(str(w_ * h_))
	return ' '.join(res)
print(solve(n))


s = 0
l = []
l1 = []
l2 = []
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	s += a
	l1.append(b)
	l2.append([a, b])
l1.sort()
ma1 = l1[-1]
ma2 = l1[-2]
ans = []
for i in range(n):
	w = s - l[i]
	if l2[i][1] == ma1:
		h = ma2
	else:
		h = ma1
	ans.append(w * h)
print(*ans)


n = int(input())
w = [0] * n
h = [0] * n
for i in range(n):
	(w[i], h[i]) = map(int, input().split())
sum_w = sum(w)
max_h = max(h)
max_count = sum(map(lambda o: int(o == max_h), h))
if max_count > 1:
	ans = map(lambda o: (sum_w - w[o]) * max_h, range(n))
else:
	max_h2 = max(filter(lambda o: o != max_h, h))
	ans = map(lambda o: (sum_w - w[o]) * (max_h2 if h[o] == max_h else max_h), range(n))
print(' '.join(map(str, ans)))


n = int(input())
W = []
H = []
for _ in range(0, n):
	(w, h) = input().split()
	w = int(w)
	h = int(h)
	W.append(w)
	H.append(h)
t = sum(W)
H1 = sorted(H)
for i in range(n):
	if H[i] == H1[n - 1]:
		print((t - W[i]) * H1[n - 2], end=' ')
	else:
		print((t - W[i]) * H1[n - 1], end=' ')


n = int(input())
W = 0
h1 = [0] * (n + 2)
h = [0] * (n + 2)
w = [0] * (n + 2)
for i in range(1, n + 1):
	(w[i], h[i]) = map(int, input().split())
	W += w[i]
	h1[i] = max(h[i], h1[i - 1])
h2 = [0] * (n + 2)
for i in range(n, 0, -1):
	h2[i] = max(h[i], h2[i + 1])
print(' '.join([str((W - w[i]) * max(h1[i - 1], h2[i + 1])) for i in range(1, n + 1)]))


w = []
h = []
W = 0
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	w.append(a)
	h.append(b)
	W += a
H1 = max(h)
I = h.index(H1)
H2 = max(h[:I] + h[I + 1:])
for i in range(n):
	H = H1 if i != I else H2
	print((W - w[i]) * H, end=' ')


n = int(input())
pp = [list(map(int, input().split())) + [i] for i in range(n)]
tw = sum([p[0] for p in pp])
pp = sorted(pp, key=lambda p: p[1])
for i in range(n - 1):
	pp[i].append((tw - pp[i][0]) * pp[-1][1])
pp[-1].append((tw - pp[-1][0]) * pp[-2][1])
pp = sorted(pp, key=lambda p: p[2])
print(*[p[3] for p in pp])


n = int(input())
(m1, m2, s) = (0, 0, 0)
(w, h) = ([], [])
for i in range(n):
	(a, b) = map(int, input().split())
	w.append(a)
	h.append(b)
	if b > m1:
		(m1, m2) = (b, m1)
	elif b > m2:
		m2 = b
	s += a
ans = []
for i in range(n):
	if h[i] == m1:
		ans.append((s - w[i]) * m2)
	else:
		ans.append((s - w[i]) * m1)
print(*ans)


n = int(input())
(w, h, h1, h2) = ([], [], 0, 0)
for i in range(n):
	(x, y) = map(int, input().split())
	w.append(x)
	h.append(y)
	if y > h1:
		h2 = h1
		h1 = y
	elif y > h2:
		h2 = y
ans = sum(w)
for i in range(n):
	if h[i] == h1:
		print((ans - w[i]) * h2, end=' ')
	else:
		print((ans - w[i]) * h1, end=' ')


n = int(input())
a = []
W = 0
h1 = h2 = 0
flag = 0
for i in range(n):
	inp = input().split()
	(wi, hi) = (int(inp[0]), int(inp[1]))
	a.append([wi, hi])
	W += wi
	if hi >= h1:
		h2 = h1
		h1 = hi
	elif hi > h2:
		h2 = hi
for i in a:
	if i[1] == h1:
		print((W - i[0]) * h2, end=' ')
	else:
		print((W - i[0]) * h1, end=' ')


import heapq

def main():
	n = int(input())
	wi = [0] * n
	hi = [0] * n
	for i in range(n):
		(w, h) = map(int, input().split())
		wi[i] = w
		hi[i] = h
	(m1, m2) = heapq.nlargest(2, hi)
	answ = [sum(wi)] * n
	ansh = [0] * n
	for i in range(n):
		answ[i] -= wi[i]
		if hi[i] != m1:
			ansh[i] = m1
		else:
			ansh[i] = m2
	ans = [0] * n
	for i in range(n):
		ans[i] = answ[i] * ansh[i]
	print(*ans)
main()


import sys
import math
import collections
from pprint import pprint as pp
mod = 1000000007

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat
n = int(input())
a = matrix(n, 2)
for i in range(n):
	(a[i][0], a[i][1]) = map(int, input().split())
w = 0
h1 = 0
h2 = 0
for i in a:
	w += i[0]
	if i[1] >= h1:
		h2 = h1
		h1 = i[1]
	else:
		h2 = max(h2, i[1])
for x in a:
	w0 = w - x[0]
	if x[1] == h1:
		h0 = h2
	else:
		h0 = h1
	print(w0 * h0, end=' ')


w = []
W = 0
F = 0
f = []
y = []
n = int(input())
for k in range(n):
	(a, b) = map(int, input().split())
	w.append(a)
	f.append(b)
	W += a
	F += b
h = 0
u = {}
for j in range(n):
	m = f[j]
	f[j] = -1
	if m in u:
		h = u[m]
	else:
		u[m] = max(f)
		h = u[m]
	y.append((W - w[j]) * h)
	f[j] = m
print(*y)