1#include<bits/stdc++.h>
2using namespace std;
3
4int count_triangles(int arr[], int n)
5{
6 int ans = 0;
7 for (int i = n - 1; i >= 2; i--){
8 int l = 0, r = i - 1;
9 while(l < r){
10 if (arr[l] + arr[r] > arr[i]){
11 ans += r - l;
12 r--;
13 }
14 else l++;
15 }
16
17 return ans;
18}