Wrong answer for The Lead Game in Beginners section!

I’ve tried the same algorithm in different languages, but aren’t able to submit it! It compiles for as many cases as I can think but gives the wrong answer error!! Why?

import java.util.Scanner;
import java.lang.Math;

class TLG
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int n = 0;
		if(in.hasNextInt())
		    n = in.nextInt();
		int Si = 0, Ti = 0, win = 0, diff = 0, max = 0;
		while (n-- > 0) {
		    if(in.hasNextInt()) {
			    Si = in.nextInt(); Ti = in.nextInt();
		    }
			diff = Si - Ti;
			if (max < Math.abs(diff)) {
				win = (diff > 0) ? 1 : 2;
				max = Math.abs(diff);
			}
		}
		System.out.println(win + " " + max);
	}
}