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