Problem C: [NOIP2017day2]列队

Time Limit: 2 Sec Memory Limit: 512 MB

Description

image.png

Sample Input

2 2 3 
1 1 
2 2 
1 2 

Sample Output

1
1
4

HINT

image.png