[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]:
a, b, l, r, ans, T = int
s = char array of size 200
vis = bool array of size 27
in function dfs taking char cp and returning int
    count = int with count = 0
    for i = 0 to a set s[i] to 'a' + i
    for i = a to a + b set s[i] to cp
    set all values of vis to false
    for i = b to a + b set vis[s[i] - 'a'] to true
    sta, ed = int with sta = a + b and ed = 0
    loop while sta < 2 * a + b
        loop while vis[ed] increment ed
        set s[sta] to ed + 'a'
        increment both sta and ed
    end of the block
    for i = 2 * a + b to T set s[i] to s[i - 1]
    set all values of vis to false
    if l <= r
        for i = l to r inclusive
            if not vis[s[i] - 'a'] increment count then set vis[s[i] - 'a'] to true
        end of the block
    else
        for i = 0 to r inclusive
            if not vis[s[i] - 'a'] increment count then set vis[s[i] - 'a'] to true
        end of the block
        for i = l to T
            if not vis[s[i] - 'a'] increment count then set vis[s[i] - 'a'] to true
        end of the block
    end of the block
    return count
end of the block
define the main function
    read a then b then l then r
    decrement both l and r
    if a <= b
        set ans to a + 1
    else
        set ans to 2 * a - b
    set T to 2 * (a + b)
    if r - l >= T
        noop
    else
        set r to r mod T then set l to l mod T
        for i = 0 to a set ans to min of dfs of ('a' + i), ans
    end of the block
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int a, b, l, r, ans, T;
char s[200];
bool vis[27];
int dfs(char cp) {
    int count = 0;
    for (int i = 0; i < a; i++) s[i] = ('a' + i);
    for (int i = a; i < a + b; i++) s[i] = cp;
    memset(vis, false, sizeof(vis));
    for (int i = b; i < a + b; i++) vis[s[i] - 'a'] = true;
    int sta = a + b, ed = 0;
    while (sta < 2 * a + b) {
        while (vis[ed]) ed++;
        s[sta] = ed + 'a';
        sta++, ed++;
    }
    for (int i = 2 * a + b; i < T; i++) s[i] = s[i - 1];
    memset(vis, false, sizeof(vis));
    if (l <= r) {
        for (int i = l; i <= r; i++) {
            if (!vis[s[i] - 'a']) { count++, vis[s[i] - 'a'] = true; }
        }
    } else {
        for (int i = 0; i <= r; i++) {
            if (!vis[s[i] - 'a']) { count++, vis[s[i] - 'a'] = true; }
        }
        for (int i = l; i < T; i++) {
            if (!vis[s[i] - 'a']) { count++, vis[s[i] - 'a'] = true; }
        }
    }
    return count;
}
int main() {
    cin >> a >> b >> l >> r;
    l--, r--;
    if (a <= b)
        ans = a + 1;
    else
        ans = 2 * a - b;
    T = 2 * (a + b);
    if (r - l >= T)
        ;
    else {
        r %= T, l %= T;
        for (int i = 0; i < a; i++) { ans = min(dfs('a' + i), ans); }
    }
    cout << ans << endl;
    return 0;
}