Problem with UVa Online Judge
I tried to solve 195 problem. Here it is.

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=3&problem=131&mosmsg=Submission+received+with+ID+9118309

Here is my solution.

http://pastebin.com/xt9AhiTL

I tries examples from the site and the result was the same. But I've got 'Wrong Answer'.
Please, help to find mistakes and give some ideas how to fix them.
PS: I know that my algorith is awful, but it works :)
Problem with UVa Online Judge
===

I tried to solve 195 problem. Here it is.

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=3&problem=131&mosmsg=Submission+received+with+ID+9118309

Here is my solution.

http://pastebin.com/xt9AhiTL

I tries examples from the site and the result was the same. But I've got 'Wrong Answer'.
Please, help to find mistakes and give some ideas how to fix them.
PS: I know that my algorith is awful, but it works :)