Wrong output please check

import java.util.*;
public class Main {

public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
	int [] arr = new int[n];
	for(int i=0;i<n;i++) {
		arr[i]=s.nextInt();
	}
	int ans=0;
	HashMap<Integer , Boolean> map = new HashMap<Integer, Boolean>();
	int j=0;
	for(int i=0;i<n;i++) {
		while(j<n && !map.containsKey(arr[j])) {
			map.put(arr[j],true);
			j++;
		}
		ans=ans + ((j-i+1)*(j-i+2))/2;
		map.remove(arr[i]);
	}
	
	System.out.println(ans);
	

}

}

bro just a minor issue, here the formulae will be ans=ans + ((j-i)*(j-i+1))/2;
Thats all.
Happy coding!