Works fine in ide but not work in codechef

My code works fine in ide but not work in codechef . Here is the link

It gives the wrong answer for the sample testcase:

[simon@simon-laptop][10:39:57]
[~/devel/hackerrank/otherpeoples]>echo "3
1 1
1 1
2 2
1 50
2 100
3 2
1 51
3 100
2 50"  | ./chnihar-IMDB.py
1
100
100