I can't understand what is happening here or even find a bug in my code. I found a similar issue with someone else here in codeforces.
What can really cause such a runtime error with this version of the GNU C++ compiler? The only thing I thought about was a bug in this version, which was fixed later in GNU C++17.
My accepted submission with GNU C++17: https://codeforces.me/contest/1696/submission/169228991 The submission with the same code but with GNU C++14: https://codeforces.me/contest/1696/submission/169229016