chotu-and-kiss-day

"It all started with a kiss."

Chotu was up all night, planning for his first kiss. He has collected the data about all the kissing spots in Allahabad.
According to his survey there are N kissing spots in the city, each spot i is associated with a security value Si.
Chotu wants to visit as many spot as they can, but unfortunately the evil seniors hosted a contest on Kiss Day. 

"Who on earth would code on kiss day!!" said Chotu. He tries to persuade his girlfriend to leave the contest but she being a true IIIT'an was determined to participate in the contest (kudos to the girlfriend).
Chotu is left with no other option but to replan his trip. He comes to a conclusion that if they visit more than three spots they will not be able to participate in the contest. So he decided to visit exactly three spots.

This is not the end of problems for Chotu. Allahabad is not a paradise for lovers. Bajrang Dal, a moral policing group is active in Allahabad, which is famous for troubling the couples during valentine week.
But Chotu being intelligent has an escape plan. Bajrang Dal's aversion towards the number K is well known. Chotu knows that if the sum of the security factors of the three visited spots is K, then they will be safe.

Help Chotu find out whether he can safely celebrate Kiss Day or not.

Input

First line contains integer N denoting total number of kissing spots according to Chotu's survey. 

Second line contains N distinct numbers separated by single space denoting the security value of N spots.

Third line contains integer K as explained above.

Output

Print YES if Chotu is able to find three places whose sum of security value is equal to given integer K else print NO.

Constraints

1 ≤ N ≤ 3*10^3

1 ≤ Security Value ≤ 10^9

1 ≤ K ≤ 10^9
Note - Chotu can visit each place only once.

SAMPLE INPUT
6
1 5 4 7 8 9
17

SAMPLE OUTPUT
YES

Explanation

He can visit places with security value of 1, 7 and 9.

Source: hackerearth | Difficulty: EASY


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
import sys
n=eval(input())
s=[int(i) for i in input().split()]
t=eval(input())
s.sort()

for i in range(n):
	x=t-s[i]
	l=0
	r=n-1
	while(l<r):
		if s[l]+s[r]==x:
			print("YES")
			sys.exit(0)
		elif s[l]+s[r]>x:
			r-=1
		else:
			l+=1
else:
	print("NO")


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
import sys
n=eval(input())
s=[int(i) for i in input().split()]
t=eval(input())
s.sort()

for i in range(n):
	x=t-s[i]
	l=0
	r=n-1
	while(l<r):
		if s[l]+s[r]==x:
			print("YES")
			sys.exit(0)
		elif s[l]+s[r]>x:
			r-=1
		else:
			l+=1
else:
	print("NO")