(define (3sum set)
(define pr (let ([pargs (make-hash)])
(lambda args
(unless (hash-has-key? pargs args)
(apply
printf "~A ~A ~A~%" args
) (hash-set! pargs args #t)))))
(for ([i (- (vector-length set) 3)])
(define a (vector-ref set i))
(let loop ([s (add1 i)]
[e (sub1 (vector-length set))])
(when (< s e)
(let* ([b (vector-ref set s)]
[c (vector-ref set e)]
[+abc (+ a b c)])
(cond [(= 0 +abc)
(pr a b c)
(loop s (sub1 e))]
[(< 0 +abc) (loop s (sub1 e))]
[else (loop (add1 s) e)]))))))
(for-each (lambda (x)
(3sum x)
(newline))
(map (compose (curryr vector-sort <)
list->vector
(curry map string->number)
string-split)
(port->lines)))
KGRlZmluZSAoM3N1bSBzZXQpCiAgKGRlZmluZSBwciAobGV0IChbcGFyZ3MgKG1ha2UtaGFzaCldKQogICAgICAgICAgICAgICAobGFtYmRhIGFyZ3MKICAgICAgICAgICAgICAgICAodW5sZXNzIChoYXNoLWhhcy1rZXk/IHBhcmdzIGFyZ3MpCiAgICAgICAgICAgICAgICAgICAoYXBwbHkgcHJpbnRmICJ+QSB+QSB+QX4lIiBhcmdzKQogICAgICAgICAgICAgICAgICAgKGhhc2gtc2V0ISBwYXJncyBhcmdzICN0KSkpKSkKICAoZm9yIChbaSAoLSAodmVjdG9yLWxlbmd0aCBzZXQpIDMpXSkKICAgIChkZWZpbmUgYSAodmVjdG9yLXJlZiBzZXQgaSkpCiAgICAobGV0IGxvb3AgKFtzIChhZGQxIGkpXQogICAgICAgICAgICAgICBbZSAoc3ViMSAodmVjdG9yLWxlbmd0aCBzZXQpKV0pCiAgICAgICh3aGVuICg8IHMgZSkKICAgICAgICAobGV0KiAoW2IgKHZlY3Rvci1yZWYgc2V0IHMpXQogICAgICAgICAgICAgICBbYyAodmVjdG9yLXJlZiBzZXQgZSldCiAgICAgICAgICAgICAgIFsrYWJjICgrIGEgYiBjKV0pCiAgICAgICAgICAoY29uZCBbKD0gMCArYWJjKQogICAgICAgICAgICAgICAgIChwciBhIGIgYykKICAgICAgICAgICAgICAgICAobG9vcCBzIChzdWIxIGUpKV0KICAgICAgICAgICAgICBbKDwgMCArYWJjKSAobG9vcCBzIChzdWIxIGUpKV0KICAgICAgICAgICAgICBbZWxzZSAobG9vcCAoYWRkMSBzKSBlKV0pKSkpKSkKCihmb3ItZWFjaCAobGFtYmRhICh4KQogICAgICAgICAgICAoM3N1bSB4KQogICAgICAgICAgICAobmV3bGluZSkpCiAgICAgICAgICAobWFwIChjb21wb3NlIChjdXJyeXIgdmVjdG9yLXNvcnQgPCkKICAgICAgICAgICAgICAgICAgICAgICAgbGlzdC0+dmVjdG9yCiAgICAgICAgICAgICAgICAgICAgICAgIChjdXJyeSBtYXAgc3RyaW5nLT5udW1iZXIpCiAgICAgICAgICAgICAgICAgICAgICAgIHN0cmluZy1zcGxpdCkKICAgICAgICAgICAgICAgKHBvcnQtPmxpbmVzKSkp