import java.util.*;
class Ideone {
public static void main
(String[] args
){ //int[] a = {4, 6, 3, 7};
int[] a = {10, 21, 22, 100, 101, 200, 300};
int trianglesCount = 0;
//Sort the array elements
for(int i=0; i< a.length; i++){
for(int j=i+1; j<a.length; j++){
//Find an element such that a[i] + a[j] > a[k]
int sum = a[i] + a[j];
int k=j;
while(k<a.length && sum > a[k]){
k++;
}
// System.out.println("No of triangles with index i => "+ i + " j => "+ j + " k-j => "+ (k-j));
trianglesCount += (k-j-1);
}
}
System.
out.
println("No of trianges can be formed with given array elements as edges of triangle => "+trianglesCount
); }
}