Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    # 現在の足場を1~K前の足場から求める
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-K),i)])

print(dp[-1])


Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-K),i)])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    # 現在の足場を1~K前の足場から求める
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-K),i)])

print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-K),i)])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    # 現在の足場を1~K前の足場から求める
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-Ｋ),i)])

print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-K),i)])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')] * N
dp[0] = 0
for i in range(N-1):
    for j in range(i+1, i+K+1):
        if N <= j:
            break
        dp[j] = min(dp[j], dp[i] + abs(h[i]-h[j]))

print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-K),i)])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp =[float('inf')] * N
dp[0] = 0
for i in range(N):
    if i + K + 1 >= N:
        t = N
    else:
        t = i + K + 1 
    for j in range(i, t):
        if j >= N:
            break
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0,i-K),i)])

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
t = list(range(A, B+1))
if K > len(t):
    K = len(t)
ans = set()
for i in range(K):
    ans.add(t[i])
    ans.add(t[-(i+1)])
ans2 = list(ans)
ans2.sort()
for a in ans2:
    print(a)

Fixed submission:
A, B, K = map(int, input().split())
if K > B-A+1:
    K = B-A+1
t = set()
for i in range(A, A+K):
    t.add(i)
for i in range(B-K+1, B+1):
    t.add(i)
ans = list(t)
ans.sort()
for a in ans:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input())-1 for i in range(N)]

light = 0
first = 0
ans = 0

while True:
    if light == A[light]:
        print(-1)
        exit()
    light = A[light]
    ans += 1
    if light == 1:
        print(ans)
        exit()
    if light == first:
        print(-1)
        exit()



Fixed submission:
N = int(input())
A = [int(input())-1 for _ in range(N)]
p = 0
for i in range(N):
    if p == 1:
        print(i)
        break
    p = A[p]
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count = 0
K += 1
for x in range(K):
    for y in range(K):
        for z in range(K):
            if S == x + y + z:
                count += 1
print(count)

Fixed submission:
K, S = map(int, input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K:
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input())
kotae = c - (a - b)
if kotae > 0:
  print(kotae)
else:
  print(0)

Fixed submission:
a, b, c = map(int, input().split())
kotae = c - (a - b)
if kotae > 0:
  print(kotae)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
kotae = 0
if n == 100000:
  kotae = 90909
elif n => 10000:
  kotae = 909 + (n - 10000 + 1)
elif n => 1000:
  kotae = 909
elif n => 100:
  kotae = 9 + (n- 100 +1)
elif n => 10:
  kotae = 9
else:
  kotae = n
print(kotae)

Fixed submission:
n = int(input())
kotae = 0
if n == 100000:
  kotae = 90909
elif n >= 10000:
  kotae = 909 + (n - 10000 + 1)
elif n >= 1000:
  kotae = 909
elif n >= 100:
  kotae = 9 + (n- 100 +1)
elif n >= 10:
  kotae = 9
else:
  kotae = n
print(kotae)

Buggy python submission (verdict: Runtime Error):
n = int(input())
kotae = 0
if n == 100000:
  kotae = 90909
elif n => 10000:
  kotae = 909 + (n - 10000 + 1)
elif n => 1000:
  kotae = 909
elif n => 100:
  kotae = 9 + (n- 100 +1)
elif n => 10:
  kotae = 9
else:
  kotae = n

Fixed submission:
n = int(input())
kotae = 0
if n == 100000:
  kotae = 90909
elif n >= 10000:
  kotae = 909 + (n - 10000 + 1)
elif n >= 1000:
  kotae = 909
elif n >= 100:
  kotae = 9 + (n- 100 +1)
elif n >= 10:
  kotae = 9
else:
  kotae = n
print(kotae)
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
        self.total = n
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self, x, y):
        return self.find[x] == self.find[y]
    def unite(self, x, y):
        if self.same_check(x, y):
            return
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.total -= 1
        else:
            self.par[y] = x
            self.total -= 1
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
n,m = map(int, input().split())
union = UnionFind(n)
for i in range(m):
    x,y,z = map(int, input().split())
    union.unite(x-1, y-1)
print(union.total)


Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
        self.total = n
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    def unite(self, x, y):
        if self.same_check(x, y):
            return
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.total -= 1
        else:
            self.par[y] = x
            self.total -= 1
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
n,m = map(int, input().split())
union = UnionFind(n)
for i in range(m):
    x,y,z = map(int, input().split())
    union.unite(x-1, y-1)
print(union.total)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

cnt = 0
for i in range(N):
    flag = False
    for j in range(0, i):
        if P[i] <= P[j]:
            #print(":", i, P[i], P[j])
            continue
        else:
            flag = True
            break
    if flag:
        continue
    else:
        #print("::", i, P[i])
        cnt += 1

print(cnt)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))

cnt = 0
last = float('inf')
for i in range(N):
    if P[i] < last:
        cnt += 1
        last = P[i] 

print(cnt)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b = map(iint, input().split())

x = a+b
if x%2 == 1:
  print('IMPOSSIBLE')
else:
  print('{}',x//2)

Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
 
x = a+b
if x%2 == 1:
  print('IMPOSSIBLE')
else:
  print('{}'.format(x//2))
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a%b)

def lcm(a,b):
  return (a*b)//gcd(a,b)
 
n = int(input())
arr = [int(x) for x in input().split()] 
mod=1000000007
lc = arr[0]
for i in range(1, len(arr)): 
  	lc = lcm(lc,arr[i])
ans=0
for i in range(n):
    ans=ans+lc//arr[i]
    ans%=mod
print(int(ans))

Fixed submission:
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a%b)

def lcm(a,b):
  return (a*b)//gcd(a,b)
 
n = int(input())
arr = [int(x) for x in input().split()] 
mod=1000000007
lc = arr[0]
for i in range(1, len(arr)): 
  	lc = lcm(lc,arr[i])
ans=0
for i in range(n):
    ans=ans+lc//arr[i]
print(int(ans)%mod)
Buggy python submission (verdict: Runtime Error):
h,a = map(int,input().split())
print(h//a + (h%a>0)

Fixed submission:
h,a = map(int,input().split())
print(h//a + (h%a>0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append((x,y))

d = dict()
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        x1,y1 = l[i]
        x2,y2 = l[j]
        if d.__contains__((x2-x1,y2-y1)):
            d[(x2-x1,y2-y1)] += 1
        else:
            d[(x2-x1,y2-y1)] = 1
maxV = max(list(d.values()))

print(n-maxV)


Fixed submission:
n = int(input())
l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append((x,y))

d = dict()
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        x1,y1 = l[i]
        x2,y2 = l[j]
        if d.__contains__((x2-x1,y2-y1)):
            d[(x2-x1,y2-y1)] += 1
        else:
            d[(x2-x1,y2-y1)] = 1

ll = list(d.values())
if ll == []:
    maxV = 0
else:
    maxV = max(list(d.values()))

print(n-maxV)
Buggy python submission (verdict: Runtime Error):
n = input()
l = list(map(int,input().split()))
diff = []
for t in range(1,n):
  diff.append(abs(sum(l[:t])-sum(l[t:]))))
print(min(diff))

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
diff = []
for t in range(1,n):
    diff.append(abs(sum(l[:t])-sum(l[t:])))
print(min(diff))
Buggy python submission (verdict: Runtime Error):
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
cnt =0
for i in range(n):
  a=list(map(int,input().split()))
  s=C+sum([b[j]*a[j] for j in range(m)])
  if s>0:
    cnt +=1
print(cnt)

Fixed submission:
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
cnt =0
for i in range(n):
  a=list(map(int,input().split()))
  s=c+sum([b[j]*a[j] for j in range(m)])
  if s>0:
    cnt +=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=0
d=0
res=0
i=0
while a>0 or b>0:
  r=1<<i
  c<<=1
  d<<=1
  c |= a&1
  d |= b&1
  if c<r:
    if d>=r:
      res |= ((d-r+1)%2)<<i
    else:
      res |= 0
  else:
    if d<r:
      res |= ((r<<1-c)%2)<<i
    else:
      res |= (((d-c+1)%r)%2)<<i
  a>>=1
  b>>=1
  i+=1
  
print(res)

Fixed submission:
a,b = map(int,input().split())

def f(x):
    i = 0
    res = 0 
    while (x>>i)>0:
        r = 1<<i
        if i == 0:
            if x%4 == 1 or x%4 == 2:
                res |= 1
            else:
                res |= 0
        else:
            d = x % (r<<1)
            if d >= r:
                res |= ((d-1)%2)<<i
        i += 1      
    return res

print(f(b)^f(a)^a)
Buggy python submission (verdict: Runtime Error):
n = map(int,input.split())
l = [int(x) for x in input().split()]

s = sum(l)
res = "Yes"
for x in l:
  if (2*x>=s):
    res = "No"
print(res)
    

Fixed submission:
n = map(int,input().split())
l = [int(x) for x in input().split()]

s = sum(l)
res = "Yes"
for x in l:
  if (2*x>=s):
    res = "No"
print(res)

Buggy python submission (verdict: Runtime Error):
n = map(int,input.split())
l = [int(x) for x in input.split()]

s = sum(l)

for x in l:
  if (2*x>=s):
    print("No")
    exit(0)
print("Yes")
    

Fixed submission:
n = map(int,input().split())
l = [int(x) for x in input().split()]

s = sum(l)
res = "Yes"
for x in l:
  if (2*x>=s):
    res = "No"
print(res)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
l = [int(x) for x in input().split()]

l.sort()

gap = [l[i]-l[i-1] for i in range(1,len(l))]

gap = gap.sort()

print(sum(gap[:-(m-1)]))

Fixed submission:
n,m = map(int,input().split())
l = [int(x) for x in input().split()]

if(n>=m):
  print('0')
  exit(0)
l.sort()
 
gap = [l[i+1]-l[i] for i in range(m-1)]
 
gap.sort()

print(sum(gap[:m-n]))
Buggy python submission (verdict: Runtime Error):
def takeSecond(elem):
    return elem[1]

n,k = map(int,input().split())

sushi = [list(map(int,input().split())) for i in range(n)]

sushi.sort(key=takeSecond,reverse=True)

selected = sushi[:k]
kindset = set([item[0] for item in selected])

startKindNum = len(kindset)

score = startKindNum*startKindNum + sum([item[1] for item in selected])
maxscore = score
front_pointer = k - 1
pointer = k
for i in range(startKindNum+1,min([k+1,n+1])):
    #remove the smallest one that does not decrease kind
    for p in range(front_pointer,-1,-1):
        item = selected[p]
        flag = False
        for idx in range(p):
            if(selected[idx][0]==item[0]):
                score -= item[1]
                selected.remove(item)
                front_pointer = p - 1
                flag = True
                break
        if(flag):
            break

    #add the largest one that add kind
    for j in range(pointer,n):
        if(sushi[j][0] not in kindset):
            selected.append(sushi[j])
            kindset.add(sushi[j][0])
            k += 1
            pointer = j + 1            
            score += 2*startKindNum + 1 + sushi[j][1]
            if(score>maxscore):
                maxscore = score
            startKindNum += 1
            break
print(maxscore)


Fixed submission:
a,b,c = map(int,input().split())

print(a*b//2)

Buggy python submission (verdict: Runtime Error):
a,b,c = map(input().split())

print(a*b//2)

Fixed submission:
a,b,c = map(int,input().split())

print(a*b//2)
Buggy python submission (verdict: Runtime Error):
s = input()
minvalue = 1000
for i in range(n-2):
  x = int(s[i:i+3])
  minvalue = min(minvalue,abs(x-753))
print(minvalue)

Fixed submission:
s = input()
minvalue = 1000
for i in range(len(s)-2):
  x = int(s[i:i+3])
  minvalue = min(minvalue,abs(x-753))
print(minvalue)
Buggy python submission (verdict: Runtime Error):
100000 1000000000

Fixed submission:
import math
n,m = map(int, input().split())
factors = []
comp = m//n
for i in range(int(math.sqrt(m)),0,-1):
    if(m%i==0):
        factors.insert(0,i)
        factors.append(m//i)
for item in factors[::-1]:
    if (item <= comp):
        print(item)
        exit(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())

for i in range(m,0,-1):
    if (m%i==0 and n<=m//i):
       print(i)
       exit(0) 


Fixed submission:
import math
n,m = map(int, input().split())
factors = []
comp = m//n
for i in range(int(math.sqrt(m)),0,-1):
    if(m%i==0):
        factors.insert(0,i)
        factors.append(m//i)
for item in factors[::-1]:
    if (item <= comp):
        print(item)
        exit(0)
Buggy python submission (verdict: Runtime Error):
6
105 119 105 119 105 119

Fixed submission:
n = int(input())

data = list(map(int,input().split()))

odd = [data[i] for i in range(0,n,2)]
even = [data[i] for i in range(1,n,2)]

odd_dict = dict({})
even_dict = dict({})

for i in range(n//2):
    if odd_dict.__contains__(odd[i]):
        odd_dict[odd[i]]+=1
    else:
        odd_dict[odd[i]] = 1
    if even_dict.__contains__(even[i]):
        even_dict[even[i]]+=1
    else:
        even_dict[even[i]] = 1

odd = sorted(odd_dict.items(), key=lambda d:d[1],reverse=True)
even = sorted(even_dict.items(), key=lambda d:d[1],reverse=True)

odd.append((0,0))
even.append((0,0))
if odd[0][0] == even[0][0]:
    print(min(n-odd[0][1]-even[1][1],n-odd[1][1]-even[0][1]))
else:
    print(n-odd[0][1]-even[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
str1 = input()
str2 = input()

n = len(str1)
res = "Yes"
for i in range(n):
    for j in range(i+1,n):
        if str1[i] == str1[j]:
            if str2[i] != str2[j]:
                res = "No"
                break
        if str2[i] == str2[j]:
            if str1[i] != str1[j]:
                res = "No"
                break
    if res == "No":
        print(res)
        exit(0)

print(res)


Fixed submission:
str1 = input()
str2 = input()

n = len(str1)
d1 = dict()
d2 = dict()
for i in range(26):
    d1[chr(97+i)] = ''
    d2[chr(97+i)] = ''
res = "Yes"
for i in range(n):
    if d1[str1[i]] != '' and d1[str1[i]]!=str2[i]:
        res = "No"
        break
    if d2[str2[i]] != '' and d2[str2[i]]!=str1[i]:
        res = "No"
        break
    if d1[str1[i]] == '':
        d1[str1[i]] = str2[i]
    if d2[str2[i]] == '':
        d2[str2[i]] = str1[i]
print(res)

Buggy python submission (verdict: Runtime Error):
str1 = list(input())
str2 = list(input())

n = len(str1)

str1 = ''.join(str1)
str2 = ''.join(str2) 
if (str1 == str2):
    print("No")
    exit(0)
for i in range(n):
    if str1[i]==str2[i]:
        continue
    for j in range(i+1,n):
        if str1[j]==str1[i]:
            tmp = str2[i]
            str2[i] = str1[j]
            str1[j] = tmp
            break
        elif str2[j] == str1[i]:
            tmp = str2[j]
            str2[j] = str1[i+1]
            str1[i+1] = str2[i]
            str2[i] = tmp
            break
str1 = ''.join(str1)
str2 = ''.join(str2) 

if(str1 == str2):
    print("Yes")
else:
    print("No")


Fixed submission:
str1 = input()
str2 = input()

n = len(str1)
d1 = dict()
d2 = dict()
for i in range(26):
    d1[chr(97+i)] = ''
    d2[chr(97+i)] = ''
res = "Yes"
for i in range(n):
    if d1[str1[i]] != '' and d1[str1[i]]!=str2[i]:
        res = "No"
        break
    if d2[str2[i]] != '' and d2[str2[i]]!=str1[i]:
        res = "No"
        break
    if d1[str1[i]] == '':
        d1[str1[i]] = str2[i]
    if d2[str2[i]] == '':
        d2[str2[i]] = str1[i]
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import math
def comb(x,y):
    f = 1
    for i in range(y):
        f *= (x-i)
        f //= (i+1)

    return f

n,m = map(int,input().split())

cnt = [0]
for i in range(2,m+1):
    while m!=i:
        if m%i==0:
            m //=i
            cnt[-1]+=1
        else:
            cnt.append(0)
            break
    if m==i:
        cnt[-1]+=1
        break
cnt = [item for item in cnt if cnt != 0]


res = 1
r = 10**9 +7
for item in cnt:
    res = (res* comb(item+n-1,item))%r

print(res%r)


Fixed submission:
import math
def comb(x,y):
    f = 1
    for i in range(y):
        f *= (x-i)
        f //= (i+1)

    return f

n,m = map(int,input().split())

i = 2
cnt = []
while i*i<=m:
    c = 0
    while m%i == 0:
        m //= i
        c += 1
    if c>0:
        cnt.append(c)
    i+=1
if m>1:
    cnt.append(1)
        

res = 1
r = 10**9 +7
for item in cnt:
    res = (res* comb(item+n-1,item))%r

print(res%r)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def comb(x,y):
    f = 1
    for i in range(y):
        f *= (x-i)
        f //= (i+1)

    return f

n,m = map(int,input().split())

cnt = [0]
for i in range(2,m+1):
    while m!=i:
        if m%i==0:
            m //=i
            cnt[-1]+=1
        else:
            cnt.append(0)
            break
    if m==i:
        cnt[-1]+=1
        break
cnt = [item for item in cnt if cnt != 0]


res = 1

for item in cnt:
    res *= comb(item+n-1,item)

print(res%(10**9+7))


Fixed submission:
import math
def comb(x,y):
    f = 1
    for i in range(y):
        f *= (x-i)
        f //= (i+1)

    return f

n,m = map(int,input().split())

i = 2
cnt = []
while i*i<=m:
    c = 0
    while m%i == 0:
        m //= i
        c += 1
    if c>0:
        cnt.append(c)
    i+=1
if m>1:
    cnt.append(1)
        

res = 1
r = 10**9 +7
for item in cnt:
    res = (res* comb(item+n-1,item))%r

print(res%r)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def comb(x,y):
    f = 1
    for i in range(y):
        f *= (x-i)
        f //= (i+1)

    return f

n,m = map(int,input().split())

cnt = [0]
for i in range(2,m+1):
    while m!=i:
        if m%i==0:
            m //=i
            cnt[-1]+=1
        else:
            cnt.append(0)
            break
    if m==i:
        cnt[-1]+=1
        break
cnt = [item for item in cnt if cnt != 0]


res = 1

for item in cnt:
    res *= comb(item+n-1,n-1)

print(res%(10**9+7))


Fixed submission:
import math
def comb(x,y):
    f = 1
    for i in range(y):
        f *= (x-i)
        f //= (i+1)

    return f

n,m = map(int,input().split())

i = 2
cnt = []
while i*i<=m:
    c = 0
    while m%i == 0:
        m //= i
        c += 1
    if c>0:
        cnt.append(c)
    i+=1
if m>1:
    cnt.append(1)
        

res = 1
r = 10**9 +7
for item in cnt:
    res = (res* comb(item+n-1,item))%r

print(res%r)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,q = map(int,input().split())

table = []
res = []
for i in range(n+1):
    table.append([0]*(i+1))
    res.append([0]*(i+1))
for i in range(m):
    a,b = map(int,input().split())
    table[b][a] += 1

for begin in range(1,n+1):
    s = 0
    for ending in range(begin,n+1):
        for k in range(begin,ending+1):
            s += table[ending][k]
        res[ending][begin] = s
for _ in range(q):
    start,end = map(int,input().split())
    print(res[end][start])


Fixed submission:
n,m,q = map(int,input().split())

table = []
for i in range(n+1):
    table.append([0]*(n+1))
for i in range(m):
    a,b = map(int,input().split())
    table[b][a] += 1

#2...n
for i in range(2,n+1):

    #1...n-1
    for j in range(1,n+2-i):
        table[i+j-1][j] += table[i+j-1][j+1]+table[i+j-2][j]-table[i+j-2][j+1]

for _ in range(q):
    start,end = map(int,input().split())
    print(table[end][start])

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q = map(int,input().split())

table = []

for i in range(n+1):
    table.append([0]*(i+1))

for i in range(m):
    a,b = map(int,input().split())
    table[b][a] += 1

for _ in range(q):
    start,end = map(int,input().split())
    res = 0
    for i in range(start,end+1):
        res += sum(table[i][start:])
    print(res)


Fixed submission:
n,m,q = map(int,input().split())

table = []
for i in range(n+1):
    table.append([0]*(n+1))
for i in range(m):
    a,b = map(int,input().split())
    table[b][a] += 1

#2...n
for i in range(2,n+1):

    #1...n-1
    for j in range(1,n+2-i):
        table[i+j-1][j] += table[i+j-1][j+1]+table[i+j-2][j]-table[i+j-2][j+1]

for _ in range(q):
    start,end = map(int,input().split())
    print(table[end][start])