PrincetonPLI/LongProc huggingface dataset:
[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]:
gcd is a int function with int arguments a and b
    return a if b = 0, or gcd of b and a % b otherwise
end of the block
define the main function
    declare ints a, b, n, k and c with k = 0 and c = 2
    read a, b and n
    while n > 0
        if c is even
            set n to n - gcd of a and n
            change k to 0
            assign 1 to c
        else
            change n to n - gcd of b and n
            set k to 1
            change c to 2
        end of the block
    end of the block
    print k
end of the block

[CODE]:

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main() {
    int a, b, n, k = 0, c = 2;
    cin >> a >> b >> n;
    while (n > 0) {
        if (c % 2 == 0) {
            n = n - gcd(a, n);
            k = 0;
            c = 1;
        } else {
            n = n - gcd(b, n);
            k = 1;
            c = 2;
        }
    }
    cout << k << endl;
}
[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]:
create integer 2d array ch with 2000 by 2 elements
define the main function
    create integer n
    read n
    declare integer now = 1
    for integer i = 1 to n inclusive, read ch[i][0] and ch[i][1]
    for i = 1, increment i in a loop
        if i >= ch[now][0] && (i - ch[now][0]) % ch[now][1] = 0, increment num
        if now is greater than n
            print i
            return to indicate successful execution
        end of the block
    end of the block
end of the block

[CODE]:

int ch[2000][2];
int main() {
    int n;
    cin >> n;
    int now = 1;
    for (int i = 1; i <= n; i++) cin >> ch[i][0] >> ch[i][1];
    for (int i = 1; i; i++) {
        if (i >= ch[now][0] && (i - ch[now][0]) % ch[now][1] == 0) now++;
        if (now > n) {
            cout << i << endl;
            return 0;
        }
    }
}
[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]:
define the main function
    declare integers N, sum = 0
    read N
    declare integer pointer H = new integer array size 100
    declare integer pointer A = new integer array size 100
    for i = 0 to N exclusive
        read H[i]
        read A[i]
    end of the block
    for i = 0 to N exclusive
        for j = 0 to N exclusive
            if H[i] is A[j], increment sum
        end of the block
    end of the block
    print sum and newline
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int N, sum = 0;
    cin >> N;
    int *H = new int[100];
    int *A = new int[100];
    for (int i = 0; i < N; i++) {
        cin >> H[i];
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (H[i] == A[j]) sum++;
        }
    }
    cout << sum << endl;
    return 0;
}
[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]:
define the main function
    create integer r,c, row=array of 0 of length 11, col = array of 0 of length 11
    Create string s
    Read r and c
    for (i=0 to r(exclusive))
        read s
        for (j=0 to c(exclusive))
            if(s[j] is 'S') execute
                row[i]=1
                col[j]=1
            end of the block
        end of the block
    end of the block
    Create integer cakes=0
    for (i=0 to r(exclusive))
        for (j=0 to c(exclusive))
            if(row[i]==0 or col[j]==0) increment cakes by 1
        end of the block
    end of the block
    print out cakes
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int r, c, row[11] = {0}, col[11] = {0};
    string s;
    cin >> r >> c;
    for (int i = 0; i < r; ++i) {
        cin >> s;
        for (int j = 0; j < c; ++j) {
            if (s[j] == 'S') {
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
    int cakes(0);
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            if (row[i] == 0 || col[j] == 0) { cakes += 1; }
        }
    }
    cout << cakes << endl;
    return 0;
}
[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 y, m and s be integer arrays with size 5
create integers ans, atkm, atky, mm, my, j, i and sum
define the main function
    for i = 1 to 3 inclusive, read y[i]
    for i = 1 to 3 inclusive, read m[i]
    for i = 1 to 3 inclusive, read s[i]
    ans = 999999
    for i = 0 to 200 inclusive
        for j = 0 to 200 inclusive
            sum = s[3] * j + s[2] * i
            atky = i + y[2] - m[3]
            atkm = m[2] - j - y[3]
            skip the rest of the loop if atky <= 0
            if atkm <= 0
                ans = min of ans and sum
                skip the rest of the loop
            end of the block
            if m[1] modulo atky != 0
                mm = m[1] / atky + 1
            else
                mm = m[1] / atky
            end of the block
            if y[1] modulo atkm != 0
                my = y[1] / atkm + 1
            else
                my = y[1] / atkm
            end of the block
            if my <= mm, increase sum by (mm * atkm + 1 - y[1]) * s[1]
            set ans to min of ans and sum
        end of the block
    end of the block
    print ans
end of the block

[CODE]:

int y[5], m[5], s[5];
int ans, atkm, atky, mm, my, j, i, sum;
int main() {
    for (i = 1; i <= 3; i++) { cin >> y[i]; }
    for (i = 1; i <= 3; i++) { cin >> m[i]; }
    for (i = 1; i <= 3; i++) { cin >> s[i]; }
    ans = 999999;
    for (i = 0; i <= 200; i++) {
        for (j = 0; j <= 200; j++) {
            sum = s[3] * j + s[2] * i;
            atky = i + y[2] - m[3];
            atkm = m[2] - j - y[3];
            if (atky <= 0) { continue; }
            if (atkm <= 0) {
                ans = min(ans, sum);
                continue;
            }
            if (m[1] % atky != 0) {
                mm = m[1] / atky + 1;
            } else {
                mm = m[1] / atky;
            }
            if (y[1] % atkm != 0) {
                my = y[1] / atkm + 1;
            } else {
                my = y[1] / atkm;
            }
            if (my <= mm) { sum += (mm * atkm + 1 - y[1]) * s[1]; }
            ans = min(ans, sum);
        }
    }
    cout << ans << endl;
}
[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]:
set max_n to 100 + 10
create long long a[max_n]
create int n
create long long ans and x, set ans to 1e3
define the main function
    read n
    for i=0 to n exclusive, read a[i]
    for i=1 to n - 1 exclusive
        for j=1 to n exclusive
            if j equal to i
                set x to max of a[j + 1] - a[j - 1] and x
            else if j - 1 different from i
                assign max of a[j] - a[j - 1] and x to x
        end of the block
        set ans to min of ans and x
        x=0
    end of the block
    print ans and a newline
    return to indicate successful execution
end of the block

[CODE]:

const int max_n = 100 + 10;
long long a[max_n];
short int n;
long long ans = 1e3, x;
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n - 1; i++) {
        for (int j = 1; j < n; j++) {
            if (j == i)
                x = max(a[j + 1] - a[j - 1], x);
            else if (j - 1 != i)
                x = max(a[j] - a[j - 1], x);
        }
        ans = min(ans, x);
        x = 0;
    }
    cout << ans << '\n';
    return 0;
}
[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]:
define the main function
    let y,b,r be integers
    read y,b and r
    for (int i is equal to r, i greater than or equal to 3, i--)
        if (i less than or equal to r and i - 1 less than or equal to b and i - 2 less than or equal to y)
            print 3 * i - 3 and newline
            stop
        end of the block
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int y, b, r;
    cin >> y >> b >> r;
    for (int i = r; i >= 3; i--) {
        if (i <= r && i - 1 <= b && i - 2 <= y) {
            cout << 3 * i - 3 << endl;
            break;
        }
    }
    return 0;
}
[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]:
define the main function
    define new integers n, k and m
    read user input to n, k and m
    declare an array of ints c with m + 2 elements and new variables i, j and r with r = m
    read m elements from the input to c starting from the index 1
    set c[m + 1] to n
    if m = 0, set r to n / k
    if m >= 1
        for i = 1 to m inclusive, increase r by (c[i] - c[i - 1] - 1) / k
        change r to r + (c[m + 1] - c[m]) / k
    end of the block
    print r
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, k, m;
    cin >> n >> k >> m;
    int c[m + 2] = {}, i, j, r = m;
    for (i = 1; i <= m; i++) cin >> c[i];
    c[m + 1] = n;
    if (m == 0) r = n / k;
    if (m >= 1) {
        for (i = 1; i <= m; i++) r += ((c[i] - c[i - 1] - 1) / k);
        r += ((c[m + 1] - c[m]) / k);
    }
    cout << r << endl;
    return 0;
}
[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]:
n, t, a, ans = integers with a = array of size 1000000
define the main function
    read n, t
    for i = 1 to n
        read a[i]
        t = t - 86400 - a[i]
        if (t <= 0 and not ans), ans = i
    end of the block
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int n, t, a[1000000], ans;
int main() {
    cin >> n >> t;
    for (register int i = 1; i <= n; i++) {
        cin >> a[i];
        t -= 86400 - a[i];
        if (t <= 0 && !ans) ans = i;
    }
    cout << ans << endl;
    return 0;
}
[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 count taking long long n and returning long long
    make long long ints k = n and s = 0
    while k is greater than 0
        set s to s + k % 10
        divide k by 10
    end of the block
    return s
end of the block
declare si taking in long long n and returning long long
    make long long integers k = n and s = 0
    while k is greater than 0
        increment s
        set k to k / 10
    end of the block
    return s
end of the block
make long long vector v of size 1000000
define the main function
    make long long ints n and i
    read n
    create long long ints k = 0 and m = n
    make long long int l = si(n)
    set i to n
    create long long int c = 0
    create long long vector p
    make long long ints j = 9 * l and q = 0
    while q is less than or equal to j
        increase q by 1
        create long long z = i + count(i)
        if z is equal to n
            increase c by 1
            append i to p
        end of the block
        decrease i by 1
    end of the block
    print c
    sort vector p
    for i = 0 to p.size() exclusive, print p[i]
end of the block

[CODE]:

long long count(long long n) {
    long long k = n, s = 0;
    while (k > 0) {
        s += k % 10;
        k /= 10;
    }
    return s;
}
long long si(long long n) {
    long long k = n, s = 0;
    while (k > 0) {
        s++;
        k /= 10;
    }
    return s;
}
vector<long long> v[1000000];
int main() {
    long long n, i;
    cin >> n;
    long long k = 0, m = n;
    long long l = si(n);
    i = n;
    long long c = 0;
    vector<long long> p;
    long long j = 9 * l, q = 0;
    while (q <= j) {
        q++;
        long long z = i + count(i);
        if (z == n) {
            c++;
            p.push_back(i);
        }
        i--;
    }
    cout << c << endl;
    sort(p.begin(), p.end());
    for (i = 0; i < p.size(); i++) cout << p[i] << endl;
}
[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]:
define the main function
    define ints a, m and d
    read m and d and loop
        if m = 1 or 3 or 5 or 7 or 8 or 10 or 12
            if (31 + d - 1) modulo 7 != 0
                print (31 + d - 1) / 7 + 1 to the output
            else
                print (31 + d - 1) / 7
        else if m is equal to 2
            if (28 + d - 1) % 7 is not 0
                print (28 + d - 1) / 7 + 1
            else
                print (28 + d - 1) / 7 to the standard output
        else if (30 + d - 1) % 7 != 0
            print (30 + d - 1) / 7 + 1
        else
            print (30 + d - 1) / 7 to the stdout
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int a, m, d;
    while (cin >> m >> d) {
        if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
            if ((31 + d - 1) % 7 != 0)
                cout << (31 + d - 1) / 7 + 1 << endl;
            else
                cout << (31 + d - 1) / 7 << endl;
        else if (m == 2)
            if ((28 + d - 1) % 7 != 0)
                cout << (28 + d - 1) / 7 + 1 << endl;
            else
                cout << (28 + d - 1) / 7 << endl;
        else if ((30 + d - 1) % 7 != 0)
            cout << (30 + d - 1) / 7 + 1 << endl;
        else
            cout << (30 + d - 1) / 7 << endl;
    }
    return 0;
}
[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]:
MAXN = constant long long integer = 200100, md = constant long long integer of size 998244353
define the main function
    n, h, a, b, k, ta, fa, tb, fb = long longs
    read n, h, a, b, k
    while looping decrease k by 1
        read ta, fa, tb, fb
        ans = long long = the absolute value of the result of ta - tb
        if ans is not zero
            if fa > b or fa < a
                ans = ans + the lower value between the absolute value of the result of fa - a + the absolute value of the result of fb - a, and the absolute value of the result of fa - b + the absolute value of the result of fb - b
            else if fb > b or fb < a
                ans = ans + the lower value between the absolute value of the result of fb - b + the absolute value of the result of fa - b, and the absolute value of the result of fb - a + the absolute value of the result of fa - a
            else
                ans = ans + the absolute value of the result of fa - fb
            end of the block
        else
            ans = ans + the absolute value of the result of fa - fb
        end of the block
        print ans
    end of the block
end of the block

[CODE]:

const long long MAXN = 200100, md = 998244353;
int main() {
    long long n, h, a, b, k, ta, fa, tb, fb;
    cin >> n >> h >> a >> b >> k;
    while (k--) {
        cin >> ta >> fa >> tb >> fb;
        long long ans = abs(ta - tb);
        if (ans != 0) {
            if (fa > b || fa < a) {
                ans += min(abs(fa - a) + abs(fb - a), abs(fa - b) + abs(fb - b));
            } else if (fb > b || fb < a) {
                ans += min(abs(fb - b) + abs(fa - b), abs(fb - a) + abs(fa - a));
            } else {
                ans += abs(fa - fb);
            }
        } else {
            ans += abs(fa - fb);
        }
        cout << ans << '\n';
    }
}