B. Good Kid

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Slavic is preparing a present for a friend's birthday. He has an array a� of n� digits and the present will be the product of all these digits. Because Slavic is a good kid who wants to make the biggest product possible, he wants to add 11 to exactly one of his digits.

What is the maximum product Slavic can make?

Input

The first line contains a single integer t� (1≤t≤1041≤�≤104) — the number of test cases.

The first line of each test case contains a single integer n� (1≤n≤91≤�≤9) — the number of digits.

The second line of each test case contains n� space-separated integers ai�� (0≤ai≤90≤��≤9) — the digits in the array.

Output

For each test case, output a single integer — the maximum product Slavic can make, by adding 11 to exactly one of his digits.

Example

input

Copy

 
  

4

4

2 2 1 2

3

0 1 2

5

4 3 2 3 4

9

9 9 9 9 9 9 9 9 9

output

Copy

16
2
432
430467210

解题说明:此题是一道数学题,为了让乘积最大,很显然将数列中最小的数扩大更能让乘积变大,于是遍历找出最小的数然后求乘积即可。

#include
int main() 
{
	int t;
	scanf("%d", &t);
	while (t--) 
	{
		int n, i, min, j, p = 1;
		scanf("%d", &n);
		int a[10];
		for (i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
			if (i == 0 || a[i] < min)
			{
				min = a[i];
				j = i;
			}
		}
		a[j]++;
		for (i = 0; i < n; i++)
		{
			p *= a[i];
		}
		printf("%d\n", p);
	}
	return 0;
}

你可能感兴趣的:(AC路漫漫,算法)