<s>[INST] public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt() ;
        int max = 0;
        int result = 0;
        for (int i = 0; i < num; i++) {
            int w = in.nextInt();
            int x = in.nextInt();
            int y = in.nextInt();
            int z = in.nextInt();
            result = w + x + y + z;
            if (result > max) {
                max = result;
            }
        }
        System.out.println(max);
    }

The code is using a for loop to take in the input of multiple sets of four integers, and it is adding them together. If the sum of any set is larger than the previous max sum, then it gets stored as the max sum. I want to change this code so it will instead be checking for the max of the largest integer that when added to any of the other three integers does not exceed 1000000. 

How would I go about doing this?[/INST]