/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		new Ideone().run();
	}

	 void run(){
    		int[] arr = { 1, 2, 3, 4, 5, 6 };
    		int req = 14;
            // For the algorithm to work correctly, the array must be sorted
            Arrays.sort(arr);      
		
    		for(int i=0; i<arr.length; i++){// Iterate over the elements of the array.

                // Check in linear time whether there exists distinct indices 
                // lo and hi that sum to req-arr[i]
    			int lo = 0;
    			int hi = arr.length-1;
    			boolean found = false;
    			while(lo<hi){
    				if(lo==i){
    					lo++;
    					continue;
    				}
    				if(hi==i){
    					hi--;
    					continue;
    				}
    				int val = arr[lo] + arr[hi] + arr[i];
    				if(val == req){
    					System.out.println(arr[lo] + " + " + arr[hi] + " + " + arr[i] + " = " + req);
    					found = true;
    					break;
    				}else if(val < req){
    					lo++;
    				}else{
    					hi--;
    				}
    			}
    			if(found){
    				break;
    			}
    		}
    	}
}