package arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class targetsumtriplets {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int num = scn.nextInt();
list.add(num);
}
int target = scn.nextInt();
Collections.sort(list);
int i = 0;
int lo = 1;
int hi = n - 1;
while (lo < hi) {
if (list.get(i) + list.get(lo) + list.get(hi) == target) {
System.out.println(list.get(i)+ list.get(lo) + "and" + list.get(hi));
lo++;
hi--;
}
if (list.get(i) + list.get(lo) + list.get(hi) > target) {
hi = hi - 1;
} else if (list.get(i) + list.get(lo) + list.get(hi) < target) {
lo = lo + 1;
}
i++;
}
}
}
WHAT IS WRONG IN THIS CODE???