Managing Difficulties

Managing Difficulties

Every day a new programming problem is published on Codehorses. Thus, n problems will be published in the following n days: the difficulty of the ii-th problem is ai.

Polycarp wants to choose exactly three days i, j and k (i<j<k) so that the difference of difficulties on the day j and the day i is equal to the difference of difficulties on the day k and day j. In other words, Polycarp wants equality aj−ai=ak−aj to be true.

Determine the number of possible ways for Polycarp to choose the three days in the desired way.

Input
The first line contains an integer t — the number of test cases in the input (1≤t≤10). Then t test case descriptions follow.

The first line of a test case contains an integer n — the number of the days (3≤n≤2000).

The second line of the test case contains n integers a1,a2,…,an, where ai is the difficulty of the problem on the i-th day (1≤ai≤10^9).

Output
Output t integers — the answers for each of the test cases in the input, in the order they are given. The answer to a test case is the number of triples of indices i, j, and k such that 1≤i<j<k≤n and ak−aj=aj−ai.

Example
input
4
5
1 2 1 2 1
3
30 20 10
5
1 2 2 3 4
9
3 1 4 1 5 9 2 6 5
output
1
1

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值