#K4851. Square Formation

    ID: 28436 Type: Default 1000ms 256MiB

Square Formation

Square Formation

You are given several pieces of wood, each with a specified positive integer length. Your task is to determine whether it is possible to form a square by using all the given pieces exactly once, so that each side of the square has the same length.

Let \(S\) be the total length of all pieces, and let \(L = \frac{S}{4}\) be the length of each side. A square can only be formed if \(S\) is divisible by 4. In that case, the problem reduces to finding a partition of the pieces into four groups such that the sum of the pieces in each group equals \(L\).

If such a partition exists, print YES, otherwise print NO.

Input Format: The first line contains an integer \(T\), the number of datasets. Then for each dataset, the first line contains an integer \(n\) (the number of pieces), followed by a line of \(n\) space-separated integers representing the lengths of the wood pieces.

Output Format: For each dataset, output a line containing YES if it is possible to form a square, otherwise NO.

inputFormat

The first line of input contains a single integer \(T\), denoting the number of datasets. For each dataset:

  • An integer \(n\) representing the number of pieces of wood.
  • A line with \(n\) space-separated integers, each denoting the length of a wood piece.

Note: If \(n < 4\), it is automatically impossible to form a square.

outputFormat

For each dataset, print a single line with either YES if the pieces can form a square, or NO otherwise.

## sample
2
4
1 1 1 1
5
2 2 2 2 2
YES

NO

</p>