Buggy python submission (verdict: Runtime Error):
# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1], reverse = True)
# 辞書をソートするとリストが返ってくることに注意

a = [0 for _ in range(N)]

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        a[train_query[j][1][0]] = 1
    else: # クエリ
        ans = sum(a[train_query[j][1][0]:train_query[j][1][1]])
        print(ans)


Fixed submission:
# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1][1])
# 辞書をソートするとリストが返ってくることに注意

StartPoints = [0 for _ in range(N)] # 対象区間の開始位置
ans = [0 for _ in range(Q)] # 各クエリに対する答え

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        StartPoints[train_query[j][1][0] - 1] += 1
    else: # クエリ
        ans[train_query[j][0] - M] = sum(StartPoints[(train_query[j][1][0] - 1):(train_query[j][1][1])])

for i in range(Q):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
# input
N, M, Q = map(int, input().split())
Trains = [list(map(int, input().split())) for _ in range(M)]
Trains = sorted(Trains)
Questions = {}
for i in range(Q):
    Questions[i] = list(map(int, input().split()))

Questions = sorted(Questions.items(), key = lambda x: x[1])

Ans = [0 for _ in range(Q)]
left = 0

for i in range(Q):
    num = Questions[i][0]
    p = Questions[i][1][0]
    q = Questions[i][1][1]
    for j in range(left, M):
        if p <= Trains[j][0]:
            left = j
            for k in range(j, M):
                if q >= Trains[k][1]:
                    Ans[num] += 1
            break

for i in range(Q):
    print(Ans[i])


Fixed submission:
# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1][1])
# 辞書をソートするとリストが返ってくることに注意

StartPoints = [0 for _ in range(N)] # 対象区間の開始位置
ans = [0 for _ in range(Q)] # 各クエリに対する答え

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        StartPoints[train_query[j][1][0] - 1] += 1
    else: # クエリ
        ans[train_query[j][0] - M] = sum(StartPoints[(train_query[j][1][0] - 1):(train_query[j][1][1])])

for i in range(Q):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
# input
N, M, Q = map(int, input().split())
Trains = [list(map(int, input().split())) for _ in range(M)]
Trains = sorted(Trains)

for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for j in range(M):
        if p <= Trains[j][0]:
            for k in range(j, M):
                if q >= Trains[k][1]:
                    ans += 1
            break
    print(ans)



Fixed submission:
# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1][1])
# 辞書をソートするとリストが返ってくることに注意

StartPoints = [0 for _ in range(N)] # 対象区間の開始位置
ans = [0 for _ in range(Q)] # 各クエリに対する答え

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        StartPoints[train_query[j][1][0] - 1] += 1
    else: # クエリ
        ans[train_query[j][0] - M] = sum(StartPoints[(train_query[j][1][0] - 1):(train_query[j][1][1])])

for i in range(Q):
    print(ans[i])