You are given an array a=(a1,a2,…,an) of length n. The function f is defined as follows.
f(1,j)=aj(1≤j≤n)
f(i,j)=min(f(i−1,j), f(i−1,j−1))+aj(2≤i≤n, i≤j≤n)
You are also given m queries. Each query consists of two integers xi and yi, and asks for the value of f(xi,yi). Write a program that answers every query.