#!/usr/bin/env python # -*- coding: utf-8 -*- import sys n = int(sys.stdin.readline().split(' ')[0]) f = [] for i in range(n-1): l = sys.stdin.readline().split(' ') f.append(int(l[0])) on = [] off = [] for i in range(n-1): l = sys.stdin.readline().split(' ') off.append(int(l[0])) on.append(int(l[1])) ans = 0 passgr = 0 for i in range(n-1): passgr += on[i] - off[i] ans += f[i] * passgr print(ans)