print((sum([i for i in range(1,int(eval(input()))+1) if not ((i%3==0 and i%5==0) or i%3==0 or i%5==0)])))
print((sum([i for i in range(1,int(eval(input()))+1) if i%15 and i%5 and i%3])))
print(
    (
        sum(
            [
                i
                for i in range(1, int(eval(input())) + 1)
                if not ((i % 3 == 0 and i % 5 == 0) or i % 3 == 0 or i % 5 == 0)
            ]
        )
    )
)

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

-    ( -        sum( -            [ -                i -                for i in range(1, int(eval(input())) + 1) -                if not ((i % 3 == 0 and i % 5 == 0) or i % 3 == 0 or i % 5 == 0) -            ] -        ) -    ) +    (sum([i for i in range(1, int(eval(input())) + 1) if i % 15 and i % 5 and i % 3]))