Codeforces Round 421 (Div. 1)
A
Mister B and Boring Game
Codeforces
未评级
原题
←B →
翻译中…

Unfortunately, a mistake was found in the proof of the author's solution to this problem. Currently, we don't know the absolutely correct solution. However, you can solve this task, but if your solution passes all the tests, it is not guaranteed to be correct. If your solution has passed all the tests, and you are sure that it is correct, you can write to one of the contest authors about it.

翻译中…

Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens.

翻译中…

All characters in this game are lowercase English letters. There are two players: Mister B and his competitor.

翻译中…

Initially the players have a string $*s*$ consisting of the first $*a*$ English letters in alphabetical order (for example, if $*a* = 5$, then $*s*$ equals to "abcde").

翻译中…

The players take turns appending letters to string $*s*$. Mister B moves first.

翻译中…

Mister B must append exactly $*b*$ letters on each his move. He can arbitrary choose these letters. His opponent adds exactly $*a*$ letters on each move.

翻译中…

Mister B quickly understood that his opponent was just a computer that used a simple algorithm. The computer on each turn considers the suffix of string $*s*$ of length $*a*$ and generates a string $*t*$ of length $*a*$ such that all letters in the string $*t*$ are distinct and don't appear in the considered suffix. From multiple variants of $*t*$ lexicographically minimal is chosen (if $*a* = 4$ and the suffix is "bfdd", the computer chooses string $*t*$ equal to "aceg"). After that the chosen string $*t*$ is appended to the end of $*s*$.

翻译中…

Mister B soon found the game boring and came up with the following question: what can be the minimum possible number of different letters in string $*s*$ on the segment between positions $*l*$ and $*r*$, inclusive. Letters of string $*s*$ are numerated starting from $1$.

翻译中…

Input

翻译中…

First and only line contains four space-separated integers: $*a*$, $*b*$, $*l*$ and $*r*$ ($1 ≤ *a*, *b* ≤ 12$, $1 ≤ *l* ≤ *r* ≤ 10^{9}$) — the numbers of letters each player appends and the bounds of the segment.

翻译中…

Output

翻译中…

Print one integer — the minimum possible number of different letters in the segment from position $*l*$ to position $*r*$, inclusive, in string $*s*$.

翻译中…

Note

翻译中…

In the first sample test one of optimal strategies generate string $*s* =$"abababab...", that's why answer is $2$.

翻译中…

In the second sample test string $*s* =$"abcdbcaefg..." can be obtained, chosen segment will look like "bcdbc", that's why answer is $3$.

翻译中…

In the third sample test string $*s* =$"abczzzacad..." can be obtained, chosen, segment will look like "zzz", that's why answer is $1$.

翻译中…

样例

Input #1
1 1 1 8
Output #1
2
InputCopy OutputCopy
Input #2
4 2 2 6
Output #2
3
InputCopy OutputCopy
Input #3
3 7 4 6
Output #3
1
InputCopy OutputCopy
题目信息
题号
819A
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。