cho.sh
Notes
Loading...

Intelligent Train

Time limit

1s

Memory limit

128 MB

Problem

An intelligent train runs through four stations in order, from station 1 (the departure station) to station 4 (the terminal station). At each station, all passengers getting off leave the train before new passengers board.

Given the number of passengers who get off and board at each station, find the maximum number of passengers that were on the train at any point during the trip.

The train satisfies the following conditions.

  1. The train visits the stations in order from station 1 to station 4.
  2. No passengers get off at station 1, and no passengers board at station 4.
  3. At no station do more passengers get off than are currently on the train.
  4. The train capacity is 10,000 passengers, and the capacity is never exceeded.

Input

Four lines are given. On the i-th line, two integers are given separated by a space: the number of passengers getting off at station i and the number of passengers boarding at station i.

Output

Print the maximum number of passengers that were on the train during the trip.