'USACO Server Input Discrepancy

I'm retrying the USACO Silver Problem Robot Instructions.

On my computer (Macbook Air M1 2020, MacOS Big Sur version 11.3.1), when I manually input the sample case my program outputs the correct answer. However, on the USACO grading server, it displays:

The following appeared on standard error:
Exception in thread "main" java.util.NoSuchElementException
    at java.base/java.util.Scanner.throwFor(Scanner.java:937)
    at java.base/java.util.Scanner.next(Scanner.java:1594)
    at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
    at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
    at RobotInstructions.main(RobotInstructions.java:33)

For reference, my current code is:

import java.util.ArrayList;
import java.util.Scanner;
import java.lang.Math;

public class RobotInstructions {
    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        
        int nInstructions = in.nextInt();
        
        int wontx = in.nextInt();
        int wonty = in.nextInt();
        
        ArrayList<int[]> a;
        ArrayList<int[]> b;
        
        int n1;
        int n2;
        
        if (nInstructions%2==0) {
            n1 = (int) nInstructions/2;
            n2 = (int) nInstructions/2;
        } else {
            n1 = ((int) (nInstructions-1)/2);
            n2 = ((int) (nInstructions+1)/2);
        }
        
        /////////////////////////////////
        Scanner in1 = new Scanner(System.in);
        int[][] instructionList = new int[n1][2];
        for (int i = 0; i<n1; i++) {
            int a1 = in1.nextInt();
            int b1 = in1.nextInt(); 
            
            instructionList[i][0] = a1;
            instructionList[i][1] = b1;
        }
        a = subset(n1, instructionList);
        /////////////////////////////////
        /////////////////////////////////
        int[][] instructionList1 = new int[n2][2];
        for (int i = 0; i<n2; i++) {
            int a1 = in1.nextInt();
            int b1 = in1.nextInt(); 
            
            instructionList1[i][0] = a1;
            instructionList1[i][1] = b1;
        }
        b = subset(n2, instructionList1);
        /////////////////////////////////
    
        
        int[] answers = new int[nInstructions];
        
        for (int[] i : a) {
            for (int[] j : b) {
                if (i[0]+j[0]==wontx && i[1]+j[1]==wonty) {
                    answers[i[2]+j[2]-1]++;
                }
            }
        }
        
        for (int i : answers) {
            System.out.println(i);
        }
        
    }
    
    
    
    public static ArrayList<int[]> subset(int n, int[][] instructionList) {
        ArrayList<int[]> sums = new ArrayList<int[]>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i< (Math.pow(2,n)) ; i++) {
            sb.setLength(0);
            String a = Integer.toBinaryString(i);
            for (int j = 0; j<(n-a.length()); j++) {
                sb.append("0");
            }
            sb.append(a);
            
            String c = sb.toString();
            
            int x = 0;
            int y = 0;
            int amt = 0;
            
            for (int k = 0; k<n; k++) {
                if (c.charAt(k) == '1') {
                    x += instructionList[k][0];
                    y += instructionList[k][1];
                    amt++;
                }
            }
            
            int[] m = new int[] {x,y,amt};
            
            sums.add(m);
            
        }
        return sums;
    }
    
    
}

I would not like any feedback on the efficiency of my program, just the reason why the grading server doesn't like my input format.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source