N = int(eval(input()))

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

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

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