# coding=utf-8

data = open("/Users/humazuhair/Downloads/TP1_data.txt", "r")

lignes = data.readlines()
nb = []
for lines in lignes:
    nb.append(int(lines.strip("\r\n")))

data.close()
print(nb)
# EX1
# Complexite N^2
# i = 1
# trouve = False
# while not trouve and i <= len(nb)-1:
#    j = i+1
#    while not trouve and j<= len(nb)-1:
#        if nb[i]+nb[j] == 2020:
#            trouve = True
#            print(nb[i] ,"+", nb[j] ," = 2020")
#        j = j+1
#    i = i+1

# EX2
# Complexité N^3
# i = 0
# trouve = False
# while not trouve and i <= len(nb) - 2:
#    j = i + 1
#    while not trouve and j <= len(nb) - 1:
#        k = j + 1
#        while not trouve and k <= len(nb) - 1:
#            if nb[i] + nb[j] + nb[k] == 2020:
#                trouve = True
#                print(nb[i], "+", nb[j], "+", nb[k], " = 2020")
#            k = k + 1
#        j = j + 1
#    i = i + 1

# print(sum(nb[:4]))

# EX3
# Complexité N^2
# k = 4
# valeur = 2020
# trouve = False
# Liste = [[]]
# j = 0
# while j < len(nb) and not trouve:
#    nNombre = nb[j]
#    nListe = []
#    for elem in Liste:
#        nElement = elem + [nNombre]
#        if len(nElement) < k and sum(nElement) < valeur:
#            nListe.append(nElement)
#        if len(nElement) == k and (sum(nElement) == valeur):
#            trouve = True
#            print(nElement)
#    Liste = Liste + nListe
#    j = j + 1

# EX4
# valeur = 32465
# trouve = False
# Liste = [[]]
# j = 0
# while j < len(nb) and not trouve:
#    nNombre = nb[j]
#    nListe = []
#    for elem in Liste:
#        nElement = elem + [nNombre]
#        if sum(nElement) < valeur:
#            nListe.append(nElement)
#        if sum(nElement) == valeur:
#            trouve = True
#            print(nElement)
#    Liste = Liste + nListe
#    j = j + 1

# EX5
# Complexité N^2
nb.sort()
valeur = 2020

i = 0
trouve = False
while i <= len(nb) - 3 and not trouve:
    a = nb[i]
    start = i + 1
    end = len(nb) - 1
    while start < end:
        b = nb[start]
        c = nb[end]
        if a + b + c == valeur:
            trouve = True
            print(a, b, c)
            break
        elif a + b + c > valeur:
            end = end - 1
        else:
            start = start + 1
    i = i + 1


