#C9610. Four Sum: Find Unique Quadruplets

    ID: 53723 Type: Default 1000ms 256MiB

Four Sum: Find Unique Quadruplets

Four Sum: Find Unique Quadruplets

You are given an array of integers \(nums\) and an integer \(target\). Your task is to find all unique quadruplets [a, b, c, d] such that:

\(a+b+c+d=target\)

Each quadruplet should be sorted in non-decreasing order and the overall list of quadruplets should not contain duplicates. If no such quadruplet exists, output nothing.

Note: Two quadruplets are considered unique if one quadruplet cannot be obtained from the other by rearranging the elements.

inputFormat

The input is given from stdin and consists of three lines:

  1. An integer \(n\) representing the number of elements in the array.
  2. \(n\) space-separated integers representing the array \(nums\).
  3. An integer \(target\) representing the target sum.

outputFormat

Print each found quadruplet on a separate line, with the four numbers separated by a single space. The quadruplets must be printed in lexicographical order (sorted order). If no quadruplet exists, output nothing.

## sample
6
1 0 -1 0 -2 2
0
-2 -1 1 2

-2 0 0 2 -1 0 0 1

</p>