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
    create integers n, x, sum and cont with sum and cont = 0, and an array a with size 1005
    read variables n and x from the input
    for i from 0 to n exclusive incrementing i
        read standard input to a[i]
        increase sum by a[i]
    end of the block
    declare integer baad with value x
    change sum to it's absolute value
    while sum is not 0
        while sum < x, decrement x
        subtract x from sum
        increment cont by one
    end of the block
    print cont
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, x, a[1005], sum = 0, cont = 0;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int baad = x;
    sum = abs(sum);
    while (sum != 0) {
        while (sum < x) x--;
        sum -= x;
        cont++;
    }
    cout << cont << 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 new int variables player1, player2 and player3
declare integer variable with name n
new integer variable a
define the main function
    read n from the input
    assign 1 to player1
    set player2 to 2
    change player3 to 3
    loop, decrementing n, while it is not 0
        read from the input to a
        if a is equal to player3
            print "NO\n" to the standard output
            return to indicate successful execution
        end of the block
        if a = player1
            swap player3 and player2
        else
            swap player3 and player1
    end of the block
    print "YES\n" to the standard output
    return to indicate successful execution
end of the block

[CODE]:

int player1, player2, player3;
int n;
int a;
int main() {
    cin >> n;
    player1 = 1;
    player2 = 2;
    player3 = 3;
    while (n--) {
        cin >> a;
        if (a == player3) {
            cout << "NO\n";
            return 0;
        }
        if (a == player1)
            swap(player3, player2);
        else
            swap(player3, player1);
    }
    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]:
n, m, a, b and c are long longs
declare long longs Yellow, Blue and ans
define the main function
    read n, m, a, b and c
    Yellow = a * 2 + b
    Blue = b + c * 3
    if Yellow >= n and Blue >= m
        increase ans by Yellow + Blue - n - m
    else if Yellow < n and Blue is greater than m
        increase ans by Blue - m
    else if Yellow > n and Blue is less than m
        increase ans by Yellow - n
    print ans and a new line
    return to indicate successful execution
end of the block

[CODE]:

long long n, m, a, b, c;
long long Yellow, Blue, ans;
int main() {
    cin >> n >> m >> a >> b >> c;
    Yellow = a * 2 + b;
    Blue = b + c * 3;
    if (Yellow >= n && Blue >= m)
        ans += Yellow + Blue - n - m;
    else if (Yellow < n && Blue > m)
        ans += Blue - m;
    else if (Yellow > n && Blue < m)
        ans += Yellow - n;
    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]:
define the main function
    x1, y1, x2, y2 = int
    read x1 then y1 then x2 then y2
    ans = int with ans = min of absolute x1 - x2 and absolute y1 - y2
    if absolute x1 - x2 is not ans
        add absolute of absolute of x2 - x1 - ans to ans
    else if absolute of y1 - y2 is not ans
        add absolute of absolute of y2 - y1 - ans to ans
    end of the block
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int ans = min(abs(x1 - x2), abs(y1 - y2));
    if (abs(x1 - x2) != ans) {
        ans += abs(abs(x2 - x1) - ans);
    } else if (abs(y1 - y2) != ans) {
        ans += abs(abs(y2 - y1) - ans);
    }
    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
    integers = n,i,j,k
    integers = array x any y with size of 101
    while inputting n do
        for = 0 to less than or equal to 100 set x[i] = y[i] = 0
        for = 0 to less than n do the following
            read j,k
            add one to x[j]
            add one to y[k]
        end of the block
        set j to k
        for = 0 to less than or equal to 100 do the following
            if x[i] is true
            if y[i] is true
        end of the block
        output j if j < k else output k
        output endl
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, i, j, k;
    int x[101], y[101];
    while (cin >> n) {
        for (i = 0; i <= 100; i++) { x[i] = y[i] = 0; }
        for (i = 0; i < n; i++) {
            cin >> j >> k;
            x[j]++;
            y[k]++;
        }
        j = k = 0;
        for (i = 0; i <= 100; i++) {
            if (x[i]) j++;
            if (y[i]) k++;
        }
        cout << (j < k ? j : k);
        cout << 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 pair array of int and int a of size 10001
declare drom taking in int r and returning integer
    if a[r].first is not 0
        create int u = r
        set r to a[r].first
        if a[r].second is not 0
            set a[r].second to min of a[r].second and a[u]second
        else do
            set a[r].second to a[u].second
        set a[u].first to 0
    else
        return r
    set r to return value of drom(r)
    return r
end of the block
make ints n, t, and l
define the main function
    read n and t
    while t is not equal to 0
        make ints x, y, and z
        read x, y, and z
        set a[x].first to y
        set a[x].second to z
        decrease t by 1
    end of the block
    for i = 1 to n
        make int m = drom(i)
        if m is not equal to i
            set a[i].first to m
            set a[i].second to a[m].second
        else do
            set first value of a[i] to 0
        end of the block
    end of the block
    for i = 1 to n
        if a[i].first is not equal to 0, increment l
    print l
    for i = 1 to n
        if a[i].first is not equal to 0, print i, " ", a[i].first, " ", and a[i].second
end of the block

[CODE]:

pair<int, int> a[10001];
int drom(int r) {
    if (a[r].first != 0) {
        int u = r;
        r = a[r].first;
        if (a[r].second != 0)
            a[r].second = min(a[r].second, a[u].second);
        else
            a[r].second = a[u].second;
        a[u].first = 0;
    } else
        return r;
    r = drom(r);
    return r;
}
int n, t, l;
int main() {
    cin >> n >> t;
    while (t != 0) {
        int x, y, z;
        cin >> x >> y >> z;
        a[x].first = y;
        a[x].second = z;
        t--;
    }
    for (int i = 1; i <= n; ++i) {
        int m = drom(i);
        if (m != i) {
            a[i].first = m;
            a[i].second = a[m].second;
        } else {
            a[i].first = 0;
        }
    }
    for (int i = 1; i <= n; ++i)
        if (a[i].first != 0) l++;
    cout << l << endl;
    for (int i = 1; i <= n; ++i)
        if (a[i].first != 0) cout << i << " " << a[i].first << " " << a[i].second << 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 = integer
    read n
    for i = 0 to i * (i - 1) / 2 <= n
        if i * (i - 1) / 2 is equal to n return !(cout << "YES\n")
    return !(cout << "NO\n")
end of the block

[CODE]:

int main() {
    int n;
    cin >> n;
    for (int i = 0; i * (i - 1) / 2 <= n; i++)
        if (i * (i - 1) / 2 == n) return !(cout << "YES\n");
    return !(cout << "NO\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]:
declare long long k
declare vector of long longs v
in the function d with long long argument n
    declare long long variable c = 0
    for i = 1 while i * i <= n
        if n % i = 0
            push i to the end of v
            if n / i != i push n / i to the end of v
        end of the block
    end of the block
    sort v
    if length of v is less than k
        print "-1"
    else
        print v[k - 1]
end of the block
define the main function
    create long long n
    read n and k
    invoke function d with argument n
    return to indicate successful execution
end of the block

[CODE]:

long long k;
vector<long long> v;
void d(long long n) {
    long long c = 0;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            v.push_back(i);
            if (n / i != i) v.push_back(n / i);
        }
    }
    sort(v.begin(), v.end());
    if (v.size() < k)
        cout << "-1" << endl;
    else
        cout << v[k - 1] << endl;
}
int main() {
    long long n;
    cin >> n >> k;
    d(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]:
function iamax (get pointer to int arr, int N, return int)
    ma=arr[0]
    for i=1 to N exclusive ma=max(arr[i], ma)
    return ma
end of the block
function readarr (get pointer to int arr and N, return nothing)
    read into N
    for i=0 to number pointed by N exclusive read arr[i]
end of the block
arr=array of 1005 char
k,n=int
function pal (get int a and b, return bool)
    while a<b
        if arr[a] is not arr[b-1] return false
        increment a
        decrement b
    end of the block
    return true
end of the block
function run (no args, return bool)
    mul=n/k
    for i=0 to n exclusive by mul
        if not pal(i,i+mul) return false
    end of the block
    return true
end of the block
define the main function
    read arr,k
    n=length of arr
    if n modulo k
        print "NO"
    else
        if run()
            print "YES"
        else
            print "NO"
    end of the block
end of the block

[CODE]:

int iamax(int *arr, int N) {
    int ma = arr[0];
    for (int i = 1; i < N; i++) ma = max(arr[i], ma);
    return ma;
}
void readarr(int *arr, int *N) {
    cin >> *N;
    for (int i = 0; i < *N; i++) cin >> arr[i];
}
char arr[1005];
int k, n;
bool pal(int a, int b) {
    while (a < b) {
        if (arr[a] != arr[b - 1]) return false;
        a++;
        b--;
    }
    return true;
}
bool run() {
    int mul = n / k;
    for (int i = 0; i < n; i += mul) {
        if (!pal(i, i + mul)) return false;
    }
    return true;
}
int main() {
    cin >> arr >> k;
    n = strlen(arr);
    if (n % k)
        cout << "NO\n";
    else {
        if (run())
            cout << "YES\n";
        else
            cout << "NO\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]:
define the main function
    declare long ints n and ans where ans = 0
    read n
    create integers vector v
    for i = 0 to n exclusive
        create integer x
        read x
        push x to v
    end of the block
    sort v
    for i from 0 to n - 1 exclusive, increase ans by v[n - 1] - v[i]
    print ans
end of the block

[CODE]:

int main() {
    long int n, ans = 0;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n - 1; i++) { ans += v[n - 1] - v[i]; }
    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]:
create constant long long MAX = 1000
define the main function
    declare long long variable n
    read input to n
    if n is odd
        print 1
    else
        print 2 to the output
end of the block

[CODE]:

const long long MAX = 1000;
int main() {
    long long n;
    cin >> n;
    if (n % 2 == 1)
        cout << 1 << endl;
    else
        cout << 2 << 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 = long long
    read a, b, c
    ada = boolean = 0
    for i = 0, i is multiplied by a to 100000 inclusive
        for i = 0, i is multiplied by b to 100000 inclusive
            if j * b + i * a > c, exit the for loop
            if j * b + i * a is c, ada = 1
            if ada is nonzero, exit the loop
        end of the block
        if ada is nonzero, exit the loop
    end of the block
    if ada is nonzero
        print Yes
    else
        print No
end of the block

[CODE]:

int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    bool ada = 0;
    for (long long i = 0; i * a <= 100000; i++) {
        for (long long j = 0; j * b <= 100000; j++) {
            if (j * b + i * a > c) break;
            if (j * b + i * a == c) ada = 1;
            if (ada) break;
        }
        if (ada) break;
    }
    if (ada)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}