import java.util.Scanner;
import java.math.*;
import java.util.*;
import java.io.*;
class Tree1
{
public static BigInteger fact(BigInteger x)
{
BigInteger ans = BigInteger.valueOf(1);
for (int i = 1; i <= x.intValue(); i++)
{
ans = ans.multiply(BigInteger.valueOf(i));
}
return ans;
}
public static BigInteger factorial(BigInteger a, BigInteger b)
{
return fact(a.add(b)).divide((fact(a).multiply(fact(b))));
}
public static BigInteger Permute(ArrayList v)
{
if(v.size() <= 1)
{
return BigInteger.valueOf(1);
}
ArrayList left = new ArrayList();
ArrayList right = new ArrayList();
Iterator itr = v.iterator();
for(int i = 1; i < v.size(); ++i)
{
if((((BigInteger)v.get(i)).compareTo((BigInteger)v.get(0)) == -1))
{
left.add(itr.next());
}
else
{
right.add(itr.next());
}
}
return Permute(left).multiply(Permute(right).multiply(factorial(BigInteger.valueOf(left.size()),BigInteger.valueOf(right.size()))));
}
public static void main(String args[]) throws IOException
{
Scanner scan = new Scanner(System.in);
int t;
t = scan.nextInt();
while(t-- > 0)
{
int n;
n = scan.nextInt();
ArrayList arr = new ArrayList();
for(int i = 0; i < n; ++i)
{
BigInteger x = scan.nextBigInteger();
arr.add(x);
}
BigInteger ans = Permute(arr);
System.out.println(ans);
}
}
}
This is my code for the problem. Can anybody figure out what is the mistake?