ref: https://www.cnblogs.com/PinkRabbit/p/10446473.htmlpro: https://codeforces.com/problemset/problem/487/E