APAC round B Problem C large

dp
dp[i] = min(dp[i], dp[k-1](if f[k,i] = True), dp[i-1]+1)
f[i,j] = f[i,k] && f[k+1,j] OR f[i+1,k-1] && f[k+1,j-1]&&
a[j]-a[k]==a[k]-a[i] == d