#C10496. Quadruplets Sum Finder

    ID: 39707 Type: Default 1000ms 256MiB

Quadruplets Sum Finder

Quadruplets Sum Finder

Given an array of integers and a target sum \(T\), your task is to find all unique quadruplets \(a, b, c, d\) in the array such that \(a+b+c+d=T\). Each quadruplet must be printed in ascending lexicographical order (i.e. sorted by their elements).

Note that the array can contain duplicate numbers, but each quadruplet in the output must be unique. It is required that you implement an efficient algorithm utilizing sorting and the two-pointer technique.

inputFormat

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

  1. The first line contains an integer \(n\), the number of integers in the array.
  2. The second line contains \(n\) space-separated integers.
  3. The third line contains the target sum \(T\).

outputFormat

Output to standard output (stdout) the list of quadruplets. Each quadruplet should be printed on a new line with the four integers separated by a single space. 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>