#K5126. Four Sum Problem

    ID: 29048 Type: Default 1000ms 256MiB

Four Sum Problem

Four Sum Problem

Given an array of integers and a target value \( T \), your task is to find all unique quadruplets \( (a, b, c, d) \) such that \( a + b + c + d = T \). The quadruplets must have their elements in non-decreasing order and the overall list of quadruplets should not contain duplicates. The input array is provided in unsorted order; your solution should handle sorting.

inputFormat

The input is read from stdin and consists of two lines.

The first line contains two integers: \( n \) (the number of elements) and \( T \) (the target sum), separated by a space.

The second line contains \( n \) space-separated integers representing the array.

outputFormat

Output a single line to stdout representing the list of unique quadruplets in Python list format. Each quadruplet must be a list of four integers. If no quadruplets exist, output an empty list [].

## sample
6 0
1 0 -1 0 -2 2
[[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]