print((sum(i for i in range(int(eval(input()))+1) if i%3!=0 and i%5!=0)))
print((sum(i for i in range(int(eval(input()))+1) if i%3 and i%5)))
print((sum(i for i in range(int(eval(input())) + 1) if i % 3 != 0 and i % 5 != 0)))

print((sum(i for i in range(int(eval(input())) + 1) if i % 3 and i % 5)))

-print((sum(i for i in range(int(eval(input())) + 1) if i % 3 != 0 and i % 5 != 0))) +print((sum(i for i in range(int(eval(input())) + 1) if i % 3 and i % 5)))