n = int(input()) total = 0 for i in range(n): c, m = map(int, input().split()) if c <= 2: total += m elif c % 2 == 0: total += c % 2 * m else: total += c // 2 * 2 * m print(total)