[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 a long long integer mod=1e9+9
into the function qm which takes two long long integers a and b and returns a long long int
    let ans be long long int with ans=1
    while b>0 do the following
        if b&1 then set ans= ans * a % mod
        set b= b >> 1
        set a= a*a%mod
    end of the block
    return (ans % mod + mod) % mod
end of the block
c= character array of size 1000005
define the main function
    n,a,b,k= long long ints
    read n,a,b,k
    read c
    create long long int ans=0
    if n+1 <= k
        for i=0 to n inclusive
            if c[i] = -
                then set ans = ans - qm(a, n - i) * qm(b, i)
                set ans = (ans % mod + mod) % mod
            else do the following
                set ans = ans + qm(a, n - i) * qm(b, i)
                set ans = (ans % mod + mod) % mod
            end of the block
        end of the block
        set ans = (ans % mod + mod) % mod
        print ans
    else do the following
        create long long t= (n+1) / k
        creaye long long integer g = (n+1) %k
        let x=0 be a long long integer
        if g is equal to 0
            for i=0 to k exclusive
                if c[i] is equal to -
                    then set x = x - qm(a, n - i) * qm(b, i)
                    set x = (x % mod + mod) % mod
                else do the following
                    set x = x + qm(a, n - i) * qm(b, i)
                    assign (x % mod + mod) % mod to x
                end of the block
            end of the block
            if qm(a, k) = qm(b, k)
                then set ans = t*t
                assign (ans % mod + mod) % mod to ans
                print ans
                return to indicate successful execution
            end of the block
            create long long integer jj = qm(a, t * k) - qm(b, t * k)
            set jj = x*jj%mod
            set jj= jj* qm(a,k) % mod
            do nothing
            set jj = jj % mod
            create long long integer nn = qm(a, k) - qm(b, k)
            set nn = nn % mod
            assign nn * qm(a, t * k) to nn
            set nn = nn % mod
            set nn = qm(nn, mod - 2)
            assign jj * nn to ans
            set ans to (ans % mod + mod) % mod
            print ans
        else do the following
            for i=0 to k exclusive
                if c[i] is equal to -
                    set x = x - qm(a, n - i) * qm(b, i)
                    set x = (x % mod + mod) % mod
                else do the following
                    set x to x + qm(a, n - i) * qm(b, i)
                    assign (x % mod + mod) % mod to x
                end of the block
            end of the block
            if qm(a, k) == qm(b, k)
                then set ans= t*x
                set ans = (ans % mod + mod) % mod
                for hh=0 to g exclusive
                    if c[hh] is equal to -
                        set ans = ans - qm(a, n - (t * k + hh)) * qm(b, (t * k + hh))
                        set ans = (ans % mod + mod) % mod
                    else do the following
                        set ans = ans + qm(a, n - (t * k + hh)) * qm(b, (t * k + hh))
                        set ans = (ans % mod + mod) % mod
                    end of the block
                end of the block
                set ans = (ans % mod + mod) % mod
                print ans
                return to indicate successful execution
            end of the block
            create long long integer jj = qm(a, t * k) - qm(b, t * k)
            set jj to x * jj % mod
            set jj = jj * qm(a, k) % mod
            do nothing
            assign jj % mod to jj
            create long long integer nn = (qm(a, k) - qm(b, k))
            set nn = nn % mod
            assign nn * qm(a, t * k) to nn
            set nn = nn % mod
            set nn = qm(nn, mod - 2)
            set ans = jj * nn
            set ans = (ans % mod + mod) % mod
            for hh=0 to g exclusive
                if c[hh] is -
                    set ans = ans - qm(a, n - (t * k + hh)) * qm(b, (t * k + hh))
                    set ans = (ans % mod + mod) % mod
                else do the following
                    set ans = ans + qm(a, n - (t * k + hh)) * qm(b, (t * k + hh))
                    set ans = (ans % mod + mod) % mod
                end of the block
            end of the block
            set ans = (ans % mod + mod) % mod
            print ans
        end of the block
    end of the block
end of the block

[CODE]:

long long mod = 1e9 + 9;
long long qm(long long a, long long b) {
    long long ans = 1;
    while (b > 0) {
        if (b & 1) ans = ans * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return (ans % mod + mod) % mod;
}
char c[1000005];
int main() {
    long long n, a, b, k;
    cin >> n >> a >> b >> k;
    cin >> c;
    long long ans = 0;
    if (n + 1 <= k) {
        for (long long i = 0; i <= n; i++) {
            if (c[i] == '-') {
                ans = ans - qm(a, n - i) * qm(b, i);
                ans = (ans % mod + mod) % mod;
            } else {
                ans = ans + qm(a, n - i) * qm(b, i);
                ans = (ans % mod + mod) % mod;
            }
        }
        ans = (ans % mod + mod) % mod;
        cout << ans << endl;
    } else {
        long long t = (n + 1) / k;
        long long g = (n + 1) % k;
        long long x = 0;
        if (g == 0) {
            for (long long i = 0; i < k; i++) {
                if (c[i] == '-') {
                    x = x - qm(a, n - i) * qm(b, i);
                    x = (x % mod + mod) % mod;
                } else {
                    x = x + qm(a, n - i) * qm(b, i);
                    x = (x % mod + mod) % mod;
                }
            }
            if (qm(a, k) == qm(b, k)) {
                ans = t * x;
                ans = (ans % mod + mod) % mod;
                cout << ans << endl;
                return 0;
            }
            long long jj = qm(a, t * k) - qm(b, t * k);
            jj = x * jj % mod;
            jj = jj * qm(a, k) % mod;
            ;
            jj = jj % mod;
            long long nn = (qm(a, k) - qm(b, k));
            nn = nn % mod;
            nn = nn * qm(a, t * k);
            nn = nn % mod;
            nn = qm(nn, mod - 2);
            ans = jj * nn;
            ans = (ans % mod + mod) % mod;
            cout << ans << endl;
        } else {
            for (long long i = 0; i < k; i++) {
                if (c[i] == '-') {
                    x = x - qm(a, n - i) * qm(b, i);
                    x = (x % mod + mod) % mod;
                } else {
                    x = x + qm(a, n - i) * qm(b, i);
                    x = (x % mod + mod) % mod;
                }
            }
            if (qm(a, k) == qm(b, k)) {
                ans = t * x;
                ans = (ans % mod + mod) % mod;
                for (long long hh = 0; hh < g; hh++) {
                    if (c[hh] == '-') {
                        ans = ans - qm(a, n - (t * k + hh)) * qm(b, (t * k + hh));
                        ans = (ans % mod + mod) % mod;
                    } else {
                        ans = ans + qm(a, n - (t * k + hh)) * qm(b, (t * k + hh));
                        ans = (ans % mod + mod) % mod;
                    }
                }
                ans = (ans % mod + mod) % mod;
                cout << ans << endl;
                return 0;
            }
            long long jj = qm(a, t * k) - qm(b, t * k);
            jj = x * jj % mod;
            jj = jj * qm(a, k) % mod;
            ;
            jj = jj % mod;
            long long nn = (qm(a, k) - qm(b, k));
            nn = nn % mod;
            nn = nn * qm(a, t * k);
            nn = nn % mod;
            nn = qm(nn, mod - 2);
            ans = jj * nn;
            ans = (ans % mod + mod) % mod;
            for (long long hh = 0; hh < g; hh++) {
                if (c[hh] == '-') {
                    ans = ans - qm(a, n - (t * k + hh)) * qm(b, (t * k + hh));
                    ans = (ans % mod + mod) % mod;
                } else {
                    ans = ans + qm(a, n - (t * k + hh)) * qm(b, (t * k + hh));
                    ans = (ans % mod + mod) % mod;
                }
            }
            ans = (ans % mod + mod) % mod;
            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]:
make ints n, a, b, and k
let int array s of size 100000
let string inp
make map dp from ints and ints
declare bpow taking in ints n and e and returning integer
    create integer array b of size 30
    set b[0] to n
    for i = 1 to 30 exclusive, set b[i] to ((long long)b[i - 1] * b[i - 1]) % 1000000009
    make integer ans = 1
    for i = 0 to 30 exclusive
        if e & (1 << i) are truthy set ans to ((long long)ans * b[i]) % 1000000009
    return ans
end of the block
declare bdiv taking in integers n and d and returning integer
    return the result of ((long long)n * bpow(d, 1000000009 - 2)) % 1000000009
end of the block
declare alt taking in int e and returning int
    if e % k is not 0, end function
    if dp.count(e) is falsy
        if e is 0
            end function
        else if e is k
            set dp[e] to 1
        else do
            create int l = e / 2 / k * k
            make integer r = e - 1
            let integer ans = (((long long)alt(l) * bpow(a, r)) + (long long)alt(r) * bpow(b, l)) % 1000000009
            set dp[e] to ans
        end of the block
    end of the block
    return dp[e]
end of the block
define the main function
    read n, a, b, and k
    read inp
    for i = 0 to k exclusive
        if inp[i] is '+'
            set s[i] to 1
        else do
            set s[i] to -1
    end of the block
    create int x = 0
    for i = 0 to k exclusive
        create integer toadd = ((long long)s[i] * bpow(a, k - 1 - i)) % 1000000009
        set toadd to ((long long)toadd * bpow(b, i)) % 1000000009
        set x to ((long long)x + toadd + 1000000009) % 1000000009
    end of the block
    display x, " ", and alt(n + 1) to error
    create integer ans = ((long long)x * alt(n + 1)) % 1000000009
    display ans
end of the block

[CODE]:

int n, a, b, k;
int s[100000];
string inp;
map<int, int> dp;
int bpow(int n, int e) {
    int b[30];
    b[0] = n;
    for (int i = 1; i < 30; i++) b[i] = ((long long)b[i - 1] * b[i - 1]) % 1000000009;
    int ans = 1;
    for (int i = 0; i < 30; i++)
        if (e & (1 << i)) ans = ((long long)ans * b[i]) % 1000000009;
    return ans;
}
int bdiv(int n, int d) {
    return ((long long)n * bpow(d, 1000000009 - 2)) % 1000000009;
}
int alt(int e) {
    assert(e % k == 0);
    if (!dp.count(e)) {
        if (e == 0)
            assert(0);
        else if (e == k)
            dp[e] = 1;
        else {
            int l = e / 2 / k * k;
            int r = e - l;
            int ans = (((long long)alt(l) * bpow(a, r)) + (long long)alt(r) * bpow(b, l)) % 1000000009;
            dp[e] = ans;
        }
    }
    return dp[e];
}
int main() {
    cin >> n >> a >> b >> k;
    cin >> inp;
    for (int i = 0; i < k; i++) {
        if (inp[i] == '+')
            s[i] = 1;
        else
            s[i] = -1;
    }
    int x = 0;
    for (int i = 0; i < k; i++) {
        int toadd = ((long long)s[i] * bpow(a, k - 1 - i)) % 1000000009;
        toadd = ((long long)toadd * bpow(b, i)) % 1000000009;
        x = ((long long)x + toadd + 1000000009) % 1000000009;
    }
    cerr << x << " " << alt(n + 1) << endl;
    int ans = ((long long)x * alt(n + 1)) % 1000000009;
    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]:
declare long long MOD = 1000000009
declare pw with long longs a, b as arguments, returning long long
    if b is 0, return 1 from function
    if b is 1, return a % MOD
    if b % 2
        declare long long rs = result of run pw ( a, b - 1 )
        return ( rs * a ) % MOD from function
    end of the block
    declare long long rs = result of run w with a, b / 2 as arguments
    return ( rs * rs ) % MOD
end of the block
declare long long vector sm
declare solve with long longs a, b as arguments, returning long long
    if b is 0, return 0 from function
    for i = 0 to 35 exclusive
        declare long long ba = (1LL bitshift left i ) bitwise and b
        if ba is 0, end current loop iteration
        return ( sm[i] + result of run solve( a, b - ( 1LL bitshift left i )) * result of run pw(a, (1LL bitshift left i))) % MOD
    end of the block
end of the block
define the main function
    declare long longs n, a, b, k
    read n, a, b, k
    declare string s
    read s
    declare long long X = 1, y + 1
    for i = 0 to k exclusive
        let X be X * b
        let X be X % MOD
    end of the block
    for i = 0 to k exclusive
        let Y be Y * a
        let Y be Y % MOD
    end of the block
    let X be X * result of run pw(Y, MOD - 2)
    let X be X % MOD
    add 1 to end of sm
    for i = 0 to 40 exclusive
        add ( back of sm + back of sm * result of run pw(X, (1LL bitshift left i) ) to end of sm
        let back of sm be back of sm % MOD
    end of the block
    declare long long st = result of run solve(X, (n + 1) / k)
    declare long long ans = 0
    for i = 0 to k exclusive
        declare long long rs = (result of run pw(b,i) * result of run pw(a,n-1) ) % MOD
        if s[i] is '-', let rs be rs * -1
        let rs be rs * st
        increment ans by rs
        let ans be ans % MOD
    end of the block
    if ans is less than 0, increment ans by MOD
    print ans and newline
end of the block

[CODE]:

long long MOD = 1000000009;
long long pw(long long a, long long b) {
    if (b == 0) return 1;
    if (b == 1) return a % MOD;
    if (b % 2) {
        long long rs = pw(a, b - 1);
        return (rs * a) % MOD;
    }
    long long rs = pw(a, b / 2);
    return (rs * rs) % MOD;
}
vector<long long> sm;
long long solve(long long a, long long b) {
    if (b == 0) return 0;
    for (long long i = 0; i < 35; i++) {
        long long ba = (1LL << i) & b;
        if (ba == 0) continue;
        return (sm[i] + solve(a, b - (1LL << i)) * pw(a, (1LL << i))) % MOD;
    }
}
int main() {
    long long n, a, b, k;
    cin >> n >> a >> b >> k;
    string s;
    cin >> s;
    long long X = 1, Y = 1;
    for (long long i = 0; i < k; i++) {
        X *= b;
        X %= MOD;
    }
    for (long long i = 0; i < k; i++) {
        Y *= a;
        Y %= MOD;
    }
    X *= pw(Y, MOD - 2);
    X %= MOD;
    sm.push_back(1);
    for (long long i = 0; i < 40; i++) {
        sm.push_back(sm.back() + sm.back() * pw(X, (1LL << i)));
        sm.back() %= MOD;
    }
    long long st = solve(X, (n + 1) / k);
    long long ans = 0;
    for (long long i = 0; i < k; i++) {
        long long rs = (pw(b, i) * pw(a, n - i)) % MOD;
        if (s[i] == '-') rs *= -1;
        rs *= st;
        ans += rs;
        ans %= MOD;
    }
    if (ans < 0) ans += MOD;
    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 long long integer MOD = 1000000009
into the function pw which takes two long long integers a and b and returns a long long integer
    if b is 0 then return 1
    if b is 1 then return a % MOD
    if b%2 is true
        create long long rs= pw(a,b-1)
        return (rs * a) % MOD
    end of the block
    create long long integer rs= pw(a,b/2)
    return (rs * rs) % MOD
end of the block
sm = long long integer vector
into the function solve which takes a and b
    if b is 0 then return 0
    for i=0 to 35 exclusive
        create long long integer ba = (1LL << i) & b
        if ba is equal to 0 then continue
        return sm[i] + solve(a, b - (1LL << i)) * pw(a, (1LL << i))) % MOD
    end of the block
end of the block
define the main function
    n,a,b,k = long long integers
    read n,a,b,k
    s=string
    read s
    create long long integers X and Y with values 1
    for i=o to k exclusive
        set X = X * b
        set X = X % MOD
    end of the block
    for i=0 to k exclusive
        set Y = Y * a
        set Y = Y % MOD
    end of the block
    set X = X * pw(Y, MOD - 2)
    set X = X % MOD
    add 1 to the end of sm
    for i=0 to 40 exclusive
        add sm.back() + sm.back() * pw(X, (1LL << i) to end of sm
        set sm.back() = sm.back() % MOD
    end of the block
    create long long integer st = solve(X, (n + 1) / k)
    create long long integer ans=0
    for i=0 to k exclusive
        create long long integer rs = (pw(b, i) * pw(a, n - i)) % MOD
        if s[i] is '-' then set rs = rs * -1
        set rs = rs * st
        set ans = ans + rs
        set ans = ans % MOD
    end of the block
    if ans is less than 0 then set ans = ans + MOD
    print ans
end of the block

[CODE]:


[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 long longs A, B, ans with ans = -0x7fffffff
create long longs bxb, bex, bob, bpb
define the main function
    read A read B
    if B is 0
        print A * A print newline
        for i = 0 to A exclusive print "o"
        print newline
        return to indicate successful execution
    end of the block
    if B is 1
        print A * A - 1 print newline
        for i = 0 to A exclusive, print "o"
        print "x" print newline
        return to indicate successful execution
    end of the block
    if A is 0
        print -B * B print newline
        for i = 0 to B exclusive, print "x'
        print newline
        return to indicate successful execution
    end of the block
    for xb = 2 to minimum of (B and A + 1) inclusive
        create integer ob with ob = xb - 1
        create long long score with score = ob - 1
        increment score by (A - (ob - 1)) * (A - (ob - 1))
        end statement
        create long long pb with pb = B / xb
        create long long ex with ex = B % xb
        decrement score by ( xb - ex ) * pb * pb
        decrement score by ex * ( pb + 1 ) * ( pb + 1 )
        if score is greater than ans
            set ans to score
            set bxb to xb
            set bex to ex
            set bob to ob
            set bpb to pb
        end of the block
    end of the block
    print ans print newline
    for i = 0 to bxb exclusive
        for j = 0 to bpb exclusive, print "x"
        if i is less than bex, print "x"
        if i is 0
            for j = 0 to A - ( bob - 1 ) exclusive, print "o"
        else if i + 1 is less than bxb
            print "o"
    end of the block
    print newline
    return to indicate successful execution
end of the block

[CODE]:

long long A, B, ans = -0x7fffffff;
long long bxb, bex, bob, bpb;
int main() {
    cin >> A >> B;
    if (B == 0) {
        cout << A * A << endl;
        for (int i = 0; i < A; i++) cout << "o";
        cout << endl;
        return 0;
    }
    if (B == 1) {
        cout << A * A - 1 << endl;
        for (int i = 0; i < A; i++) cout << "o";
        cout << "x" << endl;
        return 0;
    }
    if (A == 0) {
        cout << -B * B << endl;
        for (int i = 0; i < B; i++) cout << "x";
        cout << endl;
        return 0;
    }
    for (int xb = 2; xb <= min(B, A + 1); xb++) {
        int ob = xb - 1;
        long long score = ob - 1;
        score += (A - (ob - 1)) * (A - (ob - 1));
        ;
        long long pb = B / xb;
        long long ex = B % xb;
        score -= (xb - ex) * pb * pb;
        score -= ex * (pb + 1) * (pb + 1);
        if (score > ans) {
            ans = score;
            bxb = xb;
            bex = ex;
            bob = ob;
            bpb = pb;
        }
    }
    cout << ans << endl;
    for (int i = 0; i < bxb; i++) {
        for (int j = 0; j < bpb; j++) cout << "x";
        if (i < bex) cout << "x";
        if (i == 0)
            for (int j = 0; j < A - (bob - 1); j++) cout << "o";
        else if (i + 1 < bxb)
            cout << "o";
    }
    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]:
declare integer variables co and cx
create const long long inf = -1e16
inlined long long function gox with int argument num
    return inf if num is greater than cx
    declare int ex = cx % num
    declare int variable anch = cx / num
    declare long long variable ans = 1LL * (anch + 1) * (anch + 1) * ex
    increase ans by 1LL * anch * anch * (num - ex)
    return -ans
end of the block
inlined long long function goo with int argument num
    if num is greater than co
    declare int variable juntos = co - num + 1
    create long long ans = 1LL * juntos * juntos
    increase ans by num - 1
    return ans
end of the block
inlined void function build with int arguments x and o
    create string s
    declare integer xx = cx / x
    create bool flag = true if x > o, else false
    declare bool variable fst = true
    create integer ex = cx % x
    declare integer prim = co - o + 1
    while either x or o is true
        if flag is true
            push 'x' into s xx times
            if ex is greater than 0, push 'x' into s and decrement ex
            decrement x
        else
            if fst is true
                push 'o' into s prim times
                set fst to false
            else
                push 'o' into s
            decrement o
        end of the block
        invert the value of flag
    end of the block
    print s
end of the block
define the main function
    read co and cx
    if co is 0 or cx is 0
        if co is greater than 0
            print 1LL * co * co
            print 'o' co times
            print a new line
        end of the block
        if cx is greater than 0
            print - 1LL * cx * cx
            print 'x' cx times
            print
        end of the block
        return to indicate successful execution
    end of the block
    declare int lim = min of co and cx
    create long long ans = LLONG_MIN
    pos is a pair of integers
    for integer i = 1 to lim + 1 exclusive
        if ans is less than gox(i) + goo(i)
            assign gox(i) + goo(i) to ans
            pos = {i, i}
        end of the block
    end of the block
    for i = 2 to cx + 1 exclusive
        if ans is less than gox(i) + goo(i - 1)
            change ans to gox(i) + goo(i - 1)
            pos = {i, i - 1}
        end of the block
    end of the block
    for i = 2 to co + 1 exclusive
        if ans is less than gox(i - 1) + goo(i)
            set ans to gox(i - 1) + goo(i)
            pos = {i - 1, i}
        end of the block
    end of the block
    print ans
    call build with arguments pos.first and pos.second
    return to indicate successful execution
end of the block

[CODE]:

int co, cx;
const long long inf = -1e16;
inline long long gox(int num) {
    if (num > cx) return inf;
    int ex = cx % num;
    int anch = cx / num;
    long long ans = 1LL * (anch + 1) * (anch + 1) * ex;
    ans += 1LL * anch * anch * (num - ex);
    return -ans;
}
inline long long goo(int num) {
    if (num > co) return inf;
    int juntos = co - num + 1;
    long long ans = 1LL * juntos * juntos;
    ans += num - 1;
    return ans;
}
inline void build(int x, int o) {
    string s;
    int xx = cx / x;
    bool flag = (x > o);
    bool fst = true;
    int ex = cx % x;
    int prim = co - o + 1;
    while (x || o) {
        if (flag) {
            for (int i = int(0); i < int(xx); ++i) s.push_back('x');
            if (ex > 0) s.push_back('x'), ex--;
            x--;
        } else {
            if (fst) {
                for (int i = int(0); i < int(prim); ++i) s.push_back('o');
                fst = false;
            } else
                s.push_back('o');
            o--;
        }
        flag = (!flag);
    }
    cout << s << endl;
}
int main() {
    cin >> co >> cx;
    if (co == 0 || cx == 0) {
        if (co > 0) {
            cout << 1LL * co * co << endl;
            for (int i = int(0); i < int(co); ++i) cout << 'o';
            cout << endl;
        }
        if (cx > 0) {
            cout << -1LL * cx * cx << endl;
            for (int i = int(0); i < int(cx); ++i) cout << 'x';
            cout << endl;
        }
        return 0;
    }
    int lim = min(co, cx);
    long long ans = LLONG_MIN;
    pair<int, int> pos;
    for (int i = int(1); i < int(lim + 1); ++i) {
        if (ans < gox(i) + goo(i)) {
            ans = gox(i) + goo(i);
            pos = {i, i};
        }
    }
    for (int i = int(2); i < int(cx + 1); ++i) {
        if (ans < gox(i) + goo(i - 1)) {
            ans = gox(i) + goo(i - 1);
            pos = {i, i - 1};
        }
    }
    for (int i = int(2); i < int(co + 1); ++i) {
        if (ans < gox(i - 1) + goo(i)) {
            ans = gox(i - 1) + goo(i);
            pos = {i - 1, i};
        }
    }
    cout << ans << endl;
    build(pos.first, pos.second);
    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 long a and b
    read a,b
    if a equal to 0
        print -1 * b * b
        for i=0 to b exclusive, print x
        print a newline
    else if b = 0
        print a * a
        for i=0 to a exclusive, print o
        print a newline
    else if b equal to 1
        print a*a -1
        for i=0 to a exclusive, print o
        print x
        print a newline
    else
        ser ret to LLONG_MIN
        set foo=0
        for j=1 to min of b-1 and a
            assign (a - j + 1) * (a - j + 1) + (j - 1) to pos
            set q = b / (j + 1) and r to b % (j + 1)
            set neg = r * (q + 1) * (q + 1) + (j + 1 - r) * q * q
            if pos - neg greater than ret
                ret = pos - neg
                assign j + 1 to foo
            end of the block
        end of the block
        print ret
        set q = b / foo, r = b % foo
        assign (a - (foo - 1) + 1) to g
        for j=1 to foo + 1 exclusive
            for i=0 to q exclusive, print x
            if <= r, print x
            if j different from foo
                if j equal to 1
                    for i=0 to g exclusive, print o
                else
                    print o
            end of the block
        end of the block
        print a newline
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    long long a, b;
    cin >> a >> b;
    if (a == 0) {
        cout << -1 * b * b << endl;
        for (int(i) = (0); (i) < (b); ++(i)) cout << 'x';
        cout << endl;
    } else if (b == 0) {
        cout << a * a << endl;
        for (int(i) = (0); (i) < (a); ++(i)) cout << 'o';
        cout << endl;
    } else if (b == 1) {
        cout << a * a - 1 << endl;
        for (int(i) = (0); (i) < (a); ++(i)) cout << 'o';
        cout << 'x';
        cout << endl;
    } else {
        long long ret = LLONG_MIN;
        long long foo = 0;
        for (long long j = 1; j <= min(b - 1, a); j++) {
            long long pos = (a - j + 1) * (a - j + 1) + (j - 1);
            long long q = b / (j + 1), r = b % (j + 1);
            long long neg = r * (q + 1) * (q + 1) + (j + 1 - r) * q * q;
            if (pos - neg > ret) {
                ret = pos - neg;
                foo = j + 1;
            }
        }
        cout << ret << endl;
        long long q = b / foo, r = b % foo;
        long long g = (a - (foo - 1) + 1);
        for (int(j) = (1); (j) < (foo + 1); ++(j)) {
            for (int(i) = (0); (i) < (q); ++(i)) cout << 'x';
            if (j <= r) cout << 'x';
            if (j != foo) {
                if (j == 1)
                    for (int(i) = (0); (i) < (g); ++(i)) cout << 'o';
                else
                    cout << 'o';
            }
        }
        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 integers flag, gender, ok, t and cnt
cal is a new array of integers with size 10005
declare new string variable s
create an arrays of strings x with 6 elements = "lios", "liala", "etr", "etra", "initis", "inites", and y wth 10005 elements
function cmp with string arguments a and b that returns integer
    define integer variables len1 = length of a, and len2 = length of b
    in a for loop, change i from 0 to len2 exclusive
        if a[len1 - len2 + i] != b[i], return 0
    return 1
end of the block
function over with string argument s
    print s
    terminate the process
end of the block
define the main function
    create new integer called cnt with value 0
    loop, reading s from the input
        increment cnt by one
        change the value of y[cnt] to s
        change flag to 0
        in a for loop, change i from 0 to 6 exclusive
            if cmp(y[cnt], x[i]) returned true
                change flag to 1
                change the value of cal[cnt] to i
            end of the block
        if flag = 0, call over("NO")
        if character from the input is equal to '\n', stop the loop
    end of the block
    if cnt = 1, call over("YES")
    start for loop from i = 1 to cnt exclusive
        if cal[i] % 2 != cal[i + 1] % 2 || cal[i] > cal[i + 1], call over("NO")
    change flag to 0
    for integer i = 1 to cnt inclusive incrementing i
        if cal[i] / 2 = 1, increment flag by one
    if flag != 1, call over("NO")
    call over("YES")
    return to indicate successful execution
end of the block

[CODE]:

int flag, gender, ok, t, cnt;
int cal[10005];
string s;
string x[6] = {"lios", "liala", "etr", "etra", "initis", "inites"}, y[10005];
int cmp(string a, string b) {
    int len1 = a.size(), len2 = b.size();
    for (int i = 0; i < len2; i++)
        if (a[len1 - len2 + i] != b[i]) return 0;
    return 1;
}
void over(string s) {
    cout << s << endl;
    exit(0);
}
int main() {
    int cnt = 0;
    while (cin >> s) {
        cnt++;
        y[cnt] = s;
        flag = 0;
        for (int i = 0; i < 6; i++)
            if (cmp(y[cnt], x[i])) {
                flag = 1;
                cal[cnt] = i;
            }
        if (flag == 0) over("NO");
        if (cin.get() == '\n') break;
    }
    if (cnt == 1) over("YES");
    for (int i = 1; i < cnt; i++)
        if (cal[i] % 2 != cal[i + 1] % 2 || cal[i] > cal[i + 1]) over("NO");
    flag = 0;
    for (int i = 1; i <= cnt; i++)
        if (cal[i] / 2 == 1) flag++;
    if (flag != 1) over("NO");
    over("YES");
    return 0;
}

i i i i i i i i i i i i i i i a a a a a a v v v v v v v v v v v

fbvzqonvdlqdanwliolaqfj sbauorbinites xkbfnfinitespjy phbexglblzpobtqpisyijycmtliola aosinites lbpjiwcjoqyuhglthloiniteswb mjtxhoofohzzgefvhsywojcuxtetxmojrlktodhbgyrkeejgjzxkzyvrxwmyaqkeoqnvusnlrsfffrzeoqjdfumolhksqkrtzwhnforgpenziokrxlnhcapbbupctlmuetrani pigxerwetupjbkvlmgnjhdfjliolanz tqhaidxbqmdaeincxjuliola

hnwvfllholxfialiola cknjtxpliola daliola gqfapnhmmworliola qhetra qrisbexsrefcwzoxqwxrevinites wwldqkqhvrgwplqinites nqdpoauitczttxoinites fgbmdfpxkhahkinites

lios petr initisandinitisandliala petrainitis


[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 int variables flag, gender, ok, t and cnt
declare new string called s
define new array of strings filled with elements "lios", "liala", "etr", "etra", "initis" and "inites"
integer function cmp with string arguments a and b
    define integers len1 = length of a, and lent2 = length of b
    start for loop from i = 0 to len2 exclusive
        return 0 if a[len1 - len2 + i] != b[i]
    end of the block
    return 1
end of the block
define the main function
    assign the new value = 3 to gender
    read s and keep looping
        set ok to 0
        for integer i = 0 to 6 exclusive incrementing i
            if cmp(s, x[i]) is not 0
                assign 1 to ok
                increment cnt by one
                if gender = 3
                    set the value of gender to i modulo 2
                else if i % 2 != gender
                    print "NO"
                    return to indicate successful execution
                end of the block
                assign the new value = i / 2 + 1 to t
                if t is equal to 1 and flag = 0
                    change flag to 1
                else if t and flag are both 1
                    change flag to 1
                else if t is equal to 2 and flag is equal to 1
                    set the value of flag to 2
                else if t is equal to 2 and flag = 0
                    assign the new value = 2 to flag
                else if t is equal to 3 and flag = 0
                    assign the new value = -1 to flag
                else if t is equal to 3 and flag = 2
                    set the value of flag to 3
                else if t and flag are both equal to 3
                    change flag to 3
                else
                    print "NO"
                    return to indicate successful execution
                end of the block
            end of the block
        end of the block
        if ok is equal to 0
            print "NO"
            return to indicate successful execution
        end of the block
        if character from the input is equal to '\n', break the loop
    end of the block
    if flag = 1 and cnt > 1
        print "NO"
    else
        print "YES"
    return to indicate successful execution
end of the block

[CODE]:

int flag, gender, ok, t, cnt;
string s;
string x[6] = {"lios", "liala", "etr", "etra", "initis", "inites"};
int cmp(string a, string b) {
    int len1 = a.size(), len2 = b.size();
    for (int i = 0; i < len2; i++) {
        if (a[len1 - len2 + i] != b[i]) return 0;
    }
    return 1;
}
int main() {
    gender = 3;
    while (cin >> s) {
        ok = 0;
        for (int i = 0; i < 6; i++) {
            if (cmp(s, x[i])) {
                ok = 1;
                cnt++;
                if (gender == 3)
                    gender = i % 2;
                else if (i % 2 != gender) {
                    cout << "NO" << endl;
                    return 0;
                }
                t = i / 2 + 1;
                if (t == 1 && flag == 0)
                    flag = 1;
                else if (t == 1 && flag == 1)
                    flag = 1;
                else if (t == 2 && flag == 1)
                    flag = 2;
                else if (t == 2 && flag == 0)
                    flag = 2;
                else if (t == 3 && flag == 0)
                    flag = -1;
                else if (t == 3 && flag == 2)
                    flag = 3;
                else if (t == 3 && flag == 3)
                    flag = 3;
                else {
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        if (ok == 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (cin.get() == '\n') break;
    }
    if (flag == 1 && cnt > 1)
        cout << "NO" << endl;
    else
        cout << "YES" << 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 to_num which takes a string s and returns an integer
    if size of s is greater than or equal to 4
        if s.substr(s.size() - 4) = "lios" then return 0
    end of the block
    if size of s >= 5
        if s.substr(s.size() - 5) = "liala" then return 1
    end of the block
    if size of s >= 3
        if s.substr(s.size() - 3) = "etr" then return 2
    end of the block
    if size of s >= 4
        if s.substr(s.size() - 4) = "etra" then return 3
    end of the block
    if size of s >=6
        if s.substr(s.size() - 6) = "initis" then return 4
    end of the block
    if size of s >= 6
        if s.substr(s.size() - 6) = "inites" then return 5
    end of the block
    return -1
end of the block
in the function islegal which takes a integer vector ans and returns a boolean
    if ans[0] % 2 is equal to 0
        for i=1 to size of ans exclusive
            if ans[i] % 2 is not equal to 0 then return false
    else do the following
        for i=1 to size of ans exclusive
            if ans[i] is equal to -1 then return false
            if ans[i] % 2 = 0 then return false
        end of the block
    end of the block
    return true
end of the block
in the function isok which takes an integer vector ans and returns a boolean
    create a boolean f = false
    for i=0 to size of ans exclusive
        if ans[i]/2 is equal to 0 and f is false
            set f to true
            continue
        end of the block
        if f is false
            if ans[i]/2 is not equal to 0 then return false
        else do the following
            if ans[i]/2 is not equal to 2 then return false
        end of the block
    end of the block
    if f is false then return false
    return true
end of the block
define the main function
    c=array of chars of size 100010
    s= string
    res= vector of string
    ans = vector of integer
    create an integer pos=0
    read c
    set s=c
    for i=0 to size of s exclusive
        if s[i] is empty
            add s.substr(pos, i - pos) to the end of res
            set pos to i+1
        end of the block
    add s.substr(pos) to end of res
    for i=0 to size of res exclusive add to_num(res[i] to end of ans
    if size of ans is equal to 1 and asn[0] >=0
        print YES
        return to indicate successful execution
    end of the block
    if islegal(ans) is true
        if isok(ans)is true
            print YES
        else do the following
            print NO
    else do the following
        print NO
    return to indicate successful execution
end of the block

[CODE]:

int to_num(string s) {
    if (s.size() >= 4) {
        if (s.substr(s.size() - 4) == "lios") return 0;
    }
    if (s.size() >= 5) {
        if (s.substr(s.size() - 5) == "liala") return 1;
    }
    if (s.size() >= 3) {
        if (s.substr(s.size() - 3) == "etr") return 2;
    }
    if (s.size() >= 4) {
        if (s.substr(s.size() - 4) == "etra") return 3;
    }
    if (s.size() >= 6) {
        if (s.substr(s.size() - 6) == "initis") return 4;
    }
    if (s.size() >= 6) {
        if (s.substr(s.size() - 6) == "inites") return 5;
    }
    return -1;
}
bool islegal(vector<int> ans) {
    if (ans[0] % 2 == 0) {
        for (int i = 1; i < ans.size(); i++)
            if (ans[i] % 2 != 0) return false;
    } else {
        for (int i = 0; i < ans.size(); i++) {
            if (ans[i] == -1) return false;
            if (ans[i] % 2 == 0) return false;
        }
    }
    return true;
}
bool isok(vector<int> ans) {
    bool f = false;
    for (int i = 0; i < ans.size(); i++) {
        if ((ans[i] / 2) == 1 && !f) {
            f = true;
            continue;
        }
        if (!f) {
            if (ans[i] / 2 != 0) return false;
        } else {
            if (ans[i] / 2 != 2) return false;
        }
    }
    if (!f) { return false; }
    return true;
}
int main() {
    char c[100010];
    string s;
    vector<string> res;
    vector<int> ans;
    int pos = 0;
    gets(c);
    s = c;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == ' ') {
            res.push_back(s.substr(pos, i - pos));
            pos = i + 1;
        }
    res.push_back(s.substr(pos));
    for (int i = 0; i < res.size(); i++) ans.push_back(to_num(res[i]));
    if (ans.size() == 1 && ans[0] >= 0) {
        puts("YES");
        return 0;
    }
    if (islegal(ans)) {
        if (isok(ans))
            puts("YES");
        else
            puts("NO");
    } else
        puts("NO");
    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]:
ip, ip2 and n are ints with ip and ip2 = 0
declare vector of integers called v
s is a new array of characters with 100010 elements
in the function next_token that returns boolean
    set the value of ip to ip2
    while ip < n and (s[ip] < 'a' or s[ip] > 'z')
    if ip is equal to n, return false
    change ip2 to ip
    while ip2 < n and s[ip2] >= 'a' and s[ip2] <= 'z'
    return true
end of the block
declare character z
function get_type that returns integer
    define new integer len with value ip2-ip
    change z to s[ip2]
    assign the new value = 0 to s[ip2]
    if s + ip + len - 4 matches "lios", return 0
    if result of s + ip + len - 5 = "liala" return 1
    if s + ip + len - 3 matches "etr" return 10
    if strcmp(s + ip + len - 4,"etra") returns 0, return 11
    if comparison of s + ip + len - 6 with "initis" returns 0, return 20
    return 21 if s + ip + len - 6 matches "inites"
    return -1
end of the block
boolean function solve
    in a for loop, change i from 0 to length of v exclusive
        if v[i] is equal to -1, return false
    return true if length of v = 1
    start for loop from i = 0 to length of v exclusive incrementing i
        in a for loop, change j from 0 to i exclusive
            return false if v[i] % 10 != v[j] % 10
    start for loop from i = 0 to length of v - 1 exclusive incrementing i
        if v[i] is greater than v[i + 1], return false
    create new integer cnt = 0
    increment i in a loop from i = 0 to length of v exclusive
        if v[i] / 10 = 1, increment cnt
    if cnt is equal to 1
        return true
    else
        return false
end of the block
define the main function
    store input into s
    change n to length of s
    while next_token() returns true
        push new value = the result of get_type() into v
        change s[ip2] to z
    end of the block
    if call to solve() returned true
        print "YES"
    else
        print "NO" to standard output
    return to indicate successful execution
end of the block

[CODE]:

int ip = 0, ip2 = 0, n;
vector<int> v;
char s[100010];
bool next_token() {
    ip = ip2;
    while (ip < n && (s[ip] < 'a' || s[ip] > 'z')) ip++;
    if (ip == n) return false;
    ip2 = ip;
    while (ip2 < n && s[ip2] >= 'a' && s[ip2] <= 'z') ip2++;
    return true;
}
char z;
int get_type() {
    int len = ip2 - ip;
    z = s[ip2];
    s[ip2] = 0;
    if (strcmp(s + ip + len - 4, "lios") == 0) return 0;
    if (strcmp(s + ip + len - 5, "liala") == 0) return 1;
    if (strcmp(s + ip + len - 3, "etr") == 0) return 10;
    if (strcmp(s + ip + len - 4, "etra") == 0) return 11;
    if (strcmp(s + ip + len - 6, "initis") == 0) return 20;
    if (strcmp(s + ip + len - 6, "inites") == 0) return 21;
    return -1;
}
bool solve() {
    for (int i = 0; i < v.size(); i++)
        if (v[i] == -1) return false;
    if (v.size() == 1) return true;
    for (int i = 0; i < v.size(); i++)
        for (int j = 0; j < i; j++)
            if (v[i] % 10 != v[j] % 10) return false;
    for (int i = 0; i < v.size() - 1; i++)
        if (v[i] > v[i + 1]) return false;
    int cnt = 0;
    for (int i = 0; i < v.size(); i++)
        if (v[i] / 10 == 1) cnt++;
    if (cnt == 1)
        return true;
    else
        return false;
}
int main() {
    gets(s);
    n = strlen(s);
    while (next_token()) {
        v.push_back(get_type());
        s[ip2] = z;
    }
    if (solve())
        puts("YES");
    else
        puts("NO");
    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 N = 1e5 + 7
declare constant string array s = {"lios", "liala", "etr", "etra", "initis", "inites"}
declare map from string to integer mp
declare string array h size N
declare integer a size N
declare inline get_s with string address s as argument, returning integer
    if size of s is less than 3, return 0 from function
    for i = 3 to 6 inclusive
        if i is greater than size of s, return 0 from function
        if first index of ( substring of s from size of s - i to i ) in mp is not end of mp, return mp[substring of s from size of s - i to i]
    end of the block
    return to indicate successful execution
end of the block
define the main function
    declare integer cnt = 0
    for i = 0 to 6 exclusive, let mp[s[i]] be i + 1
    while ( read h[cnt] ), increment cnt
    declare booleans f1 = 0, f2 = 0
    for i = 0 to cnt exclusive
        let a[i] be result of run get_s(h[i])
        if not a[i], return 0 * print "NO"
        let f1 be f1 bitwise or (bitwise and 1 ), let f2 be f2 bitwise or ( bitwise not a[i] bitwise and 1 )
    end of the block
    if cnt is 1, return 0 * print "YES"
    if f1 and f2, return 0 * print "NO"
    for i = 0 to cnt exclusive, increment a[i] by 1, let a[i] be a[i] bitshift right 1
    declare integer p = 0
    while p is less than cnt - 1 and a[p] is a[p+1] and a[p] is 1, increment p
    if a[p] is 1
        increment p
    else if a[p] is 3
        return 0 * print "NO"
    if a[p] is not 2
        return 0 * print "NO"
    else
        increment p
    while p is less than cnt
        if a[increment p] is not 3, return 0 * print "NO"
    if a[increment p] is not 3, return 0 * print "NO"
    return to indicate successful execution
end of the block

[CODE]:

const int N = 1e5 + 7;
const string s[] = {"lios", "liala", "etr", "etra", "initis", "inites"};
map<string, int> mp;
string h[N];
int a[N];
inline int get_s(string &s) {
    if (s.size() < 3) return 0;
    for (int i = 3; i <= 6; i++) {
        if (i > s.size()) return 0;
        if (mp.find(s.substr(s.size() - i, i)) != mp.end()) return mp[s.substr(s.size() - i, i)];
    }
    return 0;
}
int main() {
    int cnt = 0;
    for (int i = 0; i < 6; i++) mp[s[i]] = i + 1;
    while (cin >> h[cnt]) cnt++;
    bool f1 = 0, f2 = 0;
    for (int i = 0; i < cnt; i++) {
        a[i] = get_s(h[i]);
        if (!a[i]) return 0 * puts("NO");
        f1 |= a[i] & 1, f2 |= ~a[i] & 1;
    }
    if (cnt == 1) return 0 * puts("YES");
    if (f1 && f2) return 0 * puts("NO");
    for (int i = 0; i < cnt; i++) (a[i] += 1) >>= 1;
    int p = 0;
    while (p < cnt - 1 && a[p] == a[p + 1] && a[p] == 1) p++;
    if (a[p] == 1)
        p++;
    else if (a[p] == 3)
        return 0 * puts("NO");
    if (a[p] != 2)
        return 0 * puts("NO");
    else
        p++;
    while (p < cnt)
        if (a[p++] != 3) return 0 * puts("NO");
    puts("YES");
    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]:
make string vector word
make integer vector be and af
create int set g
declare sf taking in string s and returning int
    make int n = s.size()
    if n is greater than or equal to 4 and s.substr(n - 4, 4) is equal to "lios"
        return to indicate successful execution
    else if n is greater than 5 and s.substr(n - 5, 5) is equal to "liala"
        return 1
    else if n is greater than or equal to 3 and s.substr(n - 3, 3) is equal to "etr"
        return 2
    else if n is greater than or equal to 4 and s.substr(n - 4, 4) is equal to "etra"
        return 3
    else if n is greater than or equal to 6 and s.substr(n - 6, 6) equals "initis"
        return 4
    else if n is greater than or equal to 6 and s.substr(n - 6, 6) equals "inites"
        return 5
    else do
        return -1
    end of the block
end of the block
define the main function
    make string s
    read s and while it's truthy, append s to word
    for i = 0 to size of word exclusive
        make integer j = sf(word[i])
        if j is equal to -1
            print "NO"
            return to indicate successful execution
        end of the block
        insert j % 2 to g
        append j / 2 to be
        append j / 2 to af
    end of the block
    if size of word is 1
        print "YES"
        return to indicate successful execution
    end of the block
    sort af
    if g.size() is not 1
        print "NO"
        return to indicate successful execution
    end of the block
    make integer cnt = 0
    for i = 0 to af.size() exclusive
        if af[i] is not equal to be[i]
            show "NO"
            return to indicate successful execution
        end of the block
        if af[i] is equal to 1, increment cnt
    end of the block
    if cnt is equal to 0 and size of word is not equal to 1
        show "NO"
        return to indicate successful execution
    else if cnt is not 1 and cnt is not 0
        display "NO"
        return to indicate successful execution
    end of the block
    output "YES"
    return to indicate successful execution
end of the block

[CODE]:

vector<string> word;
vector<int> be, af;
set<int> g;
int sf(string s) {
    int n = s.size();
    if (n >= 4 && s.substr(n - 4, 4) == "lios") {
        return 0;
    } else if (n >= 5 && s.substr(n - 5, 5) == "liala") {
        return 1;
    } else if (n >= 3 && s.substr(n - 3, 3) == "etr") {
        return 2;
    } else if (n >= 4 && s.substr(n - 4, 4) == "etra") {
        return 3;
    } else if (n >= 6 && s.substr(n - 6, 6) == "initis") {
        return 4;
    } else if (n >= 6 && s.substr(n - 6, 6) == "inites") {
        return 5;
    } else {
        return -1;
    }
}
int main() {
    string s;
    while (cin >> s) { word.push_back(s); }
    for (int i = 0; i < word.size(); i++) {
        int j = sf(word[i]);
        if (j == -1) {
            cout << "NO" << endl;
            return 0;
        }
        g.insert(j % 2);
        be.push_back(j / 2);
        af.push_back(j / 2);
    }
    if (word.size() == 1) {
        cout << "YES" << endl;
        return 0;
    }
    sort(af.begin(), af.end());
    if (g.size() != 1) {
        cout << "NO" << endl;
        return 0;
    }
    int cnt = 0;
    for (int i = 0; i < af.size(); i++) {
        if (af[i] != be[i]) {
            cout << "NO" << endl;
            return 0;
        }
        if (af[i] == 1) { cnt++; }
    }
    if (cnt == 0 && word.size() != 1) {
        cout << "NO" << endl;
        return 0;
    } else if (cnt != 1 && cnt != 0) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << 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]:
f is an integer array of size 1005
g is an integer array of size 1005
in function find with parameter integer x and return integer
    return f[x] if f[x] equals x, otherwise return call find with f[x]
end of the block
in function clear
    for i = 0 to 1005 exclusive, set f[i] to i
end of the block
define the main function
    call memset with g, 0, call sizeof with g
    call clear
    n, m, k are integers
    read n, m, k
    i and j are integers
    for i = 0 to k exclusive
        declare an integer gov
        read gov
        assign 1 to g[gov]
    end of the block
    for i = 0 to m exclusive
        x and y are integers
        read x, y
        if g[x] equals 1
            assign x to f[call find with y]
        else if g[y] equals 1
            assign y to f[call find with x]
        else
            if g[call find with x] equals 1
                set f[call find with y] to f[call find with x]
            else if g[call find with y] equals 1
                set f[find call with x] to f[find call with y]
            else
                set f[find call with y] to f[find call with x]
        end of the block
    end of the block
    ans is an integer set to 0
    maxx is an integer set to 0
    temp is an integer
    for i = 1 to n inclusive
        assign 1 to temp
        if g[i]
            for j = 1 to n inclusive
                if i isn't equal to j and not g[j] and f[call find with j] equals i, increment temp
            end of the block
            add temp * (temp - 1) / 2 to ans
            set maxx to call max with maxx, temp
        end of the block
    end of the block
    cnt is an integer set to 0
    for i = 1 to n inclusive
        if not g[i] and not g[f[call find with i]], increment cnt
    end of the block
    add maxx * cnt to ans
    add cnt * (cnt - 1) / 2 to ans
    subtract m from ans
    display ans
    return to indicate successful execution
end of the block

[CODE]:

int f[1005];
int g[1005];
int find(int x) {
    return f[x] == x ? x : f[x] = find(f[x]);
}
void clear() {
    for (int i = 0; i < 1005; i++) f[i] = i;
}
int main() {
    memset(g, 0, sizeof(g));
    clear();
    int n, m, k;
    cin >> n >> m >> k;
    int i, j;
    for (i = 0; i < k; i++) {
        int gov;
        cin >> gov;
        g[gov] = 1;
    }
    for (i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        if (g[x] == 1)
            f[find(y)] = x;
        else if (g[y] == 1)
            f[find(x)] = y;
        else {
            if (g[find(x)] == 1)
                f[find(y)] = f[find(x)];
            else if (g[find(y)] == 1)
                f[find(x)] = f[find(y)];
            else
                f[find(y)] = f[find(x)];
        }
    }
    int ans = 0;
    int maxx = 0;
    int temp;
    for (i = 1; i <= n; i++) {
        temp = 1;
        if (g[i]) {
            for (j = 1; j <= n; j++) {
                if (i != j && !g[j] && f[find(j)] == i) { temp++; }
            }
            ans += temp * (temp - 1) / 2;
            maxx = max(maxx, temp);
        }
    }
    int cnt = 0;
    for (i = 1; i <= n; i++) {
        if (!g[i] && !g[f[find(i)]]) { cnt++; }
    }
    ans += maxx * cnt;
    ans += cnt * (cnt - 1) / 2;
    ans -= m;
    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]:
f=array of 1005 int
g=array of 1005 int
function find (get int x, return int)
    if f[x] is x return x else (f[x] = find(f[x]), return f[x])
end of the block
function clear (no args, no return value)
    for i=0 to 1005 exclusive f[i]=i
end of the block
define the main function
    fill g with 0
    clear()
    n,m,k=int
    read n,m,k
    i,j=int
    for i=0 to k exclusive
        gov=int
        read gov
        g[gov]=1
    end of the block
    for i=0 to m exclusive
        x,y=int
        read x,y
        if g[x] is 1
            f[find(y)]=x
        else if g[y] is 1
            f[find(x)]=y
        else
            if g[find(x)] is 1
                f[find(y)]=f[find(x)]
            else if g[find(y)] is 1
                f[find(x)]=f[find(y)]
            else
                f[find(y)]=f[find(x)]
        end of the block
    end of the block
    ans=0
    maxx=0
    temp=int
    for i=1 to n inclusive
        temp=1
        if g[i]
            for j=1 to n inclusive
                if i is not j and not g[j] and f[find(j)] is i increment temp
            end of the block
            add temp*(temp-1)/2 to ans
            maxx=max(maxx,temp)
        end of the block
    end of the block
    cnt=0
    for i=1 to n inclusive
        if not g[i] and not g[f[find(i)]] increment cnt
    end of the block
    add maxx*cnt to ans
    add cnt*(cnt-1)/2 to ans
    subtract m from ans
    print ans
    return to indicate successful execution
end of the block

[CODE]:


[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 array of integers fa with 202002 elements
sum is a new array of integers with 202002 elements
create and array of integers c with size 202002
function max with int arguments a and b that returns int
    if a is greater than b
        return a
    else
        return b as a result
end of the block
int function findfa with int argument x
    if fa[x] is equal to x
        return x
    else
        return the result of findfa(fa[x])
end of the block
function U with int arguments x and y
    rx is a new integer variable = findfa(x)
    declare integer ry = findfa(y)
    if rx is not equal to ry
        set fa[rx] to ry
        add sum[rx] to sum[ry]
    end of the block
end of the block
vis is an array of booleans with size 202002
declare vector of integers called vec
define the main function
    create integers n, m and k
    read variables n, m and k from the input
    remove all elements from vec
    for i from 0 to n inclusive
        assign i to fa[i]
        assign 1 to sum[i]
    end of the block
    for i = 0 to k exclusive, read from the input to c[i]
    declare new ints x and y
    for i = 0 to m exclusive
        read user input to x and y
        call U of x and y
    end of the block
    set first sizeof(vis) bytes at the pointer vis to 0
    for i = 0 to k exclusive, change the value of vis[findfa(c[i])] to 1
    create integer variable with name MAX with value -1
    create new long long called ans with value 0
    start for loop from i = 1 to n inclusive incrementing i
        if fa[i] is equal to i
            if vis[i] is equal to 1
                set MAX to max of MAX and sum[i]
            else
                push sum[i] to the vec
            add sum[i] * (sum[i] - 1) / 2 to ans
        end of the block
    end of the block
    declare integer len with value length of vec
    start for loop from i = 0 to len exclusive incrementing i
        start for loop from j = i + 1 to len exclusive, changing ans to the sum of ans and vec[i] * vec[j] on each iteration
        change ans to ans + vec[i] * MAX
    end of the block
    change ans to ans - m
    if ans is greater than 0
        print ans
    else
        print "0" to the standard output
    return to indicate successful execution
end of the block

[CODE]:

int fa[202002];
int sum[202002];
int c[202002];
int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}
int findfa(int x) {
    if (fa[x] == x)
        return x;
    else
        return findfa(fa[x]);
}
void U(int x, int y) {
    int rx = findfa(x);
    int ry = findfa(y);
    if (rx != ry) {
        fa[rx] = ry;
        sum[ry] += sum[rx];
    }
}
bool vis[202002];
vector<int> vec;
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vec.clear();
    for (int i = 0; i <= n; i++) {
        fa[i] = i;
        sum[i] = 1;
    }
    for (int i = 0; i < k; i++) cin >> c[i];
    int x, y;
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        U(x, y);
    }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < k; i++) vis[findfa(c[i])] = 1;
    int MAX = -1;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        if (fa[i] == i) {
            if (vis[i] == 1)
                MAX = max(MAX, sum[i]);
            else
                vec.push_back(sum[i]);
            ans += sum[i] * (sum[i] - 1) / 2;
        }
    }
    int len = vec.size();
    for (int i = 0; i < len; i++) {
        for (int j = i + 1; j < len; j++) { ans += vec[i] * vec[j]; }
        ans += vec[i] * MAX;
    }
    ans = ans - m;
    if (ans > 0)
        cout << ans << endl;
    else
        cout << "0" << 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]:
v = vector of long integers of size 1100
visited = array of boolean values of length 1100
let ans be a long integer with ans = 0
let edges be a long integer with edges = 0
let edge be a long integer with edge = 0
let dfs be a long integer function that accepts long integer values x, parentu
    visited[x] is equal to true
    let n be a long integer with n = 1
    edges = edges + length of v[x]
    for long integer i = 0 to length of v[x] exclusive,
        if not visited[v[x][i]], n = n + depth first search of v[x][i], x
    end of the block
    return the value of n
end of the block
define the main function
    let n, m, k, x, y be long integers
    read n, m, k
    home = vector of long integers
    for long integer i = 0 to k exclusive
        read x
        push to back x in home
    end of the block
    for long integer i = 0 to m exclusive
        read x, y
        push to back y in v[x]
        push to back x in v[y]
    end of the block
    let sum be a long integer with sum = 0
    let num be a long integer with num = 0
    for long integer i = 0 to k exclusive
        if not visited[home[i]]
            edges is equal to 0
            let node be a long integer with node is equal to depth first search of home[i], 0
            edges is equal to edges / 2
            increment edge by edges
            num is equal to maximum of num and node
            ans is equal to ans + ((node - 1) * (node)) / 2 - edges
            increment sum by node
        end of the block
    end of the block
    ans is equal to ans + (n - sum) * num
    ans is equal to ans + ((n - sum - 1) * (n - sum)) / 2 - (m - edge)
    print ans and newline
end of the block

[CODE]:

vector<long long int> v[1100];
bool visited[1100];
long long int ans = 0;
long long int edges = 0;
long long int edge = 0;
long long int dfs(long long int x, long long int parent) {
    visited[x] = true;
    long long int n = 1;
    edges += v[x].size();
    for (long long int i = 0; i < v[x].size(); i++) {
        if (!visited[v[x][i]]) n += dfs(v[x][i], x);
    }
    return n;
}
int main() {
    long long int n, m, k, x, y;
    cin >> n >> m >> k;
    vector<long long int> home;
    for (long long int i = 0; i < k; i++) {
        cin >> x;
        home.push_back(x);
    }
    for (long long int i = 0; i < m; i++) {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    long long int sum = 0;
    long long int num = 0;
    for (long long int i = 0; i < k; i++) {
        if (!visited[home[i]]) {
            edges = 0;
            long long int node = dfs(home[i], 0);
            edges /= 2;
            edge += edges;
            num = max(num, node);
            ans += ((node - 1) * (node)) / 2 - edges;
            sum += node;
        }
    }
    ans += (n - sum) * num;
    ans += ((n - sum - 1) * (n - sum)) / 2 - (m - edge);
    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]:
f = int array of size 1000
in function find taking int x and returning int
    if f[x] is x
        return x
    else
        return find of f[x]
end of the block
in function unionn taking int a, int b
    x = int with x = find of a
    y = int with y = find of b
    if x is not y set f[x] to y
end of the block
define the main function
    t = int
    n, m, k, x, y = int
    s, num = int array of size 1000 each
    loop while reading n then m then k
        set all values of num to 0
        for i = 1 to n inclusive set f[i] to i
        for i = 1 to k inclusive read s[i]
        for i = 0 to m
            read x then y
            call unionn of x, y
        end of the block
        for i = 1 to n inclusive increment num[find of i]
        Max, sum, ss = int with Max = 0 and sum = 0 and ss = n
        for i = 1 to k inclusive
            set num[s[i]] to num[find of s[i]]
            set Max to max of Max, num[s[i]]
            decrement ss by num[s[i]]
            increment sum by (num[s[i]]) * (num[s[i]] - 1) / 2
        end of the block
        increment sum by (ss + Max) * (ss + Max - 1) / 2
        decrement sum by Max * (Max - 1) / 2 + m
        print sum
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int f[1000];
int find(int x) {
    if (f[x] == x)
        return x;
    else
        return find(f[x]);
}
void unionn(int a, int b) {
    int x = find(a);
    int y = find(b);
    if (x != y) f[x] = y;
}
int main() {
    int t;
    int n, m, k, x, y;
    int s[1000], num[1000];
    while (cin >> n >> m >> k) {
        memset(num, 0, sizeof(num));
        for (int i = 1; i <= n; i++) f[i] = i;
        for (int i = 1; i <= k; i++) cin >> s[i];
        for (int i = 0; i < m; i++) {
            cin >> x >> y;
            unionn(x, y);
        }
        for (int i = 1; i <= n; i++) num[find(i)]++;
        int Max = 0, sum = 0, ss = n;
        for (int i = 1; i <= k; i++) {
            num[s[i]] = num[find(s[i])];
            Max = max(Max, num[s[i]]);
            ss -= num[s[i]];
            sum += (num[s[i]]) * (num[s[i]] - 1) / 2;
        }
        sum += (ss + Max) * (ss + Max - 1) / 2;
        sum -= Max * (Max - 1) / 2 + m;
        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]:
create int array num of size 1005
make integer array r of size 1005
declare fast taking in int x and returning int
    if r[x] is equal to x, return x
    return r[x] = find(r[x])
end of the block
declare setunion taking in ints x and y
    create int rx = find(x)
    make int ry = find(y)
    if rx is not equal to ry, set r[rx] to ry
end of the block
define the main function
    create ints n, m, and k
    make int array gov of size 1005
    make ints x and y
    read n, m, and k and while they are truthy
        set all contents of num to 0
        for i = 0 to n, set r[i] to i
        for i = 0 to k, read gov[i]
        for i = 1 to m
            read x and y
            call setunion with arguments x and y
        end of the block
        for i = 1 to n, increment num[find(i)]
        create int maxs = 0
        make integer left = n
        let int re = 0
        for i = 1 to k
            set num[gov[i]] to num[find(gov[i])
            set maxs to max of maxs and num[gov[i]]
            subtract num[gov[i]] from left
            add (num[gov[i]] - 1) * num[gov[i]] / 2 to re
        end of the block
        set re to re + (left + maxs) * (left + maxs - 1) / 2
        set re to re - maxs * (maxs - 1) / 2 + m
        print re
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int num[1005];
int r[1005];
int find(int x) {
    if (r[x] == x) return x;
    return r[x] = find(r[x]);
}
void setunion(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx != ry) r[rx] = ry;
}
int main() {
    int n, m, k;
    int gov[1005];
    int x, y;
    while (cin >> n >> m >> k) {
        memset(num, 0, sizeof(num));
        for (int i = 0; i <= n; i++) { r[i] = i; }
        for (int i = 1; i <= k; i++) { cin >> gov[i]; }
        for (int i = 1; i <= m; i++) {
            cin >> x >> y;
            setunion(x, y);
        }
        for (int i = 1; i <= n; i++) { num[find(i)]++; }
        int maxs = 0;
        int left = n;
        int re = 0;
        for (int i = 1; i <= k; i++) {
            num[gov[i]] = num[find(gov[i])];
            maxs = max(maxs, num[gov[i]]);
            left -= num[gov[i]];
            re += (num[gov[i]] - 1) * num[gov[i]] / 2;
        }
        re += (left + maxs) * (left + maxs - 1) / 2;
        re -= maxs * (maxs - 1) / 2 + m;
        cout << re << 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]:
edges=array of 1004 by 1004 int
degree=array of 1004 int
function dfs (get int index, int cap, pointer to int visited, pointer to int numedges, pointer to int numver, int n, return nothing)
    visited[index]=1
    for i=0 to n exclusive
        if edges[index][i] is 1
            if visited[i] is 0
                add degree[i] to numedges[cap]
                increment numver[cap]
                dfs(i, cap, visited, numedges, numver, n)
            end of the block
        end of the block
    end of the block
end of the block
define the main function
    n,m,k=int
    read n,m,k
    cap=array of k int
    for i=0 to k exclusive
        read cap[i]
        decrement cap[i]
    end of the block
    a,b=int
    visited = array of n int
    for i=0 to n exclusive
        visited[i]=0
        degree[i]=0
    end of the block
    for i=0 to m exclusive
        read a,b
        decrement a
        decrement b
        edges[a][b]=1
        edges[b][a]=1
        increment degree[a]
        increment degree[b]
    end of the block
    numedges = array of k+1 int
    numver = array of k+1 int
    for i=0 to k-1 exclusive
        numedges[i]=0
        numver[i]=0
    end of the block
    count=0
    for i=0 to k exclusive
        dfs(cap[i], i, visited, numedges, numver, n)
        add degree[cap[i]] to numedges[i]
        increment numver[i]
    end of the block
    for i=0 to n exclusive
        if visited[i] is 0
            dfs(i, k, visited, numedges, numver, n)
            add degree[i] to numedges[k]
            increment numver[k]
        end of the block
    end of the block
    maxm=0
    maxindex=0
    ans=0
    for i=0 to k exclusive
        if numver[i] > maxm
            maxm=numver[i]
            maxindex=i
        end of the block
    end of the block
    for i=0 to k exclusive
        if i is maxindex continue
        xx=numver[i]*(numver[i]-1)
        divide xx by 2
        add (xx-numedges[i]/2) to ans
    end of the block
    xx=numver[maxindex]+numver[k]
    x2=(xx*(xx-1))/2
    subtract numedges[maxindex]/2 from x2
    subtract numedges[k]/2 from x2
    add x2 to ans
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int edges[1004][1004];
int degree[1004];
void dfs(int index, int cap, int *visited, int *numedges, int *numver, int n) {
    visited[index] = 1;
    for (int i = 0; i < n; i++) {
        if (edges[index][i] == 1) {
            if (visited[i] == 0) {
                numedges[cap] += degree[i];
                numver[cap]++;
                dfs(i, cap, visited, numedges, numver, n);
            }
        }
    }
}
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    int cap[k];
    for (int i = 0; i < k; i++) {
        cin >> cap[i];
        cap[i]--;
    }
    int a, b;
    int visited[n];
    for (int i = 0; i < n; i++) {
        visited[i] = 0;
        degree[i] = 0;
    }
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        a--;
        b--;
        edges[a][b] = 1;
        edges[b][a] = 1;
        degree[a]++;
        degree[b]++;
    }
    int numedges[k + 1];
    int numver[k + 1];
    for (int i = 0; i < k + 1; i++) {
        numedges[i] = 0;
        numver[i] = 0;
    }
    int count = 0;
    for (int i = 0; i < k; i++) {
        dfs(cap[i], i, visited, numedges, numver, n);
        numedges[i] += degree[cap[i]];
        numver[i] += 1;
    }
    for (int i = 0; i < n; i++) {
        if (visited[i] == 0) {
            dfs(i, k, visited, numedges, numver, n);
            numedges[k] += degree[i];
            numver[k]++;
        }
    }
    int maxm = 0;
    int maxindex = 0;
    long long ans = 0;
    for (int i = 0; i < k; i++) {
        if (numver[i] > maxm) {
            maxm = numver[i];
            maxindex = i;
        }
    }
    for (int i = 0; i < k; i++) {
        if (i == maxindex) continue;
        long long xx = numver[i] * (numver[i] - 1);
        xx /= 2;
        ans += (xx - numedges[i] / 2);
    }
    long long xx = numver[maxindex] + numver[k];
    long long x2 = (xx * (xx - 1)) / 2;
    x2 -= numedges[maxindex] / 2;
    x2 -= numedges[k] / 2;
    ans += x2;
    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]:
fa = integer array of size 202002
sum = integer array of size 202002
c = integer array of size 202002
in function max with arguments of integer a and integer b that returns an integer
    if a > b
        return a
    else
        return b
end of the block
in function findfa with arguments integer x that returns an integer
    if fa[x] is x
        return x
    else
        return the result of calling findfa with argument of fa[x]
end of the block
in function joint with argument integer x and integer y that returns nothing
    rx = integer = the result of calling findfa with argument of x
    ry = integer = the result of calling findfa with argument of y
    if rx is not ry
        fa[rx] = ry
        sum[ry] = sum[ry] + sum[rx]
    end of the block
end of the block
vis = boolean array of size 202002
vec = integer vector
define the main function
    n, m, k = integer
    read n, m, k
    clear all elements of vec
    for i = 0 to n inclusive
        fa[i] = i
        sum[i] = 1
    end of the block
    for i = 0 to k exclusive, then read c[i]
    x, y = integers
    for i = 0 to m exclusive
        read x, y
        call join with arguments of x and y
    end of the block
    set all elements of vis to 0
    for i = 0 to k exclusive, vis[the result of calling findfa with argument c[i] = 1
    mx = integer = -1
    ans = long long = 0
    for i = 1 to n inclusive
        if fa[i] is i
            if vis[i] is 1
                mx = the bigger value between mx and sum[i]
            else
                push back the values of vec and insert a new element of sum[i] at the end of vec
            ans = ans + sum[i] * (sum[i] - 1) / 2
        end of the block
    end of the block
    sz = integer = size of vec
    for i = 0 to sz exclusive
        for j = i + 1 to sz exclusive, then ans = ans + vec[i] * vec[j]
        ans = ans + vec[i] * mx
    end of the block
    ans = ans - m
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int fa[202002];
int sum[202002];
int c[202002];
int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}
int findfa(int x) {
    if (fa[x] == x)
        return x;
    else
        return findfa(fa[x]);
}
void joint(int x, int y) {
    int rx = findfa(x);
    int ry = findfa(y);
    if (rx != ry) {
        fa[rx] = ry;
        sum[ry] += sum[rx];
    }
}
bool vis[202002];
vector<int> vec;
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vec.clear();
    for (int i = 0; i <= n; i++) {
        fa[i] = i;
        sum[i] = 1;
    }
    for (int i = 0; i < k; i++) cin >> c[i];
    int x, y;
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        joint(x, y);
    }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < k; i++) vis[findfa(c[i])] = 1;
    int mx = -1;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        if (fa[i] == i) {
            if (vis[i] == 1)
                mx = max(mx, sum[i]);
            else
                vec.push_back(sum[i]);
            ans += sum[i] * (sum[i] - 1) / 2;
        }
    }
    int sz = vec.size();
    for (int i = 0; i < sz; i++) {
        for (int j = i + 1; j < sz; j++) { ans += vec[i] * vec[j]; }
        ans += vec[i] * mx;
    }
    ans -= m;
    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]:
create integer array dx of size 8 containing {0, 0, 1, 1, 1, -1, -1, -1}
create int array dy of size 8 containing {1, -1, -1, 0, 1, -1, 0, 1}
let integer vector v of size 1005
make bool array vis of size 1005
create int flag = 0 and cnt and int array dd of size 1005
declare dfs taking in int s
    set vis[s] to true
    increment cnt
    if dd[s] is truthy, set flag to 1
    for i = 0 to size of v[s] exclusive
        if vis[v[s][i]] is falsy, call dfs(v[s][i])
    end of the block
    end function
end of the block
define the main function
    create ints n, m, k, a, and b
    create long long ints maxx = 0, ans = 0, and cnt1 = 0
    make long long vector vec
    read n, m, and k
    while k-- is truthy
        read a
        set dd[a] to 1
    end of the block
    create int ml = m
    while m1-- is falsy
        read a and b
        append b to v[a]
        append a to v[b]
    end of the block
    for i = 1 to n
        if vis[i] is falsy
            set cnt and flag to 0
            call dfs with argument i
            if flag is equal to 0
                set cnt1 to cnt1 + cnt
            else
                set maxx to (cnt < maxx ? maxx : cnt)
                append cnt to vec
            end of the block
        end of the block
    end of the block
    for i = 0 to size of vec exclusive
        if vec[i] is equal to maxx
            set cnt1 to cnt 1 + vec[i]
            set ans to ans + (cnt1 * (cnt1 - 1)) / 2
            increment maxx
        else do
            set ans to ans + (vec[i] * (vec[i] - 1)) / 2
        end of the block
    end of the block
    print the result of (ans - m)
    return to indicate successful execution
end of the block

[CODE]:

int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy[8] = {1, -1, -1, 0, 1, -1, 0, 1};
vector<int> v[1005];
bool vis[1005];
int flag = 0, cnt, dd[1005];
void dfs(int s) {
    vis[s] = true;
    cnt++;
    if (dd[s]) flag = 1;
    for (int i = 0; i < v[s].size(); i++) {
        if (!vis[v[s][i]]) dfs(v[s][i]);
    }
    return;
}
int main() {
    int n, m, k, a, b;
    long long maxx = 0, ans = 0, cnt1 = 0;
    vector<long long> vec;
    cin >> n >> m >> k;
    while (k--) {
        cin >> a;
        dd[a] = 1;
    }
    int m1 = m;
    while (m1--) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            cnt = 0, flag = 0;
            dfs(i);
            if (flag == 0)
                cnt1 += cnt;
            else {
                maxx = (cnt < maxx ? maxx : cnt);
                vec.push_back(cnt);
            }
        }
    }
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] == maxx) {
            cnt1 += vec[i];
            ans += (cnt1 * (cnt1 - 1)) / 2;
            maxx++;
        } else {
            ans += (vec[i] * (vec[i] - 1)) / 2;
        }
    }
    cout << (ans - m) << endl;
    return 0;
}