import bisect import sys input = sys.stdin.readline class BIT: def __init__(self, n, func=int.__add__, one=0): self.n = n self.func = func self.one = one self.a = [0] * (self.n + 1) self.all_sum = 0 def update(self, i, x): i += 1 while i <= self.n: self.a[i] = self.func(self.a[i], x) i += i & (-i) self.all_sum += x def get(self, i): s = self.one while i != 0: s = self.func(s, self.a[i]) i -= i & (-i) return s def out_get(self, i): return self.all_sum - self.get(i) n = int(input()) y_list = list() point = list() for _ in range(n): x, y = map(int, input().split()) y_list.append(y) point.append((x, y)) y_list.sort() point.sort() def compress_index(y): idx = bisect.bisect_left(y_list, y) return idx mod = 998244353 one_bit = BIT(n) x_plus_y_bit = BIT(n) x_plus_y2_bit = BIT(n) x_minus_y_bit = BIT(n) x_minus_y2_bit = BIT(n) ans = 0 for x, y in point: y_idx = compress_index(y) one = one_bit.get(y_idx) x_plus_y = x_plus_y_bit.get(y_idx) x_plus_y2 = x_plus_y2_bit.get(y_idx) ans += (x + y) ** 2 * one - 2 * (x + y) * x_plus_y + x_plus_y2 ans %= mod one = one_bit.out_get(y_idx) x_minus_y = x_minus_y_bit.out_get(y_idx) x_minus_y2 = x_minus_y2_bit.out_get(y_idx) ans += (x - y) ** 2 * one - 2 * (x - y) * x_minus_y + x_minus_y2 ans %= mod one_bit.update(y_idx, 1) x_plus_y_bit.update(y_idx, (x + y) % mod) x_plus_y2_bit.update(y_idx, (x + y) ** 2 % mod) x_minus_y_bit.update(y_idx, (x - y) % mod) x_minus_y2_bit.update(y_idx, (x - y) ** 2 % mod) print(ans % mod)