#K3751. Three Sum Problem

    ID: 25992 Type: Default 1000ms 256MiB

Three Sum Problem

Three Sum Problem

You are given an array of n integers and a target sum \(X\). Your task is to determine whether there exist three distinct elements in the array that add up exactly to \(X\). If such a triplet exists, print True; otherwise, print False.

Input format:

  • The first line contains an integer \(n\) representing the number of elements in the array.
  • The second line contains \(n\) space-separated integers.
  • The third line contains the integer \(X\).

Output format:

  • Output a single line with either True or False depending on whether such a triplet exists.

Example:

Input:
6
12 3 4 1 6 9
24

Output: True

</p>

inputFormat

The input is taken from standard input (stdin) and follows the structure:

  • The first line contains an integer \(n\).
  • The second line contains \(n\) space-separated integers for the array.
  • The third line contains the integer \(X\).

outputFormat

Print to standard output (stdout) a single line, True if there exists a triplet in the array whose sum equals \(X\), otherwise False.

## sample
6
12 3 4 1 6 9
24
True

</p>