tried to optimize, but kattis still fail