QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 10

#10637. War [A]

Estadísticas

Jaś and Staś are playing the Byteotian War. At the beginning of the game, each player receives a deck of $n$ cards. Each card has a number written on it. The game is played in turns. During each turn, each player draws two cards from the top of their deck and decides which one to discard and which one to pass to the opponent (in each move, one card must be discarded and the other must be passed to the opponent). The opponent places the received card at the bottom of their deck.

The game ends when both players have one card left. If the number on Jaś's card is $j$ and the number on Staś's card is $s$, then Jaś receives $j-s$ points, and Staś receives $s-j$ points.

Assume that the players play optimally (they maximize their own score calculated according to the rule above). How many points will Jaś score?

Input

The first line of input contains a single integer $n$ ($1 \le n \le 1\,000\,000$) representing the number of cards each player received. The second line contains a sequence of $n$ integers $a_{i}$ ($1 \le a_{i} \le 1\,000\,000$), which describes the cards in Jaś's deck, starting from the card at the top of the deck. The third line describes the cards in Staś's deck, in an analogous format.

Output

Your program should output a single integer - the number of points Jaś will score, assuming optimal play from both players.

Examples

Input 1

4
5 3 7 2
2 8 3 4

Output 1

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.