Error in this Java code

Not able to find whats the error. The description shows lossy conversion between long and int.

import java.util.*;
public class Main {
public static void main (String args[]) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
long[] arr = new long[n];
for(int i=0 ; i<n ;i++){
arr[i]=input.nextLong();
}
majority(n,arr);

}
public static void majority(int n , long[] arr){
    long element1 = arr[0];
    long element2 = 0;
    int count1 =1;
    int count2=0;
    for(int i=1; i<n; i++){
        if(element1==arr[i]) count1++;
        else if (element2==arr[i]) count2++;
        else if(count1==0) {
            element1=arr[i];
            count1=1;
        }
        else if(count2==0){
            element2=arr[i];
            count2=1;
        }
        else{
            count1--;
            count2--;
        }
    }
    int c1=0;
    int c2=0;
    for(long i=0 ; i<n ; i++){
        if(arr[i]==element1){
            c1++;
        }
        else if(arr[i]==element2){
            c2++;
        }
    }
    if(c1>n/3 && c2>n/3){
        System.out.println(element1+ " "+element2);
    }
    else if(c2>n/3){
        System.out.println(element2);
    }
    else if(c1>n/3){
        System.out.println(element1);
    }
    else if(c1<=n/3 &&c2<=n/3){
        System.out.println("No Majority Elements");
    }
}

}

Exception in thread “main” java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Main.main(Main.java:5)

I m getting exception error while compiling but when I submitted, the code passed every test case.

Can you please paste the code in some online ide, such as ide.codingblocks.com, and share the link