xenny-and-range-sums

PowerShell had N natural numbers. He wanted to test Xenny's speed in finding the sum and difference of several numbers.

He decided to ask Xenny several questions. In each question, he gave him two positive integers L and R. He asked him to find the sum of all integers from index L to index R (inclusive) and the difference of all integers from index R to index L (inclusive).

(Numbers are 1-indexed) 

He asked Xenny Q such questions.

Your task is to report the answer that Xenny gave to each of the Q questions.

Input Format:

First line contains 2 space-separated integers - N and Q.

Second line contains N space-separated natural numbers.

Q lines follow - each line contains 2 space-separated postiive integers L and R.

Output Format:

Output Q lines - the answer to each question.

Each line should contain 2 space-separated integers - the required sum and difference.

Constraints:

1 ≤ N ≤ 10^6

1 ≤ L ≤ R ≤ 10^6

1 ≤ Q ≤ 10^5

-1000000 ≤ Numbers ≤ 1000000

SAMPLE INPUT
4 1
1 2 3 4
1 3

SAMPLE OUTPUT
6 0

Explanation

1 + 2 + 3 = 6

3 - 2 - 1 = 0

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
a,b=list(map(int,input().split()))
l=[]
l.append(0)
x=[]
x.append(0)
x.extend(list(map(int,input().split())))
for i in range(1,a+1):
	l.append(l[i-1]+x[i])
"""print l
print x"""

while(b):
	c,d=list(map(int,input().split()))
	print(l[d]-l[c-1],x[d]-(l[d-1]-l[c-1]))
	b=b-1


a,b=list(map(int,input().split()))
l=[]
l.append(0)
x=[]
x.append(0)
x.extend(list(map(int,input().split())))
for i in range(1,a+1):
	l.append(l[i-1]+x[i])
"""print l
print x"""

while(b):
	c,d=list(map(int,input().split()))
	print(l[d]-l[c-1],x[d]-(l[d-1]-l[c-1]))
	b=b-1


def main():
	N,Q=[int(x) for x in input().split()]
	nums = [0]
	nums.extend([int(x) for x in input().split()])
	for i in range(1,N+1):
		nums[i] += nums[i-1]
		
	for _ in range(Q):
		L,R = [int(x) for x in input().split()]
		print(nums[R]-nums[L-1],(nums[R]-nums[R-1])-(nums[R-1]-nums[L-1]))
		
main()
		


def main():
	N,Q=[int(x) for x in input().split()]
	nums = [0]
	nums.extend([int(x) for x in input().split()])
	for i in range(1,N+1):
		nums[i] += nums[i-1]
		
	for _ in range(Q):
		L,R = [int(x) for x in input().split()]
		print(nums[R]-nums[L-1],(nums[R]-nums[R-1])-(nums[R-1]-nums[L-1]))
		
main()