Template
Code 1 : https://mirror.codeforces.com/contest/600/submission/68729075
Code 2 : https://mirror.codeforces.com/contest/570/submission/86307066
Code 3 : https://mirror.codeforces.com/contest/246/submission/86380797
Code 4 : https://mirror.codeforces.com/contest/208/submission/87172029
Code 5 : https://mirror.codeforces.com/contest/375/submission/86462196