[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]:
let a, b, c, d, r, p, t, and ans be integers, let h be an integer array of length 150
let f be a boolen array of length 30
define the main function
    read in a, b, c, and d
    set r to a + b
    iterate for a times, set h[i] to i
    iterate for b times, set h[a+i} to a
    iterate for b times, set h[r+1] to i
    iterate for a times, set h[r + b + i] to a + i
    iterate for b times, set h[r + a + i] to h{r + a]
    if b is greater than or equal to a
        for i = r + a to r + r, increment h[i]
    set r to 2 * r
    d is equal to the min of d and c + r
    for i = c to d times
        set t to h[(i - 1) % r + 1]
        if f[t] is not true, increment p
        set f[t] to true
    end of the block
    set ans to p
    set p to 0
    change all values in f to 0
    if a - b > 1 and d - c + 1 > a + b
        iterate for b times, set h[a + j] to h[b + 1]
        iterate for a times
            let k be an integer
            while true
                increment k
                let flag be a boolean, set flag to true
                for i = b + 1 to a + b + j- 1
                    if h[i] is equal to k, set flag to false
                if flag is true, break out of the loop
            end of the block
            set h[a + b + j] to k
        end of the block
        iterate for b times, set h[a + a + b +j] to h[a + b + b+ 1]
    end of the block
    for i = c iterate until i = d
        set t to h[(i - 1) % r + 1]
        if f[t] is not true, increment p
        set f[t] to true
    end of the block
    print the min of p and ans
end of the block

[CODE]:

int a, b, c, d, r, h[150], p, t, ans;
bool f[30];
int main() {
    cin >> a >> b >> c >> d;
    r = a + b;
    for (int i = 1; i <= a; i++) h[i] = i;
    for (int i = 1; i <= b; i++) h[a + i] = a;
    for (int i = 1; i <= b; i++) h[r + i] = i;
    for (int i = 1; i <= a; i++) h[r + b + i] = a + i;
    for (int i = 1; i <= b; i++) h[r + a + i] = h[r + a];
    if (b >= a)
        for (int i = r + a; i <= r + r; i++) h[i]++;
    r *= 2;
    d = min(d, c + r);
    for (int i = c; i <= d; i++) {
        t = h[(i - 1) % r + 1];
        if (!f[t]) p++;
        f[t] = true;
    }
    ans = p;
    p = 0;
    memset(f, 0, sizeof(f));
    if (a - b > 1 && d - c + 1 > a + b) {
        for (int j = 1; j <= b; j++) h[a + j] = h[b + 1];
        for (int j = 1; j <= a; j++) {
            int k = 0;
            while (1) {
                k++;
                bool flag = true;
                for (int i = b + 1; i < a + b + j; i++)
                    if (h[i] == k) flag = false;
                if (flag) break;
            }
            h[a + b + j] = k;
        }
        for (int j = 1; j <= b; j++) h[a + a + b + j] = h[a + b + b + 1];
    }
    for (int i = c; i <= d; i++) {
        t = h[(i - 1) % r + 1];
        if (!f[t]) p++;
        f[t] = true;
    }
    cout << min(p, ans) << endl;
}