Click Here to go back to the homepage.

Shattered Cake Solution:


w = int(input())
blocks = int(input())
memo = {}
total = 0
for _ in range(blocks):
    line = input()
    if line in memo:
        total += memo[line]
    else:
        x, y = line.split()
        product = int(x)*int(y)
        memo[line] = product
        total += product
print(total//w)