solving 0000-festival in C++