solution for PSI 2012