[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
declare long longs a, b, l, r, ans = 100, T
declare Cal with character c as argument, returning long long
    declare count = 0 as long long
    declare character array s size 100
    for i = 0 to a exclusive, let s[i] be 'a' + i
    for i = a to a + b exclusive, let s[i] be c
    declare integer array have size 26
    set bytes from have to 26 * size of integer to value 0
    for i = a + b - 1 to b inclusive, decrementing i, let have[s[i]-'a'] be 1
    declare long longs i = a + b, j = 0
    while i is less than 2 * a + b
        while ( have[j] ), increment j
        let s[i] be j + 'a'
        increment i
        increment j
    end of the block
    for i = 2 * a + b to T exclusive, let s[i] be s[i-1]
    set bytes from have to 26 * size of integer to value 0
    if l is less than or equal to r
        for i = l to r inclusive
            if not have[s[i] - 'a']
                increment count
                let have[s[i] - 'a'] be 1
            end of the block
    else
        for i = 0 to r inclusive
            if not have[s[i]-'a']
                increment count
                let have[s[i]-'a'] be 1
            end of the block
        for i = l to T exclusive
            if not have[s[i]-'a']
                increment count
                let have[s[i]-'a'] be 1
            end of the block
    end of the block
    return count from function
end of the block
define the main function
    declare long long t
    read a and b and l and r
    decrement l
    decrement r
    let T be 2 * ( a + b )
    if a is greater than b + 1
        let t be 2 * a - b
    else
        let t be a + 1
    if r - l is greater than or equal to T
        let ans be t
    else
        let r be r % T
        let l be l % T
        for i = 0 to a exclusive, let ans be minimum of ( result of run Cal with 'a' + i as arguments and ans )
    end of the block
    print ans and newline
    return to indicate successful execution
end of the block

[CODE]:

long long a, b, l, r, ans = 100, T;
long long Cal(char c) {
    long long count = 0;
    char s[100];
    for (int i = 0; i < a; i++) s[i] = 'a' + i;
    for (int i = a; i < a + b; i++) s[i] = c;
    int have[26];
    memset(have, 0, 26 * sizeof(int));
    for (long long i = a + b - 1; i >= b; i--) have[s[i] - 'a'] = 1;
    long long i = a + b, j = 0;
    while (i < 2 * a + b) {
        while (have[j]) j++;
        s[i] = j + 'a';
        i++;
        j++;
    }
    for (int i = 2 * a + b; i < T; i++) s[i] = s[i - 1];
    memset(have, 0, 26 * sizeof(int));
    if (l <= r) {
        for (long long i = l; i <= r; i++)
            if (!have[s[i] - 'a']) {
                count++;
                have[s[i] - 'a'] = 1;
            }
    } else {
        for (long long i = 0; i <= r; i++)
            if (!have[s[i] - 'a']) {
                count++;
                have[s[i] - 'a'] = 1;
            }
        for (long long i = l; i < T; i++)
            if (!have[s[i] - 'a']) {
                count++;
                have[s[i] - 'a'] = 1;
            }
    }
    return count;
}
int main() {
    long long t;
    cin >> a >> b >> l >> r;
    l--;
    r--;
    T = 2 * (a + b);
    if (a > b + 1)
        t = 2 * a - b;
    else
        t = a + 1;
    if (r - l >= T)
        ans = t;
    else {
        r %= T;
        l %= T;
        for (int i = 0; i < a; i++) ans = min(Cal('a' + i), ans);
    }
    cout << ans << endl;
    return 0;
}