#C14714. Three Sum Problem

    ID: 44394 Type: Default 1000ms 256MiB

Three Sum Problem

Three Sum Problem

You are given a list of integers and a target sum. Your task is to determine if there exist three distinct elements in the list such that their sum equals the target value. Formally, given a sequence of integers \(a_1, a_2, \dots, a_n\) and a target \(T\), determine if there exist indices \(i, j, k\) (all distinct) such that:

\[a_i + a_j + a_k = T\]

If such a triplet exists, print True; otherwise, print False.

Note: Even if the same number appears multiple times, they are considered distinct if their positions in the list are different.

inputFormat

The input is given via standard input (stdin) in the following format:

n
a1 a2 ... an
T

Where:

  • n is a non-negative integer representing the number of elements in the list.
  • a1 a2 ... an are the space-separated integers.
  • T is the target sum.

outputFormat

Output a single line to standard output (stdout) containing either True or False indicating whether such a triplet exists.

## sample
6
1 4 45 6 10 8
22
True

</p>