// no of ways to divide the given array into 3 equal parts
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[]nums = new int[n];
		
		for(int i= 0;i<n;i++){
		    nums[i]=sc.nextInt();
		}
		int tot_sum=0;
		for(int i=0;i<n;i++){
		    tot_sum+=nums[i];
		}
		int lhs=0;
		int rhs=0;
		int count=0;
		
		if(tot_sum%3 ==0){
		    int y=tot_sum/3;
		    
		    //I need current sum 
		    int current_sum=0;
		    
		    HashMap<Integer,Integer>f = new HashMap<>();
		    
		    for(int j=0;j<n-1;j++){
		        lhs+=nums[j];
		        rhs=tot_sum-lhs;
		        current_sum+=nums[j];
		        
		        if(lhs == 2*y && rhs ==y ){
		          count=count + f.getOrDefault(current_sum/2,0) ;
		        }
		        f.put(current_sum,f.getOrDefault(current_sum,0)+1);
		    }
		}
		System.out.print("Number of ways to divide in three equal parts :" + count);
	}
}