count the number of possible triangles
#include<bits/stdc++.h>
using namespace std;
int count_triangles(int arr[], int n)
{
int ans = 0;
for (int i = n - 1; i >= 2; i--){
int l = 0, r = i - 1;
while(l < r){
if (arr[l] + arr[r] > arr[i]){
ans += r - l;
r--;
}
else l++;
}
return ans;
}