Tutorial is loading...
Code (C++ version)
Tutorial is loading...
Code (C++ version)
Code (Python version)
Tutorial is loading...
Code (C++ version)
Code (Python version)
Tutorial is loading...
Code (C++ version)
Tutorial is loading...
Code (C++ version)
Tutorial is loading...
Code (My stupid solution: C++ version)
Code (demon1999's fast solution: C++11 version)
UPD1: Note that the editorial of problem E is modified with some correction. Sorry for that inconvenience.
UPD2: The editorial is complete now. Hope you find it useful. :P