Why i am getting wrong answer for this question(mentioned below)?

I am getting wrong answer for Suhana and Matrix world(problem code:-TRAVERSE)
even though my output match with that one given in problem
my code is:-
/* package codechef; // don’t place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;


class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int t;
		Scanner s=new Scanner(System.in);
		t=s.nextInt();
		int x=0,y=0,n=1;
		for(int i=1;i<t;i++)
		{   
		    int p;
		   
		    p=s.nextInt();
		    if(p==0)
		    {
		        System.out.print(x);
		        System.out.print(" ");
		        System.out.print(y);
		        System.out.println("");
		    }
		    if(i==n)
		    {
		        x=x+1;
		        n=n+3;
		    }
		    else{
		        y=y+1;
		    }
		    
		        System.out.print(x);
		        System.out.print(" ");
		        System.out.print(y);
		        System.out.println("");
		    
		    
		}
	}
}
Thanks in advance

This problem is from an ongoing contest on Codechef. You should wait till its over.

Bro never post your code!

//