fork download
  1. // Online C++ compiler to run C++ program online
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int main() {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. long int n,m,c=0;
  10. cin>>n;
  11. int a[n];
  12. for(int i=0;i<n;i++)
  13. {
  14. cin>>m;
  15. a[i]=m;
  16. }
  17. for(int j=n-1;j>=0;j--)
  18. {
  19. for(int i=j-1;i>=0;i--)
  20. {
  21. if((a[j]-a[i])==(j-i))
  22. c++;
  23. }
  24. }
  25. cout<<c<<endl;
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5388KB
stdin
4
6
3 5 1 4 6 6
3
1 2 3
4
1 3 3 4
6
1 6 3 4 5 6
stdout
1
3
3
10