Harry potter and mixtures

import java.util.*;
public class HarryPotterMixtures {

static long[][] dp = new long[1000][1000];
static int[] a = new int[1000];

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	for(int i=0;i<n;i++) {
		a[i] = sc.nextInt();
	}
	
	
	
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=n;j++) {
			dp[i][j] = -1;
		}
	}
	
	System.out.println(solveMixtures(0,n-1));
	
}

public static long solveMixtures(int i,int j) {
	//base case
	if(i>=j) {
		return 0;
	}
	
	if(dp[i][j] != -1) {
		return dp[i][j];
	}
	
	dp[i][j] = Integer.MAX_VALUE;
	for(int k=i;k<=j;k++){
		dp[i][j] = Math.min(dp[i][j], solveMixtures(i,k)+solveMixtures(k+1,j)+sum(i,k)*sum(k+1,j));
	}
	return dp[i][j];
}

public static long sum(int s,int e) {
	long ans = 0;
	for(int i=s;s<=e;i++) {
		ans += a[i];
		ans %= 100;
	}
	return ans;
}

}

//sir I’m getting index out of bounds exception in this code

@Siddharth_sharma1808,

https://ide.codingblocks.com/s/233031 corrected code. I have highlighted the error as well.

you had done s<=e instead of i<=e that’s why the loop was going in an infinite loop.