Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import bisect

n, m = map(int, input().split())
a = list(map(int, input().split()))
min_num = min(a)
process = []

for i in range(m):
    array = list(map(int, input().split()))
    if array[1] > min_num:
        process.append(array)


a.sort()
process = sorted(process, key=lambda x: -x[1])

for i in range(len(process)):
    index = bisect.bisect_left(a, process[i][1])
    ooo = min(index, process[i][0])
    if ooo == 0:
        continue
    else:
        a[0:ooo] = [process[i][1]]*ooo
    a.sort()
    if a[0] > process[i][1]:
        break

print(sum(a))


### FIXED CODE ###

from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import math

K = int(input())
result = 0
sum = 0




for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            result = math.gcd(a, b)
            result = math.gcd(result, c)
            sum = sum + result

print(sum)            


### FIXED CODE ###

K = int(input())
import math
sum=0
for i in range(1, K+1):
    for j in range(1, K+1):
        value = math.gcd(i,j)
        for k in range(1, K+1):
            sum += math.gcd(value,k)
 
print(sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7

dp = [0] * (1 << n)
dp[0] = 1

for bit in range(1,1 << n):
    i = bin(bit).count('1')
    for j in range(n):
        if ((bit >> j) & 1 == 1) and (a[i - 1][j] == 1):
            dp[bit] += dp[bit ^ (1 << j)]
            dp[bit] %= mod
print(dp[-1])


### FIXED CODE ###

mod = 10**9+7
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
dp = [0]*(1 << n)
dp[0] = 1
for i in range(1, 1 << n):
    k = bin(i).count("1")
    for j in range(n):
        if i >> j & 1 and a[k-1][j]:
            dp[i] += dp[i ^ (1 << j)]
    dp[i] %= mod
print(dp[(1 << n)-1])
### BUGGY CODE ###

import functools
import fractions
N = int(input())
A_list = list(map(int, input().split()))
ans = 0

for i in range(1,N+1):
    x = A_list[-i]
    del A_list[-i]
    gcd = functools.reduce(fractions.gcd, A_list)
    ans = max(gcd,ans)
    A_list.append(x)
print(ans)



### FIXED CODE ###

#累積GCDによるsolution : O(N)
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
B = [A[0]]+[0]*(N-1)
C = [0]*(N-1)+[A[-1]]
for i in range(N-1):
    B[i+1] = gcd(A[i+1],B[i])
for i in range(N):
    C[-i-1] = gcd(A[-i-1],C[-i])

ans = 0
for i in range(1,N-1):
    ans = max(gcd(B[i-1],C[i+1]),ans)
# in case of i=0,N-1
ans = max(ans,C[1])
ans = max(ans,B[-2])
print(ans)
### BUGGY CODE ###

s = input()
q = int(input())

for i in range(q):
    Q = list(input().split())
    if int(Q[0]) == 1:
        s = s[::-1]
    else:
        if int(Q[1]) == 1:
            t = s[::-1]
            t += Q[2]
            s = t[::-1]
        else:
            s += Q[2]

print(s)


### FIXED CODE ###

from collections import deque
s = input()
q = int(input())

s = deque(s)
cnt = 0

for i in range(q):
    Q = list(input().split())
    if int(Q[0]) == 1:
        cnt += 1
    else:
        if int(Q[1]) == 1:
            if cnt % 2 == 0:
                s.appendleft(Q[2])
            else:
                s.append(Q[2])
        else:
            if cnt % 2 == 0:
                s.append(Q[2])
            else:
                s.appendleft(Q[2])

ans = ''

for _ in range(len(s)):
    if cnt % 2 == 0:
        ans += s.popleft()
    else:
        ans += s.pop()

print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import copy

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

B = []
C = []
for _ in range(Q):
    B_i, C_i = map(int, input().split())
    
    B.append(B_i)
    C.append(C_i)

for i in range(Q):
    A_ = []
    for j in range(N):
        A_.append((A[j] if A[j] != B[i] else C[i]))
    print(sum(A_))
    
    A = copy.deepcopy(A_)


### FIXED CODE ###

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

B = []
C = []
for _ in range(Q):
    B_i, C_i = map(int, input().split())
    
    B.append(B_i)
    C.append(C_i)

max_i = max(max(A), max(C))

A_N = [0 for _ in range(max_i + 1)]
sum_i = 0

for a in A:
    A_N[a] += a
    sum_i += a

for i in range(Q):
    diff_replace = int(A_N[B[i]] / B[i]) * C[i]
    sum_i += diff_replace - A_N[B[i]]
    
    A_N[C[i]] += diff_replace
    A_N[B[i]] = 0
    
    print(sum_i)
### BUGGY CODE ###

import collections

n = int(input())
s = str(input())

aaa = collections.Counter(s)
s_r = aaa["R"]
s_g = aaa["G"]
s_b = aaa["B"]

s = s.replace("R", "0").replace("G", "1").replace("B", "2")

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

ans = s_r * s_g * s_b

for i in range(n):
  for d in range(n):
    j = i + d
    k = j + d
    if k >= n:
      break;
    else:
      a = int(s[i])
      b = int(s[j])
      c = int(s[k])
      if noteq(a, b, c):
        ans -= 1
    
print(ans)

### FIXED CODE ###

import collections

n = int(input())
s = str(input())

aaa = collections.Counter(s)
s_r = aaa["R"]
s_g = aaa["G"]
s_b = aaa["B"]

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

ans = s_r * s_g * s_b

for i in range(n):
  for d in range(n):
    j = i + d
    k = j + d
    if k >= n:
      break;
    else:
      a = s[i]
      b = s[j]
      c = s[k]
      if noteq(a, b, c):
        ans -= 1
    
print(ans)
### BUGGY CODE ###

import queue
import numpy as np

def penetrate(x, y, count):
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]

        if 0 <= nx < h and 0 <= ny < w and A[nx][ny] == "." and d[nx][ny] == -1:
            d[nx][ny] = count + 1
            q.put((nx, ny, d[nx][ny]))


h, w = map(int, input().split())
d = [[-1] * w for _ in range(h)]

A = [[] for i in range(h)]
q = queue.Queue()

for i in range(h):
    A[i] = list(input())
    for j in range(w):
        if A[i][j] == "#":
            d[i][j] = 0
            q.put((i, j, d[i][j]))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

while q.empty() == False:
    idx = q.get()
    penetrate(idx[0], idx[1], idx[2])

print(np.max(d))


### FIXED CODE ###

from collections import deque

def penetrate(x, y, count):
    global max_idx
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]

        if 0 <= nx < h and 0 <= ny < w and A[nx][ny] == "." and d[nx][ny] == -1:
            d[nx][ny] = count + 1
            q.append((nx, ny, d[nx][ny]))
            max_idx = max(max_idx, d[nx][ny])


h, w = map(int, input().split())
d = [[-1] * w for _ in range(h)]

A = [[] for i in range(h)]
q = deque()

for i in range(h):
    A[i] = list(input())
    for j in range(w):
        if A[i][j] == "#":
            d[i][j] = 0
            q.append((i, j, d[i][j]))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
max_idx = 0

while len(q) > 0:
    idx = q.popleft()
    penetrate(idx[0], idx[1], idx[2])

print(max_idx)
### BUGGY CODE ###

N,X,Y = map(int,input().split())
data = [[3000]*N for _ in range(N)]
edge = []
for i in range(N-1):
  edge.append((i+1,i+2))
edge.append((X,Y))
for item in edge:
  data[item[0]-1][item[1]-1] = 1
  data[item[1]-1][item[0]-1] = 1
for i in range(N):
  data[i][i] = 0
for k in range(N):
  for i in range(N):
    for j in range(N):
      data[i][j] = min(data[i][j],data[i][k]+data[k][j])
for i in range(N-1):
  counter = 0
  for j in range(N):
    counter += data[j].count(i+1)
  print(int(counter//2))

### FIXED CODE ###

N,X,Y = map(int,input().split())
a = [0]*(N-1)
for i in range(1,N):
  for j in range(i+1,N+1):
    ans = min(j-i,abs(X-i)+1+abs(Y-j),abs(X-j)+1+abs(Y-i))
    a[ans -1] += 1
for item in a:
  print(item)
### BUGGY CODE ###

n = int(input())
ans = []
for i,a in enumerate([int(i) for i in input().split()]):
    a = str(a)
    #if i%2 == 0:
    ans.append(a)
    ans = ans[::-1]
    #else:
    #    ans.insert(0,a)
print(' '.join(ans))


### FIXED CODE ###

n = int(input())
l,r = [],[]
for i,a in enumerate([int(i) for i in input().split()]):
    if (n%2 == 0 and (i+1)%2 == 0) or (n%2 == 1 and (i+1)%2 == 1):
        l.append(str(a))
    else:
        r.append(str(a))
for a in l[::-1]:
    print(a,end=' ')
for b in r:
    print(b,end=' ')
print()
### BUGGY CODE ###

n = int(input())

print(0, flush=True)
sex = input()
if sex == "Vacant":
    exit(0)
axis = sex

left = 1
right = n

while left + 1 < right:
    mid = (left + right) // 2
    print(mid, flush=True)
    sex = input()
    if sex == "Vacant":
        exit(0)
    elif sex == axis:
        left = mid + 1
    else:
        right = mid
    cnt += 1
    if cnt >= 20:
        exit(0)

print(left, flush=True)
exit(0)


### FIXED CODE ###

def val(num):
    print(num, flush=True)
    sex = input()
    if sex == "Vacant":
        exit(0)
    return 1 if sex == "Male" else 0


n = int(input())

l_sex = val(0)
r_sex = val(n - 1)

left = 0
right = n - 1

while left < right:
    mid = (left + right) // 2
    sex = val(mid)
    if (mid - left) % 2 == 0 and sex != l_sex:
        right = mid
        r_sex = sex
    elif (mid - left) % 2 == 1 and sex == l_sex:
        right = mid
        r_sex = sex
    else:
        left = mid
        l_sex = sex

print(left, flush=True)
exit(0)
### BUGGY CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
def Sum(i,k):
  return (sum(p[i:i+k])+k)/2
ans=0
for i in range(n-k+1):
  ans = max(ans,Sum(i,k))
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
for i in range(n-k+1):
  if i==0:
    s=sum(p[:k])
    m=s
  else:
    s=s+p[i+k-1]-p[i-1]
    m = max(m,s)
print((m+k)/2)
### BUGGY CODE ###

from collections import deque

def main():
    N,M,K=map(int,input().split())
    MOD=998244353
    E=0

    n_=1
    for i in range(1,N):
        n_=(n_*i)%MOD

    nr_ = 1
    nr_array=deque([])
    for i in range(1,N-1):
        nr_ = (nr_ * i) % MOD
        nr_array.append(nr_)

    r_=1
    for i in range(0,K+1):
        if i!=0 and i!=N-1:
            r_ = (r_ * i) % MOD
            nr_=nr_array.pop()
            power_r=pow(r_,MOD-2,MOD)
            power_nr=pow(nr_,MOD-2,MOD)
        Mk=pow(M-1,N-1-i,MOD)

        if i!=0 and i!=N-1:
            E+=(n_*power_r*power_nr*Mk)%MOD
        else:
            E+=Mk%MOD

    res=(M*E)%MOD
    print(res)

if __name__=="__main__":
    main()



### FIXED CODE ###

def main():
    N,M,K=map(int,input().split())
    MOD=998244353
    E=0

    n_=1
    for i in range(1,N):
        n_=(n_*i)%MOD

    nr_ = 1
    nr_array=[]
    for i in range(1,N-1):
        nr_ = (nr_ * i) % MOD
        nr_array.append(nr_)
    m=1
    Mk_array=[1]
    for i in range(1,N):
        m=(m*(M-1))%MOD
        Mk_array.append(m)
    r_=1
    for i in range(0,K+1):
        if i!=0 and i!=N-1:
            r_ = (r_ * i) % MOD
            nr_=nr_array.pop()
            power_r=pow(r_,MOD-2,MOD)
            power_nr=pow(nr_,MOD-2,MOD)
        Mk=Mk_array.pop()

        if i!=0 and i!=N-1:
            E+=(n_*power_r*power_nr*Mk)%MOD
        else:
            E+=Mk%MOD

    res=(M*E)%MOD
    print(res)

if __name__=="__main__":
    main()
### BUGGY CODE ###

words = lambda t : list(map(t, input().split()))

h,w = words(int)
mat = []
mat.append([True for _ in range(w+2)])
for _ in range(h):
    mat.append([True] + [a == '#' for a in input()] + [True])
mat.append([True for _ in range(w+2)])

#mat = np.array(mat)
#print(mat)

prev = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if mat[i][j]:
            prev.append((i,j))

round = -1
while not len(prev) ==  0:
    #print(prev)
    #print(mat)
    round += 1
    next = []
    for (x,y) in prev:
        if not mat[x-1][y]:
            next.append((x-1,y))
            mat[x-1][y] = True
        if not mat[x][y-1]:
            next.append((x,y-1))
            mat[x][y-1] = True
        if not mat[x+1][y]:
            next.append((x+1,y))
            mat[x+1][y] = True
        if not mat[x][y+1]:
            next.append((x,y+1))
            mat[x][y+1] = True
    prev = next

print(round)


### FIXED CODE ###

import functools as ft

h,w = map(int, input().split())
mat = [[True] * (w+2)]
for _ in range(h):
    mat.append([True] + [a == '#' for a in input()] + [True])
mat.append([True]*(w+2))

prev = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if mat[i][j]:
            prev.append((i,j))



round = -1
while prev:
    round += 1
    #print(prev)
    #print(mat)
    def calc(next, tup):
        x = tup[0]
        y = tup[1]
        if not mat[x-1][y]:
            next.append((x-1,y))
            mat[x-1][y] = True
        if not mat[x][y-1]:
            next.append((x,y-1))
            mat[x][y-1] = True
        if not mat[x+1][y]:
            next.append((x+1,y))
            mat[x+1][y] = True
        if not mat[x][y+1]:
            next.append((x,y+1))
            mat[x][y+1] = True
        return next
    next = ft.reduce(calc, prev, [])

    prev = next

print(round)
### BUGGY CODE ###

#ABC951B/Sum_of_Three_Integers

K, S = map(int, input().split())
ans = 0
for X in range(0, K+1):
    for Y in range(X, K+1):
        for Z in range(Y, K+1):
            if X == Y == Z and X + Y + Z == S:
                ans += 1
            elif X == Y and X + Y + Z == S:
                ans += 3
            elif Y == Z and X + Y + Z ==S:
                ans += 3
            elif X + Y + Z == S:
                ans += 6
print(ans)

### FIXED CODE ###

#ABC951B/Sum_of_Three_Integers

K, S = map(int, input().split())
ans = 0
for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if 0 <= z and z <= K:
            ans += 1
print(ans)
### BUGGY CODE ###

count=0
k,s=map(int,input().split())
for i in range(k+1):
  for j in range(k+1):
    for m in range(k+1):
      if i+j+m==s:
        count+=1
print(count)

### FIXED CODE ###

count=0
k,s=map(int,input().split())
for i in range(k+1):
  for j in range(k+1):
    if s-k<=i+j<=s:
      count+=1
print(count)
### BUGGY CODE ###

N,M = map(int, input().split())
Ss = list(map(int, input().split()))
Ts = list(map(int, input().split()))
mod = 10**9 + 7

x = 2160
dp = [[0]*x for i in range(x)]
for i in range(N):
    for j in range(M):
        if Ss[i] == Ts[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % mod
        else:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] - dp[i][j])%mod

print((dp[N][M]+1)%mod)

### FIXED CODE ###

N,M = map(int, input().split())
Ss = list(map(int, input().split()))
Ts = list(map(int, input().split()))
mod = 10**9 + 7

x = 2160
dp = [[0]*x for i in range(x)]
for i in range(N):
    for j in range(M):
        if Ss[i] == Ts[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % mod
        else:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] - dp[i][j])%mod

print((dp[N][M]+1)%mod)
### BUGGY CODE ###

n=int(input())
mod=10**9+7;ans=0
a=list(map(int,input().split()))
for i in range(61):
  checkbit=1 << i
  cnt=0
  for j in a:
    cnt+= (j & checkbit) // checkbit
  ans+=checkbit*cnt*(n-cnt)
  ans%=mod
print(ans)


### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
s=[0]*61
for i in range(n):
  c=format(a[i], 'b')
  L=len(c)
  for j in range(L)[::-1]:
    s[L-j-1]+=int(c[j])
ans=0
for i in range(61):
  ans+=2**(i)*(s[i])*(n-s[i])
  ans%=mod
print(ans)
### BUGGY CODE ###


N=int(input())
X=[]
L=[]
for i in range(1,N+1):
    x, l=map(int,input().split())
    X.append(x)
    L.append(l)
A=N
c=0

X.sort()

Check=[[X[i]-L[i],X[i]+L[i]] for i in range(N)]

for j in range(1,N):
    if j == N:
        break
    if Check[j-1][1] > Check[j][0]:
        c=c+1
        Check.remove(Check[j])
        j=j-1
        N=N-1
    
print(A-c)

### FIXED CODE ###

N=int(input())
s=[list(map(int,input().split())) for i in range(N)]
A=N
c=0
s.sort(key=lambda x: x[0])

Check=[[s[i][0]-s[i][1],s[i][0]+s[i][1]] for i in range(N)]
tmp=Check[0][1]
for j in range(1,N):
    if tmp > Check[j][0]:
        c=c+1
        tmp=min(tmp, Check[j][1])
    else:
        tmp=Check[j][1]
    
print(A-c)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
C = list(map(int,input().split()))
LR = [tuple(map(int,input().split())) for i in range(Q)]

class SegTree:
    def __init__(self,arr,func,unit):
        self.func = func
        self.unit = unit
        n = 1
        while n < len(arr):
            n *= 2
        self.n = n
        nodes = [set() for _ in range(2*n-1)]
        nodes[n-1:n-1+len(arr)] = [set([a]) for a in arr]
        for i in range(n-2,-1,-1):
            nodes[i] = func(nodes[2*i+1],nodes[2*i+2])
        self.nodes = nodes

    def update(self,i,val):
        i += self.n-1
        self.nodes[i] = val
        while i >= 0:
            i = (i - 1) // 2
            self.nodes[i] = self.func(self.nodes[2*i+1], self.nodes[2*i+2])

    def query(self,l,r):
        l += self.n
        r += self.n
        s = self.unit
        while l < r:
            if r & 1:
                r -= 1
                s = self.func(self.nodes[r-1], s)
            if l & 1:
                s = self.func(s, self.nodes[l-1])
                l += 1
            l >>= 1
            r >>= 1
        return s

segt = SegTree(C, lambda x,y:x|y, set())
ans = []
for l,r in LR:
    ans.append(len(segt.query(l-1,r)))
print(*ans, sep='\n')

### FIXED CODE ###

import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
C = list(map(int,input().split()))
LR = [tuple(map(int,input().split())) for i in range(Q)]

qs = [[] for _ in range(N)]
for i,(l,r) in enumerate(LR):
    qs[l-1].append((i,r-1))

from collections import defaultdict
hist = defaultdict(lambda: -1)
nx = [-1] * N
for i in range(N-1,-1,-1):
    nx[i] = hist[C[i]]
    hist[C[i]] = i

class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr)
bit = BinaryIndexedTree(N)

ans = [None] * Q
for l in range(N-1,-1,-1):
    if nx[l] != -1:
        bit.add(nx[l], -1)
    for i,r in qs[l]:
        ans[i] = r-l+1 + bit.sum(l,r+1)

print(*ans, sep='\n')
### BUGGY CODE ###

S = list(input())
dp = [[0 for _ in range(13)] for _ in range(len(S)+1)]
dp[0][0]=1
#print(dp[15][5])
for i in range(len(S)):
  a = 0
  if S[i]=="?":
    a = -1
  else:
    a = int(S[i])
  for j in range(10):
    if a!=-1 and a!=j:
      continue
    for k in range(13):
      dp[i+1][(k*10+j)%13] += dp[i][k]
print(dp[len(S)][5]%(10**9+7))

### FIXED CODE ###

S = list(input())
dp = [[0 for _ in range(13)] for _ in range(len(S)+1)]
dp[0][0]=1
#print(dp[15][5])
for i in range(len(S)):
  a = 0
  if S[i]=="?":
    for j in range(10):
      for k in range(13):
        dp[i+1][(k*10+j)%13] += dp[i][k]
  else:
    a = int(S[i])
    for k in range(13):
      dp[i+1][(k*10+a)%13] += dp[i][k]
  for k in range(13):
    dp[i + 1][k] %= (10**9+7)
print(dp[len(S)][5])
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10**9 + 7

    answer = 0
    for i in range(N):
        answer = answer % mod +  A[i] % mod * sum(A[i+1:]) % mod

    print(answer)

main()



### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

sq_sum = sum(map(lambda x: x*x, A))
sum_sq = sum(A) * sum(A)
answer = (sum_sq - sq_sum) // 2

print(answer % mod)
### BUGGY CODE ###


n,m,q=map(int,input().split())
counts=[[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l,r=map(int,input().split())
    counts[l-1][r-1]+=1
cumsum=[[0 for _ in range(n+1)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        cumsum[i][j+1]=cumsum[i][j]+counts[i][j]
    
for _ in range(q):
    l,r=map(int,input().split())
    print(sum(cumsum[i][r]-cumsum[i][l-1] for i in range(l-1,r)))

### FIXED CODE ###

n,m,q=map(int,input().split())
counts=[[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l,r=map(int,input().split())
    counts[l-1][r-1]+=1
cumsum=[[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        cumsum[i+1][j+1]=cumsum[i+1][j]+counts[i][j]
for j in range(n+1):
    for i in range(n):
        cumsum[i+1][j]+=cumsum[i][j]
        
for _ in range(q):
    l,r=map(int,input().split())
    print(cumsum[r][r]-cumsum[r][l-1]-cumsum[l-1][r]+cumsum[l-1][l-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import math

if __name__ == '__main__':
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    for i in range(N):
        b = A[:i] + A[i+1:]
        print(max(b))


### FIXED CODE ###

# -*- coding: utf-8 -*-

import math

if __name__ == '__main__':
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    value = sorted(A)
    first = value[N-1]
    second = value[N-2]


    # print(A)

    for i in range(N):
        if A[i] != first:
            print(first)
        else:
            print(second)
### BUGGY CODE ###

# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

# n = int(input())
h, n = map(int, input().split())
# a = list(map(int, input().split()))
a, b = [0] * n, [0] * n

for i in range(n):
    a[i], b[i] = map(int,input().split())

dp = [10**9+7] * (h+1)
dp[0] = 0

for i in range(n):

    for j in range(h):

        dp[min(j+a[i], h)] = min(dp[min(j+a[i],h)], dp[j]+b[i])


print(dp[h])

### FIXED CODE ###

# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

# n = int(input())
h, n = map(int, input().split())
# a = list(map(int, input().split()))
a, b = [0] * n, [0] * n

for i in range(n):
    a[i], b[i] = map(int,input().split())

dp = [10**9+7] * (h+1)
dp[0] = 0

for i in range(n):

    for j in range(h):

        dp[min(j+a[i], h)] = min(dp[min(j+a[i],h)], dp[j]+b[i])


print(dp[h])
### BUGGY CODE ###

N = int(input())
inf = 10**18
a = list(map(int, input().split()))
ans = a[0]
for i in range(1,len(a)):
    ans = ans * a[i]
if ans > inf:
    print("-1")
else:
    print(ans)

### FIXED CODE ###

#b
import sys
N = int(input())
inf = 10**18
a = list(map(int, input().split()))
ans = a[0]
if 0 in a:
    print("0")
    sys.exit()
for i in range(1,len(a)):
    ans = ans * a[i]

    if ans > inf:
        print("-1")
        sys.exit()
print(ans)