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]:
a = integer array of size 105
in function summ with parameters integers l, r and return long long
    ans = long long set to 0
    for i = l to r inclusive, add a[i] to ans
    return ans
end of the block
define the main function
    declare an integer n
    input n
    sum = long long set to 0
    ans = integer set to 0
    for i = 1 to n inclusive
        read a[i]
        add a[i] to sum
        if a[i] is 0, increment ans
    end of the block
    if sum is 0
        if ans is n
            print NO
        else
            for i = 1 to n exclusive
                if call summ with 1, i isn't 0 and call summ with i + 1, n isn't 0
                    print YES, newline, 2
                    print 1, " ", i
                    print i + 1, " ", n
                    break
                end of the block
            end of the block
        end of the block
    else
        print YES
        print 1
        print 1, " ", n
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int a[105];
long long summ(int l, int r) {
    long long ans = 0;
    for (int i = l; i <= r; i++) { ans += a[i]; }
    return ans;
}
int main() {
    int n;
    cin >> n;
    long long sum = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
        if (a[i] == 0) ans++;
    }
    if (sum == 0) {
        if (ans == n) {
            cout << "NO" << endl;
        } else {
            for (int i = 1; i < n; i++) {
                if (summ(1, i) != 0 && summ(i + 1, n) != 0) {
                    cout << "YES" << endl << 2 << endl;
                    cout << 1 << " " << i << endl;
                    cout << i + 1 << " " << n << endl;
                    break;
                }
            }
        }
    } else {
        cout << "YES" << endl;
        cout << 1 << endl;
        cout << 1 << " " << n << 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
    x = integer with x = 0
    s2 = string
    read s2
    for i = s2.length() - 2 down to 0
        if s2[i] is s2[i + 1], erase(i, 2) from s2
    end of the block
    print s2
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int x = 0;
    string s2;
    cin >> s2;
    for (int i = s2.length() - 2; i >= 0; i--) {
        if (s2[i] == s2[i + 1]) s2.erase(i, 2);
    }
    cout << s2 << 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 constant integer maxn = 1e5 + 10
declare integer arrays a size maxn, b size maxn
declare integer arrays c size maxn, d size maxn
define the main function
    declare integer n
    read n
    for i = 0 to n exclusive
        read a[i]
        increment c[a[i]]
    end of the block
    for i = 0 to n exclusive
        read b[i]
        increment d[b[i]]
    end of the block
    declare integer k = 0
    for i = 1 to 5 inclusive
        if (d[i] + c[i] bitwise and 1 )
            print "-1" and newline
            return to indicate successful execution
        end of the block
        increment k by absolute value of ( c[i] - d[i] ) / 2
    end of the block
    print k / 2 and newline
    return to indicate successful execution
end of the block

[CODE]:

const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
int c[maxn], d[maxn];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        c[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        d[b[i]]++;
    }
    int k = 0;
    for (int i = 1; i <= 5; i++) {
        if ((d[i] + c[i] & 1)) {
            cout << "-1" << endl;
            return 0;
        }
        k += abs(c[i] - d[i]) / 2;
    }
    cout << k / 2 << 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 = integer
    read a
    if a & 1 or a = 2
        print "NO" and a new line
    else
        print "YES" and a new line
end of the block

[CODE]:

int main() {
    int a;
    cin >> a;
    if (a & 1 || a == 2)
        cout << "NO" << endl;
    else
        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
    a, b, c, d are strings
    read a, b
    display a, ' ', b
    n is an integer
    read n
    iterate n times
        read c, d
        if c equals a
            assign d to a
        else
            assign d to b
        display a, ' ', b
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    string a, b, c, d;
    cin >> a >> b;
    cout << a + ' ' + b << '\n';
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c >> d;
        if (c == a)
            a = d;
        else
            b = d;
        cout << a + ' ' + b << '\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 integer n
    read n
    if n equal 0
        print 0
    else if n equal 2
        print 2
    else
        print 1
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n;
    cin >> n;
    if (n == 0)
        cout << 0 << endl;
    else if (n == 2)
        cout << 2 << endl;
    else
        cout << 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
    n, one, two and trone are integers where one, two and trone = 0
    declare vector of ints called x
    read n
    for integer i = 0 to n exclusive
        declare integer variable tmp
        read tmp
        if tmp = 1
            increment one by 1
        else
            increment two by 1
        push tmp into x
    end of the block
    assign one to trone
    create int ans = min of one and two
    subtract ans from trone
    divide trone by 3
    print ans + trone
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, one = 0, two = 0, trone = 0;
    vector<int> x;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        if (tmp == 1)
            one++;
        else
            two++;
        x.push_back(tmp);
    }
    trone = one;
    int ans = min(one, two);
    trone -= ans;
    trone /= 3;
    cout << ans + trone << 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]:
in the function binaria that takes integer x, reference n and returns integer
    l, r = integers with l = 1, r = sqrt(n) + 1
    while l <= r
        mid = integer with mid = (l + r) / 2
        if mid * (mid + 1) is x
            return 1
        else if mid * (mid + 1) < x
            l = mid + 1
        else
            r = mid - 1
    end of the block
    return to indicate successful execution
end of the block
define the main function
    n = integer
    read n
    flag = bool with flag = false
    for i = 1 to sqrt(n * 2)
        if binaria(2 * n - i * (i + 1), n)
            flag = true
            break loop
        end of the block
    if not flag
        print NO
    else
        print YES
end of the block

[CODE]:

int binaria(int x, int &n) {
    int l = 1, r = sqrt(n) + 1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (mid * (mid + 1) == x)
            return 1;
        else if (mid * (mid + 1) < x)
            l = mid + 1;
        else
            r = mid - 1;
    }
    return 0;
}
int main() {
    int n;
    cin >> n;
    bool flag = false;
    for (int i = 1; i <= sqrt(n * 2); i++)
        if (binaria(2 * n - i * (i + 1), n)) {
            flag = true;
            break;
        }
    if (!flag)
        cout << "NO" << endl;
    else
        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
    create integers n, m
    create characters a, b
    read n read m
    for i = 0 to n exclusive
        for j = 0 to m exclusive
            if j is 0
                read a
                if i is not 0 and a is b
                    print "NO\n"
                    return to indicate successful execution
                end of the block
                set b to a
            else
                read a
            if a is not b
                print "NO\n"
                return to indicate successful execution
            end of the block
        end of the block
    end of the block
    print "YES\n"
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, m;
    char a, b;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (j == 0) {
                cin >> a;
                if (i != 0 && a == b) {
                    cout << "NO\n";
                    return 0;
                }
                b = a;
            } else
                cin >> a;
            if (a != b) {
                cout << "NO\n";
                return 0;
            }
        }
    }
    cout << "YES\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]:
create const int MAXN = 1005
create character c
declare integer array s with size MAXN
create integers n and p
function work2 with int argument x
    if x is greater than n
        for i from 1 to n inclusive, print s[i] + 'a' - 1 as char
        print a new line
        call exit with argument 0
    end of the block
    for i from 1 to p inclusive incrementing i
        declare boolean ch1 = (x - 1 <= 0 || i != s[x - 1])
        declare boolean ch2 = (x - 2 <= 0 || i != s[x - 2])
        if ch1 is true and ch2 is true
            assign i to s[x]
            call function work2 with arguments x + 1
        end of the block
    end of the block
end of the block
function work with int argument x
    while s[x] < p
        increment s[x] by one
        declare bool ch1 = (x - 1 <= 0 || s[x - 1] != s[x])
        create boolean ch2 = (x - 2 <= 0 || s[x - 2] != s[x])
        if ch1 && ch2 are both true, call work2(x + 1)
    end of the block
end of the block
define the main function
    read from the input to n and p
    for i = 1 to n inclusive, read c and set s[i] to c - 'a' + 1
    for integer i = n to 1 inclusive, decrementing i, call work(i)
    print "NO"
    return to indicate successful execution
end of the block

[CODE]:

const int MAXN = 1005;
char c;
int s[MAXN];
int n, p;
void work2(int x) {
    if (x > n) {
        for (int i = 1; i <= n; i++) cout << (char)(s[i] + 'a' - 1);
        cout << endl;
        exit(0);
    }
    for (int i = 1; i <= p; i++) {
        bool ch1 = (x - 1 <= 0 || i != s[x - 1]);
        bool ch2 = (x - 2 <= 0 || i != s[x - 2]);
        if (ch1 && ch2) {
            s[x] = i;
            work2(x + 1);
        }
    }
}
void work(int x) {
    while (s[x] < p) {
        s[x]++;
        bool ch1 = (x - 1 <= 0 || s[x - 1] != s[x]);
        bool ch2 = (x - 2 <= 0 || s[x - 2] != s[x]);
        if (ch1 && ch2) work2(x + 1);
    }
}
int main() {
    cin >> n >> p;
    for (int i = 1; i <= n; i++) cin >> c, s[i] = c - 'a' + 1;
    for (int i = n; i >= 1; i--) work(i);
    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
    create long longs n, k
    create 2d integer array a with size 3 by 10 with a = {{0, 1, 2, 2, 1, 0}, {1, 0, 0, 1, 2, 2}, {2, 2, 1, 0, 0, 1}}
    read n read k
    set n to n % 6
    for i = 0 to 3 exclusive
        if a[i][n] is k, print i print newline
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    long long n, k;
    int a[3][10] = {{0, 1, 2, 2, 1, 0}, {1, 0, 0, 1, 2, 2}, {2, 2, 1, 0, 0, 1}};
    cin >> n >> k;
    n = n % 6;
    for (int i = 0; i < 3; i++) {
        if (a[i][n] == k) 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
    let t be a character
    read t
    let a, b be strings
    read a, b
    let s0 , s1 be characters with s0 is equal to a[1], s1 is equal to b[1]
    if a[0] is equal to A, a[0] is equal to Z
    if b[0] is equal to A, b[0] is equal to Z
    if a[0] is equal to T, a[0] is equal to B
    if b[0] is equal to T, b[0] is equal to B
    if a[0] is equal to K, a[0] is equal to X
    if b[0] is equal to K, b[0] is equal to X
    if s0 is equal to t and s1 is not equal to t
        print YES and newline
        return to indicate successful execution
    end of the block
    if s0 is equal to s1 and a[0] is greater than b[0]
        print YES and newline
        return to indicate successful execution
    end of the block
    print NO and newline
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    char t;
    cin >> t;
    string a, b;
    cin >> a >> b;
    char s0 = a[1], s1 = b[1];
    if (a[0] == 'A') a[0] = 'Z';
    if (b[0] == 'A') b[0] = 'Z';
    if (a[0] == 'T') a[0] = 'B';
    if (b[0] == 'T') b[0] = 'B';
    if (a[0] == 'K') a[0] = 'X';
    if (b[0] == 'K') b[0] = 'X';
    if (s0 == t && s1 != t) {
        cout << "YES" << endl;
        return 0;
    }
    if (s0 == s1 && a[0] > b[0]) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}