#K35177. Four Sum Problem

    ID: 25474 Type: Default 1000ms 256MiB

Four Sum Problem

Four Sum Problem

Given an array of integers and a target value \(T\), find all unique quadruplets \( [a, b, c, d] \) in the array such that:

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

The quadruplets must be unique (the solution set must not contain duplicate quadruplets), and each quadruplet should be printed in non-decreasing order.

Example:

Input: [1, 0, -1, 0, -2, 2], T = 0
Output:
-2 -1 1 2
-2 0 0 2
-1 0 0 1

If no quadruplet exists, output [].

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains space-separated integers representing the array.
  2. The second line contains a single integer, the target value \(T\).

outputFormat

Output all unique quadruplets that sum to \(T\) to standard output (stdout). Each quadruplet should be printed on a separate line with its numbers separated by a single space. If no quadruplet is found, output a single line containing [].

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

-2 0 0 2 -1 0 0 1

</p>