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]:
define the main function
    i, j, k, even, odd, n, x and y are ints with even and odd = 0, j = 1 and k = 2; a is an array of ints with size 56
    read input to n
    for i = 0 to n / 2 exclusive, read input to a[i]
    sort a from index 0 to n / 2
    for i = 0 to n / 2 exclusive
        assign j - a[i] to x
        if x is less than 0, invert the sign of x
        add x to odd
        assign k - a[i] to y
        if y is less than 0, invert the sign of y
        increase even by y
        add 2 to j
        add 2 to k
    end of the block
    if odd is greater than even
        print even
    else
        print odd
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int i, j = 1, k = 2, even = 0, odd = 0, n, x, y, a[56];
    cin >> n;
    for (i = 0; i < n / 2; i++) { cin >> a[i]; }
    sort(a, a + n / 2);
    for (i = 0; i < n / 2; i++) {
        x = j - a[i];
        if (x < 0) x = -x;
        odd += x;
        y = k - a[i];
        if (y < 0) y = -y;
        even += y;
        j += 2;
        k += 2;
    }
    if (odd > even)
        cout << even << endl;
    else
        cout << odd << 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]:
create constant integer maxn = 110
create integer array a of size maxn
define the main function
    create integers i, j, n, and k
    read n and k
    for i = 0 to n exclusive, read a[i]
    create integers e, s, and maxx = -1
    for i = 0 to k exclusive
        set e to 0
        set s to 0
        for j = 0 to n exclusive
            if (j - i) modulo k is 0
                continue to next loop iteration
            else
                if a[j] is equal to 1
                    increment e
                else if a[j] is equal to -1
                    increment s
            end of the block
        end of the block
        set maxx to the max of maxx and the absolute value of e - s
    end of the block
    print maxx
    return to indicate successful execution
end of the block

[CODE]:

const int maxn = 110;
int a[maxn];
int main() {
    int i, j, n, k;
    cin >> n >> k;
    for (i = 0; i < n; i++) { cin >> a[i]; }
    int e, s, maxx = -1;
    for (i = 0; i < k; i++) {
        e = 0;
        s = 0;
        for (j = 0; j < n; j++) {
            if ((j - i) % k == 0) {
                continue;
            } else {
                if (a[j] == 1)
                    e++;
                else if (a[j] == -1)
                    s++;
            }
        }
        maxx = max(maxx, abs(e - s));
    }
    cout << maxx << 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]:
INF = const long with INF = 2000000
a = long array of size 10000
i, j = long
n, m = long
define the main function
    read n, m
    for i = 0 to m exclusive
        read j
        increment a[j]
    end of the block
    j = INF
    for i = 1 to n
        if (j > a[i]), j = a[i]
    print j
    return to indicate successful execution
end of the block

[CODE]:

const long INF = 2000000;
long a[10000];
long i, j;
long n, m;
int main() {
    cin >> n >> m;
    for (i = 0; i < m; i++) {
        cin >> j;
        a[j]++;
    }
    j = INF;
    for (i = 1; i <= n; i++)
        if (j > a[i]) j = a[i];
    cout << j << 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 tp with integer a as argument, returning boolean
    if a is less than 2, return false from function
    for i = 2 to i * i is less than or equal to a, incrementing i
        if a % i is 0, return false from function
    end of the block
    return true from function
end of the block
declare cm with integer a as argument
    create integer lt with lt = 2
    for i = 3 to a inclusive
        if result of run tp with i as argument is true
            if lt + i is a, return true from function
            if lt + i is greater than a, return false from function
            set lt to i
        end of the block
    end of the block
    return false from function
end of the block
create integers n, k, cnt
define the main function
    read n read k
    for i = 2 to n inclusive
        if result of run tp with i as argument is true
            create integer p with p = i - 1
            if result of run cm with p as argument is true, increment cnt
        end of the block
    end of the block
    if cnt is greater than or equal to k
        print "YES" print newline
    else
        print "NO" print newline
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

bool tp(int a) {
    if (a < 2) { return false; }
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) { return false; }
    }
    return true;
}
bool cm(int a) {
    int lt = 2;
    for (int i = 3; i <= a; i++) {
        if (tp(i)) {
            if (lt + i == a) { return true; }
            if (lt + i > a) { return false; }
            lt = i;
        }
    }
    return false;
}
int n, k, cnt;
int main() {
    cin >> n >> k;
    for (int i = 2; i <= n; i++) {
        if (tp(i)) {
            int p = i - 1;
            if (cm(p)) { cnt++; }
        }
    }
    if (cnt >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << 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
    a is a new array of ints with 6 elements; i, j, k, sum, flg and b are integers with sum, flg and b = 0 and j = 1
    for i = 0 to 6 exclusive
        read b from the user input
        assign b to a[i] if 0 <= b and b <= 1000
    end of the block
    start for loop from i = 0 to 6 exclusive, increasing sum by a[i] on each loop iteration
    if sum is even
        in a for loop, change i from 0 to 4 exclusive incrementing i
            for j = i + 1 to 5 exclusive
                change k from j + 1 to 6 exclusive incrementing k in a for loop
                    if a[i] + a[j] + a[k] is equal to sum / 2
                        change flg to 1
                        stop the loop
                    end of the block
                end of the block
                if flg is equal to 1, break
            end of the block
            if flg is equal to 1, break
        end of the block
        if flg is equal to 1
            print "YES"
        else
            print "NO" to the standard output
        end of the block
    else
        print "NO"
end of the block

[CODE]:

int main() {
    int a[6], i, j = 1, k, sum = 0, flg = 0, b = 0;
    for (i = 0; i < 6; i++) {
        cin >> b;
        if (0 <= b && b <= 1000) { a[i] = b; }
    }
    for (i = 0; i < 6; i++) { sum += a[i]; }
    if (sum % 2 == 0) {
        for (i = 0; i < 4; i++) {
            for (j = i + 1; j < 5; j++) {
                for (k = j + 1; k < 6; k++) {
                    if (a[i] + a[j] + a[k] == (sum / 2)) {
                        flg = 1;
                        break;
                    }
                }
                if (flg == 1) { break; }
            }
            if (flg == 1) { break; }
        }
        if (flg == 1) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } else
        cout << "NO" << 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
    let n, m, max, idx = integers with max = -1
    let x = float
    read n, m
    for integer i=0 to n exclusive do the following
        read x
        set x = round up of x / m
        if x is greater than or equal to max do the following
            set max = x
            set idx = i
        end of the block
    end of the block
    print idx + 1
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, m, max = -1, idx;
    float x;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> x;
        x = ceil(x / m);
        if (x >= max) {
            max = x;
            idx = i;
        }
    }
    cout << (idx + 1) << 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
    let a be an array of characters of length 10
    read 9 characters into a
    for i = 0 to 5 exclusive
        if a[i] != a[8 - i]
            print "NO" and a new line
            return to indicate successful execution
        end of the block
    end of the block
    print "YES" and a new line
end of the block

[CODE]:

int main() {
    char a[10];
    for (int i = 0; i < 9; i++) { cin >> a[i]; }
    for (int i = 0; i < 5; i++) {
        if (a[i] != a[8 - i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << 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
    s = string
    loop while reading s
        len = int with len = length of s
        print (len + 1) * 26 - len
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    string s;
    while (cin >> s) {
        int len = s.length();
        cout << (len + 1) * 26 - len << 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 strings ans, s
    read s
    create integer i with size of s / 2 - 1
    if size of s % 2 is 1, increment i
    create integer p with p = i + 1
    for i is less than or equal to 0, decrementing i, incrementing p
        add element s[i] to end of ans
        if p is less than size of s, add element s[p] to end of ans
    end of the block
    print ans print newline
end of the block

[CODE]:

int main() {
    string ans, s;
    cin >> s;
    int i = s.size() / 2 - 1;
    if (s.size() % 2 == 1) i++;
    int p = i + 1;
    for (; i >= 0; i--, p++) {
        ans.push_back(s[i]);
        if (p < s.size()) ans.push_back(s[p]);
    }
    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]:
define the main function
    create int a, b, c, d, k, set k to 0
    read a, b and c
    create int n
    read n
    for i=0 to n exclusive
        read d
        if d greater than b and d less than c, increment k
    end of the block
    print k
end of the block

[CODE]:

int main() {
    int a, b, c, d, k = 0;
    cin >> a >> b >> c;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d;
        if (d > b && d < c) k++;
    }
    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]:
define the main function
    n,s,a,b,c,d=int, pos=1
    read n,a,b,c,d
    s=a+b+c+d
    decrement n
    while decremented value of n is not zero
        read a,b,c,d
        if a+b+c+d > s increment pos
    end of the block
    print pos
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, s, a, b, c, d, pos = 1;
    cin >> n >> a >> b >> c >> d;
    s = a + b + c + d;
    n--;
    while (n--) {
        cin >> a >> b >> c >> d;
        if (a + b + c + d > s) { pos++; }
    }
    cout << pos << '\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
    declare character arrays m1 = "1", m2 = "14", m3 ="144"
    declare character array a size 1000
    declare integers i, j, k, l
    read a
    for i = 0 to a[i]
        if a[i] is m3[0] and a[i+1] is m3[1] and a[i+2] is m3[2]
            increment i by 3
        else if a[i] is m2[0] and a[i+1] is m2[1]
            increment i by 2
        else if a[i] is m1[0]
            increment i by 1
        else
            print "NO\n"
            exit program with code 0
        end of the block
    end of the block
    print "YES\n"
end of the block

[CODE]:

int main() {
    char m1[] = "1", m2[] = "14", m3[] = "144";
    char a[1000];
    int i, j, k, l;
    cin >> a;
    for (i = 0; a[i];) {
        if (a[i] == m3[0] && a[i + 1] == m3[1] && a[i + 2] == m3[2])
            i += 3;
        else if (a[i] == m2[0] && a[i + 1] == m2[1])
            i += 2;
        else if (a[i] == m1[0])
            i += 1;
        else {
            cout << "NO\n";
            exit(0);
        }
    }
    cout << "YES\n";
}
[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, d = integers with vis, lvl = arrays of 200 integers
st = string
in function bfs
    Q = queue of integers
    set all contents of vis to -1
    push 0 in Q
    lvl[0] = 0
    u = integer
    while not Q is empty
        set u to the front of Q
        pop Q
        if u is n - 1 then return lvl[u]
        for i = u + 1 to u + d inclusive
            if vis[i] is -1 and st[i] is character 1
                vis[i] = 1
                set lvl[i] to lvl[u] + 1
                push i in Q
            end of the block
        end of the block
    end of the block
    return -1
end of the block
define the main function
    read n and d
    read st
    print the result of fuction bfs
end of the block

[CODE]:

int n, d, vis[200], lvl[200];
string st;
int bfs() {
    queue<int> Q;
    memset(vis, -1, sizeof(vis));
    Q.push(0);
    lvl[0] = 0;
    int u;
    while (!Q.empty()) {
        u = Q.front();
        Q.pop();
        if (u == n - 1) return lvl[u];
        for (int i = u + 1; i <= u + d; i++) {
            if (vis[i] == -1 && st[i] == '1') {
                vis[i] = 1;
                lvl[i] = lvl[u] + 1;
                Q.push(i);
            }
        }
    }
    return -1;
}
int main() {
    cin >> n >> d;
    cin >> st;
    cout << bfs() << "\n";
}