Little Elephant and Music

i don’t know why i’m getting wrong this question is from april cook off can some one help me
package codechef;

public class LittleElephant {

/**
 * @param args
 */
public static void main(String[] args) {
	 int ans[],bands[],length[];
	java.util.Scanner r = new java.util.Scanner(System.in);
	int t=Integer.parseInt(r.next());
	ans=new int[t];
	int n=0;
	boolean reset=true,set=true;
	while(t>0)
	{
		n=Integer.parseInt(r.next());
		bands=new int[n]; 
		length=new int[n];
		
		for(int i=0;i<bands.length;i++)
		{
			bands[i]=Integer.parseInt(r.next());
			length[i]=Integer.parseInt(r.next());
		}
		int s1=bands[0];
		for(int i=1;i<bands.length;i++)
		{
			s1=s1+bands[i];
			if(bands[i-1]==bands[i])
			{
				
			}
			else
			 set=false;
		}
		int s2=length[0];
		for(int i=1;i<length.length;i++)
		{
			s2=s2+length[i];
			if(length[i-1]==length[i])
			{
				
			}
			else
			 reset=false;
		}
         if(set&&reset)
        	 ans[t-1]=n*(bands[0]*length[0]);
         else if(set)
        	 ans[t-1]=bands[0]*s2;
         else if(reset)
        	 ans[t-1]=length[0]*s1;
         else
         {
        	 java.util.Arrays.sort(length);
        	 java.util.Arrays.sort(bands);
        	 int temp=0;
        	 for(int i=0;i<length.length;i++)
        	 {
        		 temp+=bands[i]*length[i];
        	 }
        	 ans[t-1]=temp;
         }
         t--;
	}
	for(int i=ans.length-1;i>=0;i--)
		System.out.println(ans[i]);
}

}

//