Error: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space in MULTHREE

/* package codechef; // don’t place package name! */

import java.util.Scanner;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
while(scan.hasNextLong()) {
long input = scan.nextLong();
for(long i=0;i<input;i++) {
long a = scan.nextLong();
long[] arr = new long[(int) a];
arr[0] = scan.nextInt();
arr[1] = scan.nextInt();
for(long b=2;b<a;b++) {
arr[(int) b] = sum(arr)%10;
}
if (sum(arr)%3==0)
System.out.println(“YES”);
else
System.out.println(“NO”);
}
}
}
public static long sum(long[] array) {
long sum=0;
for(long i=0;i<array.length;i++)
sum+=array[(int) i];
return sum;
}
}

It works for the first two cases but fails for the test case: 760399384224 5 1

You cannot declare array of size “760399384224”.
Maximum allowed is upto 10^7 or 10^8

Please change logic of your code.

Thanks for the help. I’ll keep that in mind

even i am facing the same issue,
can u help me in my code
import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in=new Scanner(System.in);
long test_case=in.nextLong();

	//int sum=d+d1;
	long s1;
	while(test_case>0)
	{
	    long k=in.nextLong();
        long d=in.nextLong();
	    long d1=in.nextLong();
	    long arr[]=new long[(int)k];
        arr[0]=d;
	    arr[1]=d1;
	    long sum=d+d1;
	for(int i=2;i<k;i++)
{ 
    s1=0;
	    for(int j=0;j<i;j++)
	    {
	        s1+=arr[j];
	    }
	    d1=s1%10;
	    sum+=d1;
	}
	--test_case;
	if(sum%3==0)
	System.out.println("YES");
	else
	System.out.println("NO");
	}
	
	
	
}

}
can u say how to reduce memory