Моклев Вячеслав, 2539

I don't know how much tests are needed, I made ~10 by myself with different bas cases and 1 I generate automatically (with a lot of operations, about 2^11 numbers).