logind
memo : http://codeforces.com/contest/467/submission/7828195