Welcome to ZOJ
101 - ZOJ Monthly, December 2010 - H
Doraemon's Sweet Bullet

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Doraemon likes to shoot his enemies with sweet bullets.

n "enemies" stand in a line, each with a life value li (the index i increases from left to right side and starts from 1). Each time Doraemon shoots a sweet bullet from the right side. The ith bullet has a "critical range" ki. That is to say, it attacks the first enemy from right side whose life value is equal to or greater than ki. The life value of the attacked enemy will decrease to 1 immediately.

However, Doraemon finds a terrible fact that after an enemy is attacked, it will distribute the sweets to his friends and his friends' life value will increase by 1. For the ith enemy, his friends are in a consecutive range from the aith enemy to the bith. Note that an enemy may be the friend of himself so that after being attacked his life value will be 2.

What's more, if a bullet can't find a target--there doesn't exist an enemy with life greater or equal than ki, all enemies' life will increase by 1.

Now Doraemon wants to know after m bullets were shot, what the maximum life value in all enemies is.


The input contains multiple test cases.

Each test case begins with a line containing a single integer n (1 ≤ n ≤ 100000) indicating the number of enemies.

The following n lines describes enemies, one enemy each line. Each line contains three integers, the initial life value li (1 ≤ li ≤ 10000) and his range of friends ai bi (1 ≤ aibi≤ n) - that is, enemies with index from ai to bi (inclusive) are all his friends.

The following line contains an integer m (1 ≤ m ≤ 100000) indicating the number of bullets Doraemon has shot. The last m lines follows, each with a single integer ki (1 ≤ ki ≤ 10000) describing the bullet's "critical range".

Different cases are separated by a blank line.

Process to the end of input.


For each test case, output the maximum life value after shooting in a single line.

Sample Input

3 1 2
4 1 3
5 1 1

Sample Output



Doraemon suggests that you should use scanf to read data.

Author: WAN, Xinyi
Contest: ZOJ Monthly, December 2010
Submit    Status