JOSWAP - Just One Swap

You are given an array of size N. How many distinct arrays can you generate by swapping two numbers for exactly once? The two selected numbers can be equal but their positions in the array must be different.

Input

The first line of the input contains a single integer T, denoting the number of test cases. Every test case starts with an integer N. The next line contains N integers, the numbers of the array.

Output

For each test case output the answer in a single line.

Constraints

1 <= T <= 5

1 <= Value of a number in the array <= 100000

2 <= N <= 100000

Example

Input:
1
5
2 3 2 3 3

Output:
7

You can generate the following arrays:

  • 2 3 2 3 3
  • 2 2 3 3 3
  • 2 3 3 2 3
  • 2 3 3 3 2
  • 3 2 2 3 3
  • 3 3 2 2 3
  • 3 3 2 3 2

Added by:Bertho Coder
Date:2017-04-07
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:National High School Programming Contest 2017

hide comments
2021-10-05 10:25:29 Waseem Ahmed
Nice problem. Had to read through the comments carefully to understand the problem. Thanks @invincible and @candide!!
2021-02-28 05:40:43 Rafail Loizou
What do you mean swapping 2 numbers for exactly once dude? If that means one time then for the test case:
1
2
1 2
then the answer should be 2. Because you have the initial array [1,2] and the array if you swap [2,1].

Oh I just realized he doesn't want you to count the initial array. Smh...

Last edit: 2021-02-28 05:44:09
2019-09-21 15:58:50
Easy question but words are important 'swapping two numbers for exactly once'. AC in 10th GO.
For array [1 2 ]
answer should be 1 as only [2 1] counted and not [1 2] if you go by the words.
2019-07-16 00:01:25 :D
"... by swapping two numbers for exactly once?"
2017-07-30 19:55:02
For Case :
1
2
1 2
What is the expected answer,1 or 2?
Mine with answer 1 getting accepted..
2017-04-30 17:46:56 shahzada
what should be the answer for -
1
4
1 2 3 4
2017-04-26 05:00:53
Bertho Coder can u check my solution?
2017-04-24 22:10:38
simple combinations Ac in 1 go..
2017-04-09 12:26:51 candide
Basic combinatorial logic gives the answer. Use long long.
2017-04-07 16:22:00 Vipul Srivastava
Are the test cases surely correct?

Reply: Yes, tested by stress testing.

Last edit: 2017-04-07 18:01:49
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.