[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
define the main function
    declare integer variable n
    read n
    print "+------------------------+\n"
    create 2d character array arr 4 by 11 elements
    for i = 0 to 4 exclusive
        for integer j = 0 to 11 exclusive set arr[i][j] to '#'
    for integer j = 0 to 11 exclusive
        for integer i = 0 to 4 exclusive
            if i = 2 && j is greater than 0
                set arr[i][j] to '.'
            else if n
                set arr[i][j] to 'O'
                decrease n
            end of the block
        end of the block
    end of the block
    for i = 0 to 4 exclusive
        print "|"
        for integer j = 0 to 11 exclusive print arr[i][j] and '.'
        if i = 0
            print "|D|)\n"
        else if i = 1
            print "|.|\n"
        else if i = 2
            print "..|\n"
        else
            print "|.|)\n"
    end of the block
    print "+------------------------+\n"
    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]:
define the main function
    create integer k
    read k
    create string array s with length 6
    set s[0] to "+------------------------+"
    set s[1] to "|#.#.#.#.#.#.#.#.#.#.#.|D|)"
    set s[2] to "|#.#.#.#.#.#.#.#.#.#.#.|.|"
    set s[3] to "|#.......................|"
    set s[4] to "|#.#.#.#.#.#.#.#.#.#.#.|.|)"
    set s[5] to "+------------------------+"
    create integer idx to 0
    while k
        for i=0 to 6 exclusive
            if s[i][idx] is equal to '#'
                decrement k
                set s[i][idx] to 'O'
                if not k break
            end of the block
        increment idx
    end of the block
    for i=0 to 6 exclusive print s[i]
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]:
define the main function
    create integer k
    read k
    create string array str with size 6
    set str[0] to "+------------------------+"
    set str[1] to "|#.#.#.#.#.#.#.#.#.#.#.|D|)"
    set str[2] to "|#.#.#.#.#.#.#.#.#.#.#.|.|"
    set str[3] to "|#.......................|"
    set str[4] to "|#.#.#.#.#.#.#.#.#.#.#.|.|)"
    set str[5] to "+------------------------+"
    for j = 1 to 23 exclusive, increment j by 2
        for i = 1 to 5 exclusive
            if k is greater than 0
                if i is 3 and j is not 1, break current loop iteration
                set str[i][j] to 'O', decrement k
            end of the block
        end of the block
    end of the block
    for i = 0 to 6 exclusive, print str[i] print newline
    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]:
n, i, j, ans = long long with ans = 9999999999999 and a,db = two dimensional arrays of long longs with the sizes 201 and 201 each
define the main function
    read n
    print "+------------------------+"
    if n is greater than 2
        decrement n
        print '|'
        for i = 1 to 11 inclusive
            if (n + 2) / 3 is greater or equal to i
                print "O."
            else
                print "#."
        end of the block
        print "|D|)"
        print '|'
        for i = 1 to 11 inclusive
            if (n + 1) / 3 is greater or equal to i
                print "O."
            else
                print "#."
        end of the block
        print "|.|"
        print "|O.......................|"
        print '|'
        for i = 1 to 11 inclusive
            if n / 3 is greater or equal to i
                print "O."
            else
                print "#."
        end of the block
        print "|.|)"
    else
        print '|'
        if n is greater than 0
            print "O."
        else
            print "#."
        print "#.#.#.#.#.#.#.#.#.#.|D|)"
        print '|'
        if n is greater than 1
            print "O."
        else
            print "#."
        print "#.#.#.#.#.#.#.#.#.#.|.|"
        print "|#.......................|"
        print "|#.#.#.#.#.#.#.#.#.#.#.|.|)"
    end of the block
    print "+------------------------+"
    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 long long variable k
create string array s with 8 elements
define the main function
    set s[1] to "+------------------------+"
    set s[2] to "|#.#.#.#.#.#.#.#.#.#.#.|D|)"
    set s[3] to "|#.#.#.#.#.#.#.#.#.#.#.|.|"
    set s[4] to "|#.......................|"
    set s[5] to "|#.#.#.#.#.#.#.#.#.#.#.|.|)"
    change s[6] to " +------------------------+"
    read k
    loop j from 1 to 25 inclusive
        loop i from 2 to 5 inclusive
            break if k = 0
            if s[i][j] is '#', change s[i][j] to 'O' and decrement k by one
        end of the block
        break if k = 0
    end of the block
    for i from 1 to 6 inclusive, print s[i] and "\n"
    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]:
create int k
create char matrix s of dimensions 4x11
define the main function
    for i = 0 to 4 exclusive
        for j = 0 to 11 exclusive set s[i][j] to #
    set the elements of the second row of s to .
    read k
    for j=0 to 11 exclusive
        for i=0 to 4 exclusive
            if k is true and s[i][j] is #
                set s[i][j] to character O
                decrease k by 1
            end of the block
    print +------------------------+ and move to newline
    for i = 0 to 4 exclusive
        print |
        for j = 0 to 11 exclusive print s[i][j] and .
        if i is 0
            print |D|) and move to newline
        else if i is equal to 1
            print |.| and move to newline
        else if i is 2
            print ..| and move to newline
        else do the following
            print |.|) and move to newline
    end of the block
    print +------------------------+
    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]:
Grades = char array of size 200005
define the main function
    let lfp, zp, n, i, t, last be integers with lfp = -1
    let carryFlag, pf be boolean with carryFlag = false, pf = false
    read n, t, Grades[1]
    for i = 1 to n inclusive
        if Grades[i] == '.'
            increment i
            break out of for loop
        end of the block
    end of the block
    while Grades[i] and t > 0
        if Grades[i] is greater than or equal to '5'
            set lfp to i
            break
        end of the block
        increment i
    end of the block
    while (-lfp) is not zero and t > 0 and pf is false
        if Grades[lfp - 1] == '.'
            set Grades[lfp - 1] to 0
            increment Grades[lfp - 2]
            update last to lfp - 2
            set pf to true
        else
            update Grades[lfp] to 0
            increment Grades[lfp - 1]
            update last to lfp - 1
        end of the block
        set lfp to -1
        decrement t
        if Grades[last] > '9'
            let c be integer with c = 1
            set Grades[last] to '0'
            decrement last
            while c is not zero
                set c to 0
                if Grades[last] == '.'
                    set Grades[last] to '\0'
                    increment Grades[last - 1]
                    decrement last by 2
                    set pf to true
                else if last == '\0'
                    set carryFlag to true
                    set Grades[0] to '1'
                    break
                else
                    increment Grades[last]
                end of the block
                if Grades[last] > '9'
                    if not pf
                        set Grades[last] to '\0'
                    else
                        set Grades[last] to '0'
                    decrement last
                    set c to 1
                end of the block
                if Grades[last] >= '5', set lfp to last
            end of the block
        else if Grades[last] >= '5'
            set lfp to last
        end of the block
    end of the block
    if carryFlag is true
        print out first element of Grades
    else
        print out second element of Grades
    return to indicate successful execution
end of the block

[CODE]:

char Grades[200005];
int main() {
    int lfp = -1, zp, n, i, t, last;
    bool carryFlag = false, pf = false;
    cin >> n >> t >> (Grades + 1);
    for (i = 1; i <= n; ++i) {
        if (Grades[i] == '.') {
            ++i;
            break;
        }
    }
    while (Grades[i] && t > 0) {
        if (Grades[i] >= '5') {
            lfp = i;
            break;
        }
        ++i;
    }
    while ((~lfp) && t > 0 && !pf) {
        if (Grades[lfp - 1] == '.') {
            Grades[lfp - 1] = 0;
            Grades[lfp - 2]++;
            last = lfp - 2;
            pf = true;
        } else {
            Grades[lfp] = 0;
            Grades[lfp - 1]++;
            last = lfp - 1;
        }
        lfp = -1;
        t--;
        if (Grades[last] > '9') {
            int c = 1;
            Grades[last] = '0';
            last--;
            while (c) {
                c = 0;
                if (Grades[last] == '.') {
                    Grades[last] = '\0';
                    Grades[last - 1]++;
                    last -= 2;
                    pf = true;
                } else if (last == '\0') {
                    carryFlag = true;
                    Grades[0] = '1';
                    break;
                } else {
                    Grades[last]++;
                }
                if (Grades[last] > '9') {
                    if (!pf)
                        Grades[last] = '\0';
                    else
                        Grades[last] = '0';
                    last--;
                    c = 1;
                }
                if (Grades[last] >= '5') lfp = last;
            }
        } else if (Grades[last] >= '5') {
            lfp = last;
        }
    }
    if (carryFlag)
        cout << Grades << endl;
    else
        cout << (Grades + 1) << endl;
    return 0;
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
define the main function
    declare ints n and t
    read user input to n and t
    new string variable s
    read variable s from the input
    define new integer called pointPos = -1
    declare integer variable with name start = -1
    start for loop from i = 0 to length of s exclusive incrementing i
        if pointPos != -1 and s[i] - '0' >= 5
            set start to i
            break
        end of the block
        if s[i] is equal to '.', set the value of pointPos to i
    end of the block
    if start != - 1
        define new boolean called next with value true
        while start > pointPos and next and t > 0
            if start - pointPos is equal to 1
                create integer variable nextVal = s[start - 2] - '0' + 1
                if nextVal is equal to 10
                    set the value of s[start - 2] to '0'
                else
                    assign nextVal + '0' to s[start - 2]
                    set the value of next to false
                end of the block
            else
                create integer variable nextVal with value s[start-1] - '0' + 1
                if nextVal < 5 or t - 1 = 0, assign false to next
                assign the new value = nextVal + '0' to s[start - 1]
            end of the block
            decrement start
            decrement t
        end of the block
        remove elements from the start + 1 to the end of s
        if *(--s.end()) == '.', remove last element of s
        change start to pointPos - 1
        while next and start >= 0
            if start is equal to 0
                insert '0' to the start of s
                set start to 1
            end of the block
            declare integer variable with name nextVal and value s[start-1] - '0' + 1
            if nextVal is equal to 10
                assign '0' to s[start - 1]
            else
                assign the new value = nextVal + '0' to s[start - 1]
                set next to false
            end of the block
            decrement start
        end of the block
    end of the block
    print s to the standard output
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, t;
    cin >> n >> t;
    string s;
    cin >> s;
    int pointPos = -1;
    int start = -1;
    for (int i = 0; i < s.size(); i++) {
        if (pointPos != -1 && s[i] - '0' >= 5) {
            start = i;
            break;
        };
        if (s[i] == '.') pointPos = i;
    }
    if (start != -1) {
        bool next = true;
        while (start > pointPos && next && t > 0) {
            if (start - pointPos == 1) {
                int nextVal = s[start - 2] - '0' + 1;
                if (nextVal == 10)
                    s[start - 2] = '0';
                else {
                    s[start - 2] = nextVal + '0';
                    next = false;
                }
            } else {
                int nextVal = s[start - 1] - '0' + 1;
                if (nextVal < 5 || t - 1 == 0) next = false;
                s[start - 1] = nextVal + '0';
            }
            --start;
            --t;
        }
        s.erase(s.begin() + start + 1, s.end());
        if (*(--s.end()) == '.') s.erase(--s.end());
        start = pointPos - 1;
        while (next && start >= 0) {
            if (start == 0) {
                s.insert(s.begin(), '0');
                start = 1;
            }
            int nextVal = s[start - 1] - '0' + 1;
            if (nextVal == 10)
                s[start - 1] = '0';
            else {
                s[start - 1] = nextVal + '0';
                next = false;
            }
            --start;
        }
    }
    cout << s << endl;
    return 0;
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
define the main function
    make ints n and t
    read n and t
    create string s
    read s
    make integer i = 0
    while i is less than n and s[i] is not equal to '.', increment i
    if i is not equal to n and t is greater than 0
        make integer p = i
        increment i
        while i is less than n and s[i] is less than '5', add 1 to i
        if i is not equal to n
            set s to s.substr(0, i)
            subtract 1 from i
            add 1 to s[i]
            take away 1 from t
            decrease i by 1
            while i is greater than p, s[i + 1] is more than '4', and t is greater than 0
                increment s[i]
                set s[i + 1] to '0'
                decrease t by 1
                decrease i by 1
            end of the block
            if s[i + 1] is equal to '/'
                set s to s.substr(0, i + 1)
                while i is greater than or equal to 0 and s[i] is equal to '9'
                    set s[i] to '0'
                    decrease i by 1
                end of the block
                if i is not equal to -1
                    increment s[i]
                else
                    output 1
                end of the block
            else if i is equal to p, s[p + 1] is greater than '4', and t is greater than 0
                take away 1 from t
                set s to s.substr(0, i)
                decrease i by 1
                while i is greater than or equal to 0 and s[i] is equal to '9'
                    set s[i] to '0'
                    reduce i by 1
                end of the block
                if i not equal to -1
                    increment s[i] by 1
                else do
                    print 1
                end of the block
            otherwise
                set s to s.substr(0, i + 2)
            end of the block
        end of the block
    end of the block
    print s
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 integer array tab size 55 by 55
declare integer array vis size 55 by 55
declare integers n, m
declare czysc with no arguments, returning void
    for i = 1 to n inclusive
        for j = 1 to m inclusive, let vis[i][j] be 0
    end of the block
    return from function
end of the block
declare dfs with integers i, j as arguments, returning void
    let vis[i][j] be 1
    if tab[i+1][j] is 1 and vis[i+1][j] is 0, run dfs(i+1 and j)
    if tab[i-1][j] is 1 and vis[i-1][j] is 0, run dfs(i-1, j)
    if tab[i][j+1] is 1 and vis[i][j+1] is 0, run dfs with i, j + 1 as arguments
    if tab[i][j-1] is 1 and vis[i][j-1] is 0, run dfs(i,j-1)
    return from function
end of the block
define the main function
    declare character c
    read n, m
    declare integers licz = 0
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            read c
            if c is '#'
                let tab[i][j] be 1
                increment licz
            end of the block
        end of the block
    end of the block
    if licz is less than 3
        print "-1" and newline
        return to indicate successful execution
    end of the block
    declare integers wynik = 5
    declare integer akt
    declare integer odw
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            if tab[i][j] is 1
                let akt be 0
                let akt be tab[i + 1][j] + tab[i - 1][j] + tab[i][j + 1] + tab[i][j - 1]
                if akt is 1
                    print "1" and newline
                    return to indicate successful execution
                else
                    run czysc
                    let tab[i][j] be 0
                    if tab[i+1][j] is 1
                        run dfs with i + 1, j as arguments
                    else
                        if tab[i-1][j] is 1
                            run dfs(i-1,j)
                        else
                            run dfs(i,j+1)
                        end of the block
                    end of the block
                    let tab[i][j] be 1
                end of the block
                let odw be vis[i + 1][j] + vis[i - 1][j] + vis[i][j + 1] + vis[i][j - 1]
                if odw is less than akt
                    print "1" and newline
                    return to indicate successful execution
                end of the block
            end of the block
        end of the block
    end of the block
    print "2" and newline
    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]:
data=array of 51 by 51 char
visited=array of 51 by 51 bool
dr=array of 4 int filled with 0,0,1,-1
dc=array of 4 int filled with 1,-1,0,0
function Counter (get int i and j, return int)
    if visited[i][j] return 0
    visited[i][j]=true
    ans=0
    if data[i][j] is '#'
        increment ans
        for x=0 to 4 exclusive add Counter(i+dr[x],j+dc[x]) to ans
    end of the block
    return ans
end of the block
define the main function
    n,m=int
    read n,m
    Total=0
    start=pair of int, int
    for i=0 to n exclusive
        for j=o to m exclusive
            read data[i][j]
            if data[i][j] is '#' increment Total, start=i,j
        end of the block
    end of the block
    fill visited with false
    t=Counter(first item of start, second item of start)
    if t < Total
        print 0
        return to indicate successful execution
    else if Total < 3
        print -1
        return to indicate successful execution
    else
        ans=0
        for i=0 to n exclusive
            for j=0 to m exclusive
                if data[i][j] is '#'
                    if i is 6 and j is 5 r=1
                    fill visited with false
                    visited[i][j]=true
                    x,y=int
                    for k=0 to 4 exclusive
                        if data[i+dr[k]][j+dc[k]] is '#'
                            x=i+dr[k]
                            y=j+dc[k]
                            break
                        end of the block
                    end of the block
                    t=Counter(x,y)
                    if t<Total-1
                        print 1
                        return to indicate successful execution
                    end of the block
                end of the block
            end of the block
        end of the block
    end of the block
    print 2
    return to indicate successful execution
end of the block

[CODE]:

char data[51][51];
bool visited[51][51];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
int Counter(int i, int j) {
    if (visited[i][j]) return 0;
    visited[i][j] = true;
    int ans = 0;
    if (data[i][j] == '#') {
        ans++;
        for (int x = 0; x < 4; x++) { ans += Counter(i + dr[x], j + dc[x]); }
    }
    return ans;
}
int main() {
    int n, m;
    cin >> n >> m;
    int Total = 0;
    pair<int, int> start;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> data[i][j];
            if (data[i][j] == '#') Total++, start = pair<int, int>(i, j);
        }
    }
    memset(visited, false, sizeof visited);
    int t = Counter(start.first, start.second);
    if (t < Total) {
        cout << 0 << endl;
        return 0;
    } else if (Total < 3) {
        cout << -1 << endl;
        return 0;
    } else {
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (data[i][j] == '#') {
                    if (i == 6 && j == 5) { int r = 1; }
                    memset(visited, false, sizeof visited);
                    visited[i][j] = true;
                    int x, y;
                    for (int k = 0; k < 4; k++) {
                        if (data[i + dr[k]][j + dc[k]] == '#') {
                            x = i + dr[k];
                            y = j + dc[k];
                            break;
                        }
                    }
                    int t = Counter(x, y);
                    if (t < Total - 1) {
                        cout << "1" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << 2 << endl;
    return 0;
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
create constant integer MAXN = 55
let char array mp of size MAXN with array of size MAXN
make bool vis of size MAXN with array of size MAXN
create constant integer array go of size 4 with array of size 2 containing {0, 1, 0, -1, -1, 0, 1, 0}
make ints n, m, and all = 0
declare dfs taking in ints x and y and returning integer
    create int ans = 1
    for i = 0 to 4 exclusive
        create ints xx = x + go [i][0] and yy = y + go[i][1]
        if mp[xx][yy] is equal to '#' and vis[xx][yy] is falsy
            set vis[xx][yy] to true
            set ans to ans + dfs(x + go[i][0], y + go[i][1])
        end of the block
    end of the block
    return ans
end of the block
declare solve
    if all is less than or equal to 2, return -1
    for i = 1 to n
        for j = 1 to m
            if mp[i][j] is equal to '#'
                set mp[i][j] to '.'
                create integer t = 0
                for k = 0 to 4 exclusive
                    make ints xx = i + go[k][0] and yy = j + go[k][1]
                    if mp[xx][yy] is equal to '#'
                        set all contents of vis to 0
                        set vis[xx][yy] to true
                        set t to dfs(xx, yy)
                        break loop
                    end of the block
                end of the block
                set mp[i][j] to '#'
                if t is 0, return -1
                if t is not all - 1, return 1
            end of the block
        end of the block
    end of the block
    return 2
end of the block
define the main function
    read n and m
    set all contents of mp to '.'
    for i = 1 to n
        for j = 1 to m
            read mp[i][j]
            if mp[i][j] is equal to '#', increment all
        end of the block
    end of the block
    print result of solve()
    return to indicate successful execution
end of the block

[CODE]:

const int MAXN = 55;
char mp[MAXN][MAXN];
bool vis[MAXN][MAXN];
const int go[4][2] = {0, 1, 0, -1, -1, 0, 1, 0};
int n, m, all = 0;
int dfs(int x, int y) {
    int ans = 1;
    for (int i = 0; i < 4; i++) {
        int xx = x + go[i][0], yy = y + go[i][1];
        if (mp[xx][yy] == '#' && !vis[xx][yy]) {
            vis[xx][yy] = true;
            ans += dfs(x + go[i][0], y + go[i][1]);
        }
    }
    return ans;
}
int solve() {
    if (all <= 2) return -1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mp[i][j] == '#') {
                mp[i][j] = '.';
                int t = 0;
                for (int k = 0; k < 4; k++) {
                    int xx = i + go[k][0], yy = j + go[k][1];
                    if (mp[xx][yy] == '#') {
                        memset(vis, 0, sizeof(vis));
                        vis[xx][yy] = true;
                        t = dfs(xx, yy);
                        break;
                    }
                }
                mp[i][j] = '#';
                if (t == 0) return -1;
                if (t != all - 1) { return 1; }
            }
        }
    }
    return 2;
}
int main() {
    cin >> n >> m;
    memset(mp, '.', sizeof(mp));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> mp[i][j];
            if (mp[i][j] == '#') ++all;
        }
    }
    cout << solve() << 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]:
mnx=8000009
mod=1000000007
dx=array of 4 long long filled with -1, 0, 0, 1
dy=array of 4 long long filled with 0, -1, 1, 0
n,m=long long
s=array of 111 by 111 char
u=array of 111 by 111 bool
function check (get long long x and y, return bool)
    return 0 < x and x < n+1 and 0 < y and y < m+1
end of the block
function dfs (get long long x and y, return nothing)
    if u[x][y] return
    u[x][y]=true
    for i=0 to 4 exclusive
        if check(x+dx[i], y+dy[i]) and s[x+dx[i]][y+dy[i]] is '#' dfs(x+dx[i], y+dy[i])
    end of the block
end of the block
define the main function
    read n,m
    for i=1 to n inclusive
        for j=1 to m inclusive read s[i][j]
    end of the block
    qwe=0
    for i=1 to n inclusive
        for j=1 to m inclusive
            if s[i][j] is '#' increment qwe
        end of the block
    end of the block
    res=11111111111111
    for i=1 to n inclusive
        for j=1 to m inclusive
            if s[i][j] is '#'
                q=0
                for k=0 to 4 exclusive
                    if check(i+dx[k], j+dy[k]) and s[i+dx[k]][j+dy[k]] is '#' increment q
                end of the block
                if q+1 < qwe res=min(res, q)
                if qwe>1
                    s[i][j]='0'
                    for k=1 to n inclusive
                        for l=1 to m inclusive u[k][l]=false
                    end of the block
                    cnt=0
                    for k=1 to n inclusive
                        for l=1 to m inclusive
                            if s[k][l] is '#' and not u[k][l]
                                dfs(k,l)
                                increment cnt
                            end of the block
                        end of the block
                    end of the block
                    if cnt>1 res=min(res, 1)
                    s[i][j]='#'
                end of the block
            end of the block
        end of the block
    end of the block
    if res is 11111111111111 subtract 11111111111112 from res
    print res
    return to indicate successful execution
end of the block

[CODE]:

const long long mnx = 8e6 + 9;
const long long mod = 1e9 + 7;
const long long dx[4] = {-1, 0, 0, 1};
const long long dy[4] = {0, -1, 1, 0};
long long n, m;
char s[111][111];
bool u[111][111];
bool check(long long x, long long y) {
    return 0 < x && x < n + 1 && 0 < y && y < m + 1;
}
void dfs(long long x, long long y) {
    if (u[x][y]) { return; }
    u[x][y] = true;
    for (long long i = 0; i < 4; i++) {
        if (check(x + dx[i], y + dy[i]) && s[x + dx[i]][y + dy[i]] == '#') { dfs(x + dx[i], y + dy[i]); }
    }
}
int main() {
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= m; j++) { cin >> s[i][j]; }
    }
    long long qwe = 0;
    for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= m; j++) {
            if (s[i][j] == '#') { qwe++; }
        }
    }
    long long res = 11111111111111;
    for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= m; j++) {
            if (s[i][j] == '#') {
                long long q = 0;
                for (long long k = 0; k < 4; k++) {
                    if (check(i + dx[k], j + dy[k]) && s[i + dx[k]][j + dy[k]] == '#') q++;
                }
                if (q + 1 < qwe) { res = min(res, q); }
                if (qwe > 1) {
                    s[i][j] = '0';
                    for (long long k = 1; k <= n; k++) {
                        for (long long l = 1; l <= m; l++) { u[k][l] = false; }
                    }
                    long long cnt = 0;
                    for (long long k = 1; k <= n; k++) {
                        for (long long l = 1; l <= m; l++) {
                            if (s[k][l] == '#' && !u[k][l]) {
                                dfs(k, l);
                                cnt++;
                            }
                        }
                    }
                    if (cnt > 1) { res = min(res, 1LL); }
                    s[i][j] = '#';
                }
            }
        }
    }
    if (res == 11111111111111) res -= 11111111111112;
    cout << res << '\n';
    return 0;
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
declare constant integer MAXN = 55
declare integers n, m, area
declare integer array dx = {-1, 0, 1, 0}
declare integer array dy = {0, 1, 0, -1}
declare integer array bio size MAXN by MAXN
declare character array grid size MAXN by MAXN
declare valid with integers x, y as arguments, returning boolean
    if x is less than 0 or x is greater than or equal to n, return false from function
    if y is less than 0 or y is greater than or equal to m, return false from function
    return true from function
end of the block
declare dfs with integers x, y as arguments, returning void
    let bio[x][y] be 1
    for i = 0 to 4 exclusive
        declare integer xx = x + dx[i]
        declare integer yy = y + dy[i]
        if result of run valid(xx,yy) and grid[xx][yy] is '#' and not bio[xx][yy], run dfs(xx,yy)
    end of the block
end of the block
declare nc with no arguments, returning integer
    for i = 0 to n exclusive
        for j = 0 to m exclusive, let bio[i][j] be 0
    end of the block
    declare integer bk = 0
    for i = 0 to n exclusive
        for j = 0 to m exclusive
            if grid[i][j] is '.', end current loop iteration
            if bio[i][j], end current loop iteration
            run dfs(i,j)
            increment bk
        end of the block
    end of the block
    return bk
end of the block
define the main function
    read n and m
    for i = 0 to n exclusive, read grid[i]
    for i = 0 to n exclusive
        for j = 0 to m exclusive
            if grid[i][j] is '#', increment area
        end of the block
    end of the block
    if area is less than 3
        print "-1\n"
        return to indicate successful execution
    else if area is 3
        print "1\n"
        return to indicate successful execution
    else
        for i = 0 to n exclusive
            for j = 0 to m exclusive
                if grid[i][j] is '.', end current loop iteration
                let gird[i][j] be '.'
                if result of run nc is greater than 1
                    print "1\n"
                    return to indicate successful execution
                end of the block
                let grid[i][j] be '#'
            end of the block
        end of the block
        print "2\n"
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

const int MAXN = 55;
int n, m, area;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int bio[MAXN][MAXN];
char grid[MAXN][MAXN];
bool valid(int x, int y) {
    if (x < 0 || x >= n) return false;
    if (y < 0 || y >= m) return false;
    return true;
}
void dfs(int x, int y) {
    bio[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (valid(xx, yy) && grid[xx][yy] == '#' && !bio[xx][yy]) { dfs(xx, yy); }
    }
}
int nc() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) { bio[i][j] = 0; }
    }
    int bk = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (grid[i][j] == '.') continue;
            if (bio[i][j]) continue;
            dfs(i, j);
            bk++;
        }
    }
    return bk;
}
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) { cin >> grid[i]; }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (grid[i][j] == '#') area++;
        }
    }
    if (area < 3) {
        cout << "-1\n";
        return 0;
    } else if (area == 3) {
        cout << "1\n";
        return 0;
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (grid[i][j] == '.') continue;
                grid[i][j] = '.';
                if (nc() > 1) {
                    cout << "1\n";
                    return 0;
                }
                grid[i][j] = '#';
            }
        }
        cout << "2\n";
    }
    return 0;
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
create integer array A of size 100 X 100
create integer array B of size 26000
create vector integer array NEB of size 27000
let yy be integer with yy=0
create integer arrays vis,low,malow,tim,F of sizes 27000 each
create integer t=1
create integer uu=0
create integer vector check
in the function dfs which takes a integer s
    set low[s] = t
    set vis[s] = 1
    set tim[s] =t
    add 1 to t
    create integer pp=0
    for i=0 to NEB[s].size exclusive
        create integer l = NEB[s][i]
        if F[s] is not equal to 1
            if vis[l] is equal to 1
                set low[s] to minimum of low[s] and tim[l]
            else do the following
                add 1 to pp
                set F[l] =s
                call dfs with argument l
                create integer u=s
                set low[u] = minimum of low[u] and low[l]
                set malow[w] to maximum of malow[u] and low[l]
            end of the block
        end of the block
    end of the block
    create integer u = s
    is s=yy and pp>1
        set uu=1
        add s to the end of check
    else if ss is not equal to yy and malow[u] >= tim[u]
        set uu to 1
        add s to end of check
    end of the block
end of the block
define the main function
    n,m = integers
    read n and m
    create integer no=0
    for i=1 to n inclusive
        for j=1 to m inclusive
            c= char
            read c
            if c is equal to #
                increment no
                set A[i][j] to 1
                set B[(m + 1) * i + j] = 1
                set yy = (m + 1) * i + j
            end of the block
        end of the block
    end of the block
    create integer array of size 4 P = {-1, 1, (0 - m - 1), m + 1}{-1, 1, (0 - m - 1), m + 1}
    for i=1 to 2700 exclusive
        for j=0 to 4 exclusive
            if i + P[j] >= 0 and B[i + P[j]] = 1 then add i+P[j] to the end of NEB[i]
        end of the block
    end of the block
    call dfs on yy
    if no<3
        then print -1
    else do the following
        if uu is 1
            print 1 and new line
        else do the following
            print 2
    end of the block
end of the block

[CODE]:

int A[100][100];
int B[26000];
vector<int> NEB[27000];
int yy = 0;
int vis[27000], low[27000], malow[27000], tim[27000], F[27000];
int t = 1;
int uu = 0;
vector<int> check;
void dfs(int s) {
    low[s] = t;
    vis[s] = 1;
    tim[s] = t;
    t++;
    int pp = 0;
    for (int i = 0; i < NEB[s].size(); i++) {
        int l = NEB[s][i];
        if (F[s] != l) {
            if (vis[l] == 1) {
                low[s] = min(low[s], tim[l]);
            } else {
                pp++;
                F[l] = s;
                dfs(l);
                int u = s;
                low[u] = min(low[u], low[l]);
                malow[u] = max(malow[u], low[l]);
            }
        }
    }
    int u = s;
    if (s == yy && pp > 1) {
        uu = 1;
        check.push_back(s);
    } else if (s != yy && malow[u] >= tim[u]) {
        uu = 1;
        check.push_back(s);
    }
}
int main() {
    int n, m;
    cin >> n >> m;
    int no = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            char c;
            cin >> c;
            if (c == '#') {
                no++;
                A[i][j] = 1;
                B[(m + 1) * i + j] = 1;
                yy = (m + 1) * i + j;
            }
        }
    }
    int P[4] = {-1, 1, (0 - m - 1), m + 1};
    for (int i = 1; i < 2700; i++) {
        for (int j = 0; j < 4; j++) {
            if (i + P[j] >= 0 && B[i + P[j]] == 1) NEB[i].push_back(i + P[j]);
        }
    }
    dfs(yy);
    if (no < 3)
        cout << -1 << endl;
    else {
        if (uu == 1)
            cout << 1 << endl;
        else
            cout << 2 << endl;
    }
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
create new constant integer MAX_N = 50
new integer constant MAX_M with value 50
define new 2d array of integers v with size MAX_N by MAX_M
define new 2d array of integers u MAX_N by MAX_M elements
define new integers n and m
void function dfs with int arguments x, y and first
    if first is false, assign the new value = 1 to u[y][x]
    if x > 0 and v[y][x - 1] is true and u[y][x - 1] is false, call dfs(x - 1, y)
    call dfs(x + 1, y) if x < m - 1 and v[y][x + 1] is true and u[y][x + 1] is false
    if y > 0 and v[y - 1][x] is true and u[y - 1][x] is false, run function dfs(x, y - 1)
    if y < n - 1 and v[y + 1][x] is true and u[y + 1][x] is false, call method dfs(x, y + 1)
end of the block
define the main function
    read n and m from the user input
    create new integer called k = 0
    for i from 0 to n exclusive
        new string variable s
        read variable s from the input
        start for loop from j = 0 to m exclusive
            assign the new value = (true if s[j]='#' or false otherwise), to v[i][j]
            add v[i][j] to k
        end of the block
    end of the block
    if k <= 2
        print - 1
        return to indicate successful execution
    end of the block
    define boolean f = false
    start for loop from i = 0 to n exclusive
        increment j in a loop from 0 to m exclusive
            if v[i][j] is false, skip the rest of the loop
            set first MAX_N * MAX_M *sizeof(int) bytes at the pointer u to 0
            assign 0 to v[i][j]
            create boolean variable with name f = false
            for integer ii = 0 to n exclusive incrementing ii, while f is false
                in a for loop, change jj from 0 to m exclusive, while f is false
                    if v[ii][jj] != 0
                        call dfs(jj, ii)
                        assign true to f
                    end of the block
                end of the block
            end of the block
            start for loop from ii = 0 to n exclusive
                loop through jj from 0 to m exclusive incrementing by 1
                    if i = ii and j = jj, go to the start of the loop
                    if v[ii][jj] != u[ii][jj]
                        print 1 and a new line
                        return to indicate successful execution
                    end of the block
                end of the block
            end of the block
            change the value of v[i][j] to 1
        end of the block
    end of the block
    print 2
    return to indicate successful execution
end of the block

[CODE]:

const int MAX_N = 50;
const int MAX_M = 50;
int v[MAX_N][MAX_M];
int u[MAX_N][MAX_M];
int n, m;
void dfs(int x, int y, int first = 0) {
    if (!first) u[y][x] = 1;
    if (x > 0 && v[y][x - 1] && !u[y][x - 1]) dfs(x - 1, y);
    if (x < m - 1 && v[y][x + 1] && !u[y][x + 1]) dfs(x + 1, y);
    if (y > 0 && v[y - 1][x] && !u[y - 1][x]) dfs(x, y - 1);
    if (y < n - 1 && v[y + 1][x] && !u[y + 1][x]) dfs(x, y + 1);
}
int main() {
    cin >> n >> m;
    int k = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < m; ++j) {
            v[i][j] = (s[j] == '#');
            k += v[i][j];
        }
    }
    if (k <= 2) {
        cout << -1 << endl;
        return 0;
    }
    bool f = false;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (!v[i][j]) continue;
            memset(u, 0, MAX_N * MAX_M * sizeof(int));
            v[i][j] = 0;
            bool f = false;
            for (int ii = 0; ii < n && !f; ++ii) {
                for (int jj = 0; jj < m && !f; ++jj) {
                    if (v[ii][jj] != 0) {
                        dfs(jj, ii);
                        f = true;
                    }
                }
            }
            for (int ii = 0; ii < n; ++ii) {
                for (int jj = 0; jj < m; ++jj) {
                    if (i == ii && j == jj) continue;
                    if (v[ii][jj] != u[ii][jj]) {
                        cout << 1 << endl;
                        return 0;
                    }
                }
            }
            v[i][j] = 1;
        }
    }
    cout << 2 << endl;
    return 0;
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
declare character array a size 55 by 55
declare integer array is size 55 by 55
declare integers n, m
declare integer arrays dx size 4 = {-1, 1, 0, 0}, dy size 4 = {0, 0, -1, 1}
declare inline work with integers x, y as arguments, returning void
    if is[x][y] is 1, return from function
    if a[x][y] is not '#', return from function
    let is[x][y] be 1
    declare integer i
    for i = 0 to 4 exclusive, run work with x + dx[i], y + dy[i] as arguments
end of the block
declare inline check with integers x, y as arguments, returning boolean
    let a[x][y] be '.'
    declare integer kk = 0
    set bytes from is to size of is to value 0
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            if a[i][j] is '#' and is[i][j] is 0
                increment kk
                run work(i,j)
            end of the block
    end of the block
    let a[x][y] be '#'
    return kk is greater than 1
end of the block
define the main function
    read n, m
    declare integer kk = 0
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            read a[i][j]
            if a[i][j] is '#', increment kk
        end of the block
    end of the block
    if kk is less than 3
        print -1 and newline
        return to indicate successful execution
    end of the block
    declare integer ans = 2
    for i = 0 to n inclusive
        for j = 1 to m inclusive
            if a[i][j] is '#'
                if result of run check(i,j) is true, let ans be 1
            end of the block
    end of the block
    print ans and newline
    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]:
define the main function
    make ints i and j
    make int array vis of size 220 with array of size 220 with {0}
    make integer array vis1 of size 220 with array of size 220 with {0}
    make int arrays x of size 5, y of size 5, x1 of size 5, and y1 of size 5
    for i = 0 to 4 exclusive, read x[i] and y[i]
    for i = 0 to 4 exclusive, read x1[i] and y1[i]
    sort x using x + 4
    sort x1 using x1 + 4
    sort y using y + 4
    sort y1 using y1 + 4
    make integer ox = min(x[0], x1[0])
    create int oy = min(y[0], y1[0])
    if ox is less than 0, set ox to -ox
    if oy is less than 0, set oy to -oy
    for i = x[0] + ox to x[3] + ox
        for j = y[0] + oy to y[3] + oy, set vis[i][j] to 1
    make integer mid = (x1[0] + ox + x1[3] + ox) / 2
    create int s = y1[0] + oy
    let int t = y1[3] + oy
    for i = mid to x1[0] + ox
        for j = s to t, set vis1[i][j] to 1
        increment s
        decrease t by 1
    end of the block
    set s to y1[0] + oy
    set t to y1[3] + oy
    for i = mid to x1[3] + ox
        for j = s to t, set vis1[i][j] to 1
        increment s
        decrease t by 1
    end of the block
    for i = 0 to 220 exclusive
        for j = 0 to 220 exclusive
            if vis[i][j] is equal to 1 and vis1[i][j] is equal to 1
                print "YES"
                return to indicate successful execution
            end of the block
        end of the block
    end of the block
    show "NO"
    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]:
create integer adj of size 1000 with array of size 1000
declare swap taking in floats &a and &b
    if b is less than a
        create float temp = b
        set b to a
        set a to temp
    end of the block
    return
end of the block
declare inside taking in float arrays p of size 2 and s of size 4 with array of size 2 and returning bool
    if s[0][0] is equal to s[1][0]
        create float l = s[0][0] and u = s[2][0]
        swap values of l and u
        if p[0] is less than or equal to u and p[0] is greater than or equal to 1
            set l to s[0][1]
            set u to s[1][1]
            swap values of l and u
            if p[1] is greater than or equal to 1 and p[1] is less than or equal to u
                return true
            otherwise do
                return false
        else do
            return false
        end of the block
    else
        make floats l = s[0][1] and u = s[2][1]
        swap values of l and u
        if p[1] is less than or equal to u and p[1] is greater than or equal to 1
            set l to s[0][0]
            set u to s[1][0]
            swap values of l and u
            if p[0] is greater than or equal to 1 and p[0] is less than or equal to u
                return true
            else
                return false
        otherwise
            return false
        end of the block
    end of the block
end of the block
define the main function
    make float arrays p1 of size 4 with array of size 2 and p2 of size 4 with array of size 2
    for i = 0 to (4) exclusive
        for j = 0 to (2) exclusive, read p1[i][j]
    end of the block
    for i = 0 to (4) exclusive
        for j = 0 to (2) exclusive, read p2[i][j]
    end of the block
    create bool ans = false
    for i = 0 to (4) exclusive
        if inside(p2[i], p1) is truthy, set ans to true
    end of the block
    make float array p of size 2 containing {0, 0}
    for i = 0 to (4) exclusive
        set p[0] to p[0] + p2[i][0]
        set p[1] to p[1] + p2[i][1]
    end of the block
    set p[0] to p[0] * 1.0 / 4
    set p[1] to p[1] * 1.0 / 4
    if inside(p, p1) is truthy, set ans to true
    for i = 0 to (4) exclusive
        make floats x = p1[i][0] - p1[i][1] and y = p1[i][0] + p1[i][1]
        set p1[i][0] to x
        set p1[i][1] to y
    end of the block
    for i = 0 to (4) exclusive
        make floats x = p2[i][0] - p2[i][1] and y = p2[i][0] + p2[i][1]
        set p2[i][0] to x
        set p2[i][1] to y
    end of the block
    for i = 0 to (4) exclusive
        if inside(p1[i], p2) is truthy, set ans to true
    end of the block
    if ans is truthy
        print "YES\n"
    else do
        show "NO\n"
    end of the block
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]:
make string s
in function ok with return type boolean and parameter string t
    make int msk = 0
    for i = 0 to (cast t size to int) exclusive
        if isupper(t[i]) then set msk to msk bitwise or 1
        if islower(t[i]) then set msk to msk bitwise or1
        if isdigit(t[i]) then set msk to msk bitwise or 1
    end of the block
    return msk is equal to 7
end of the block
define the main function
    make integer t
    read t
    for i = 0 to t exclusive
        read s
        if ok(s)
            print s
            continue
        end of the block
        make boolean fnd = false
        for i = 0 to (cast s size to int) exclusive
            make string t = s
            set t[i] to '1'
            if ok(t)
                print t
                set fnd to true
                break
            end of the block
            set t[i] to 'a'
            if ok(t)
                print t
                set fnd to true
                break
            end of the block
            set t[i] to 'A'
            if ok(t)
                print t
                set fnd to true
                break
            end of the block
        end of the block
        if fnd then continue
        if isupper(s[2])
            set s[0] to 'a'
            set s[1] to '1'
            print s
            continue
        end of the block
        if islower(s[2])
            set s[0] to 'A'
            set s[1] to '1'
            print s
            continue
        end of the block
        if isdigit(s[2])
            set s[0] to 'a'
            set s[1] to 'A'
            print s
            continue
        end of the block
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

string s;
bool ok(string t) {
    int msk = 0;
    for (int i = 0; i < int(t.size()); ++i) {
        if (isupper(t[i])) msk |= 1;
        if (islower(t[i])) msk |= 2;
        if (isdigit(t[i])) msk |= 4;
    }
    return msk == 7;
}
int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        cin >> s;
        if (ok(s)) {
            cout << s << endl;
            continue;
        }
        bool fnd = false;
        for (int i = 0; i < int(s.size()); ++i) {
            string t = s;
            t[i] = '1';
            if (ok(t)) {
                cout << t << endl;
                fnd = true;
                break;
            }
            t[i] = 'a';
            if (ok(t)) {
                cout << t << endl;
                fnd = true;
                break;
            }
            t[i] = 'A';
            if (ok(t)) {
                cout << t << endl;
                fnd = true;
                break;
            }
        }
        if (fnd) continue;
        if (isupper(s[2])) {
            s[0] = 'a';
            s[1] = '1';
            cout << s << endl;
            continue;
        }
        if (islower(s[2])) {
            s[0] = 'A';
            s[1] = '1';
            cout << s << endl;
            continue;
        }
        if (isdigit(s[2])) {
            s[0] = 'a';
            s[1] = 'A';
            cout << s << endl;
            continue;
        }
    }
    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 INF = 1e9 + 10
declare map from integer to character rep
declare integer arrays cnt size 3, tp size 110
declare con with character ch as argument, returning integer
    if 'a' is less than or equal to ch and ch is less than or equal to 'z', return 0 from function
    if 'A' is less than or equal to ch and ch is less than or equal to 'Z', return 1 from function
    return 2
end of the block
define the main function
    let rep[1] be 'a'
    let rep[2] be 'A'
    let rep[4] be '1'
    declare integer Tst
    read Tst
    while decrement Tst is true
        declare string s
        read s
        declare integer msk = 0
        let cnt[0] be cnt[1] be cnt[2] be 0
        for i = 0 to integer casted size of s exclusive
            let tp[i] be result of run con(s[i])
            let msk be msk bitwise or ( 1 bitshift left tp[i] )
            increment cnt[tp[i]]
        end of the block
        if msk is 7
            print s, '\n'
        else if result of run __builtin_popcount(msk) is 2
            for i = 0 to integer casted size of s exclusive
                if cnt[tp[i]] is greater than 1
                    let s[i] be rep[7 bitwise xor msk]
                    end loop
                end of the block
            print s, '\n'
        else
            declare integer M = 7 bitwise xor msk
            declare integer t = result of run __builtin_ctz(M)
            let M be M bitwise xor ( 1 bitshift left t )
            let s[0] be rep[1 bitshift left t]
            let s[1] be rep[1 bitshift left result of run __builtin_ctz(M)]
            print s, '\n'
        end of the block
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

const int INF = 1e9 + 10;
map<int, char> rep;
int cnt[3], tp[110];
int con(char ch) {
    if ('a' <= ch && ch <= 'z') return 0;
    if ('A' <= ch && ch <= 'Z') return 1;
    return 2;
}
int main() {
    rep[1] = 'a';
    rep[2] = 'A';
    rep[4] = '1';
    int Tst;
    cin >> Tst;
    while (Tst--) {
        string s;
        cin >> s;
        int msk = 0;
        cnt[0] = cnt[1] = cnt[2] = 0;
        for (int i = 0; i < ((int)(s).size()); i++) {
            tp[i] = con(s[i]);
            msk |= 1 << tp[i];
            ++cnt[tp[i]];
        }
        if (msk == 7)
            cout << s << '\n';
        else if (__builtin_popcount(msk) == 2) {
            for (int i = 0; i < ((int)(s).size()); i++)
                if (cnt[tp[i]] > 1) {
                    s[i] = rep[7 ^ msk];
                    break;
                }
            cout << s << '\n';
        } else {
            int M = 7 ^ msk;
            int t = __builtin_ctz(M);
            M ^= 1 << t;
            s[0] = rep[1 << t];
            s[1] = rep[1 << (__builtin_ctz(M))];
            cout << s << '\n';
        }
    }
    return 0;
}


[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
define the main function
    n = int
    read n
    let num = 0, chr = 0, CHR = 0 be ints
    str = string
    for i = 0 to n exclusvie
        read str
        for j = 0 to length of str exclusive
            if str at j is between 'a' and 'z' both inclusive
                increment chr
            else if str at j is between 'A' and 'Z' both inclusive
                increment CHR
            else
                increment num
            end of the block
        end of the block
        if chr = and CHR = 0
            insert "aA" int str at 0
            call erase on str with args 2, 2
        else if chr and num are both = 0
            insert "a1" into str[0]
            call erase on str with args 2, 2
        else if CHR and num are both = 0
            insert "A1" into str[0]
            erase 2, 2 form str
        else if chr = 0
            for j = 0 to length of str
                if str at j >= 'A' bit and str[j] <= 'Z' bit and CHR > 1
                    insert "a" in str at j
                    erase j+1, 1 form str
                    exit loop
                else if str[j] is >= '0' bit and str[j] <= '9' bit and num > 1
                    insert "a", j into str
                    erase j+1, 1 from str
                    exit loop
                end of the block
            end of the block
        else if CHR = 0
            for j = 0 to length of str
                if str at j >= 'a' bit and str[j] <= 'z' bit and chr > 1
                    call insert on str with args j, "A"
                    erase j+1, 1 from str
                    exit loop
                else if str at j >= 'a' bit and str[j] <= 'z' bit and num > 1
                    call insert on str with args j, "A"
                    erase j+1, 1 from str
                    exit loop
                end of the block
            end of the block
        else if num = 0
            for j = 0 to length of str
                if str at j >= 'a' bit and str[j] <= 'z' bit and chr > 1
                    insert j, "1" into str
                    erase j+1, 1 from str
                    exit loop
                else if str at j >= 'A' bit and str[j] <= 'Z' bit and CHR > 1
                    insert j, "1" into str
                    erase j+1, 1 from str
                    exit loop
                end of the block
            end of the block
        end of the block
        print str
        set num to 0
        set chr to 0
        set CHR to 0
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n;
    cin >> n;
    int num = 0, chr = 0, CHR = 0;
    string str;
    for (int i = 0; i < n; i++) {
        cin >> str;
        for (int j = 0; j < str.length(); j++) {
            if (str[j] >= 'a' & str[j] <= 'z') {
                chr++;
            } else if (str[j] >= 'A' & str[j] <= 'Z') {
                CHR++;
            } else {
                num++;
            }
        }
        if (chr == 0 && CHR == 0) {
            str.insert(0, "aA");
            str.erase(2, 2);
        } else if (chr == 0 && num == 0) {
            str.insert(0, "a1");
            str.erase(2, 2);
        } else if (CHR == 0 && num == 0) {
            str.insert(0, "A1");
            str.erase(2, 2);
        } else if (chr == 0) {
            for (int j = 0; j < str.length(); j++) {
                if (str[j] >= 'A' & str[j] <= 'Z' & CHR > 1) {
                    str.insert(j, "a");
                    str.erase(j + 1, 1);
                    break;
                } else if (str[j] >= '0' & str[j] <= '9' & num > 1) {
                    str.insert(j, "a");
                    str.erase(j + 1, 1);
                    break;
                }
            }
        } else if (CHR == 0) {
            for (int j = 0; j < str.length(); j++) {
                if (str[j] >= 'a' & str[j] <= 'z' & chr > 1) {
                    str.insert(j, "A");
                    str.erase(j + 1, 1);
                    break;
                } else if (str[j] >= '0' & str[j] <= '9' & num > 1) {
                    str.insert(j, "A");
                    str.erase(j + 1, 1);
                    break;
                }
            }
        } else if (num == 0) {
            for (int j = 0; j < str.length(); j++) {
                if (str[j] >= 'a' & str[j] <= 'z' & chr > 1) {
                    str.insert(j, "1");
                    str.erase(j + 1, 1);
                    break;
                } else if (str[j] >= 'A' & str[j] <= 'Z' & CHR > 1) {
                    str.insert(j, "1");
                    str.erase(j + 1, 1);
                    break;
                }
            }
        }
        cout << str << endl;
        num = 0;
        chr = 0;
        CHR = 0;
    }
    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 ok with string t as argument, returning boolean
    declare integer msk = 0
    for i = 0 to integer casted size of t exclusive
        if t[i] is upper case, let msk be msk bitwise or 1
        if t[i] is lower case, let msk be msk bitwise or 2
        if t[i] is digit, let msk be msk bitwise or 4
    end of the block
    return mks is 7
end of the block
define the main function
    declare integer t
    declare string s
    read t
    for i = 0 to t exclusive
        read s
        if result of run ok(s) is true
            print s and newline
            end current loop iteration
        end of the block
        declare boolean fnd = false
        for i = 0 to integer casted size of s exclusive
            deeclare string t = s
            let t[i] be '1'
            if result of run ok(t) is true
                print t, newline
                let fnd be true
                end loop
            end of the block
            let t[i] be 'a'
            if result of run ok(t) is true
                print t, newline
                let fnd be true
                end loop
            end of the block
            let t[i] be 'A'
            if result of run ok(t) is true
                print t, newline
                let fnd be true
                end loop
            end of the block
        end of the block
        if fnd is true, end loop iteration
        if s[2] is upper case
            let s[0] be 'a'
            let s[1] be '1'
            print s, newline
            end loop iteration
        end of the block
        if s[2] is lower case
            let s[0] be 'A'
            let s[1] be '1'
            print s, newline
            end loop iteration
        end of the block
        if s[2] is digit
            let s[0] be 'a'
            let s[1] be 'A'
            print s, newline
            end loop iteration
        end of the block
    end of the block
end of the block

[CODE]:

bool ok(string t) {
    int msk = 0;
    for (int i = 0; i < int(t.size()); ++i) {
        if (isupper(t[i])) msk |= 1;
        if (islower(t[i])) msk |= 2;
        if (isdigit(t[i])) msk |= 4;
    }
    return msk == 7;
}
int main() {
    int t;
    string s;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        cin >> s;
        if (ok(s)) {
            cout << s << endl;
            continue;
        }
        bool fnd = false;
        for (int i = 0; i < int(s.size()); ++i) {
            string t = s;
            t[i] = '1';
            if (ok(t)) {
                cout << t << endl;
                fnd = true;
                break;
            }
            t[i] = 'a';
            if (ok(t)) {
                cout << t << endl;
                fnd = true;
                break;
            }
            t[i] = 'A';
            if (ok(t)) {
                cout << t << endl;
                fnd = true;
                break;
            }
        }
        if (fnd) continue;
        if (isupper(s[2])) {
            s[0] = 'a';
            s[1] = '1';
            cout << s << endl;
            continue;
        }
        if (islower(s[2])) {
            s[0] = 'A';
            s[1] = '1';
            cout << s << endl;
            continue;
        }
        if (isdigit(s[2])) {
            s[0] = 'a';
            s[1] = 'A';
            cout << s << endl;
            continue;
        }
    }
}


[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 map of strings to integers M
create 2d array of booleans like with size 7 by 7
declare strings s1, s2 and temp
create integer n and integer array g with size 3
create an array of integers team with size 3
create an array of integers heros with size 7
create integer b1 = INT_MAX and b2= -1
void function back_track with int argument a
    declare integers i and j
    if a is equal to 7
        declare an array of integers count with elements 0, 0, 0
        create ints mx = - and mn = INT_MAX
        for i = 0 to 7 exclusive increment count[heros[i]]
        if count[0], count[1] or count[2] = 0, return
        for i from 0 to 7 exclusive
            declare integer temp = g[heros[i]] / count[heros[i]]
            change mx to max of mx and temp
            change mn to min of mn and temp
        end of the block
        if mx - mn is greater than b1, return
        create int likeNum = 0
        loop i from 0 to 7 exclusive
            loop j from 0 to 7 exclusive
                if heros[i] = heros[j] and like[i][j] != 0, increment likeNum by one
        if mx - mn < b1 or mx - mn = b1and likeNum > b2
            set b1 to mx - mn
            set b2 to likeNum
        end of the block
        return
    end of the block
    loop i from 0 to 3 exclusive
        change heros[a] to i
        call back_track(a + 1)
    end of the block
end of the block
define the main function
    assign 0 to M["Anka"]
    assign 1 to M["Chapay"]
    assign 2 to M["Cleo"]
    assign 3 to M["Troll"]
    assign 4 to M["Dracul"]
    assign 5 to M["Snowy"]
    assign 6 to M["Hexadecimal"]
    loop i from 0 to 7 exclusive
        loop j from 0 to 7 exclusive, change like[i][j] to false
    read n
    while n != 0, decrement it and continue the loop
        read input to s1, temp and s2
        set value of like[M[s1]][M[s2]] to true
    end of the block
    read g[0], g[1] and g[2]
    call back_track(0)
    print b1, ' ' and b2
    return to indicate successful execution
end of the block

[CODE]:

map<string, int> M;
bool like[7][7];
string s1, s2, temp;
int n, g[3];
int team[3];
int heros[7];
int b1 = INT_MAX, b2 = -1;
void back_track(int a) {
    int i, j;
    if (a == 7) {
        int count[3] = {0, 0, 0};
        int mx = -1, mn = INT_MAX;
        for (i = 0; i < 7; i++) count[heros[i]]++;
        if (count[0] == 0 || count[1] == 0 || count[2] == 0) return;
        for (i = 0; i < 7; i++) {
            int temp = g[heros[i]] / count[heros[i]];
            mx = max(mx, temp);
            mn = min(mn, temp);
        }
        if (mx - mn > b1) return;
        int likeNum = 0;
        for (i = 0; i < 7; i++)
            for (j = 0; j < 7; j++)
                if (heros[i] == heros[j] && like[i][j]) likeNum++;
        if ((mx - mn) < b1 || (mx - mn) == b1 && likeNum > b2) {
            b1 = mx - mn;
            b2 = likeNum;
        }
        return;
    }
    for (i = 0; i < 3; i++) {
        heros[a] = i;
        back_track(a + 1);
    }
}
int main() {
    M["Anka"] = 0;
    M["Chapay"] = 1;
    M["Cleo"] = 2;
    M["Troll"] = 3;
    M["Dracul"] = 4;
    M["Snowy"] = 5;
    M["Hexadecimal"] = 6;
    for (int i = 0; i < 7; i++)
        for (int j = 0; j < 7; j++) like[i][j] = false;
    cin >> n;
    while (n--) {
        cin >> s1 >> temp >> s2;
        like[M[s1]][M[s2]] = true;
    }
    cin >> g[0] >> g[1] >> g[2];
    back_track(0);
    cout << b1 << ' ' << b2 << endl;
    return 0;
}

3
Troll likes Dracul
Dracul likes Anka
Snowy likes Hexadecimal
210 200 180

2
Anka likes Chapay
Chapay likes Anka
10000 50 50

11
Snowy likes Dracul
Anka likes Dracul
Chapay likes Snowy
Hexadecimal likes Troll
Anka likes Cleo
Chapay likes Dracul
Anka likes Chapay
Snowy likes Troll
Anka likes Hexadecimal
Cleo likes Chapay
Troll likes Cleo
100 100 100

14
Chapay likes Cleo
Cleo likes Anka
Dracul likes Snowy
Snowy likes Cleo
Chapay likes Anka
Snowy likes Anka
Chapay likes Troll
Troll likes Anka
Anka likes Snowy
Chapay likes Dracul
Dracul likes Anka
Hexadecimal likes Chapay
Snowy likes Dracul
Cleo likes Dracul
15 15 15

4
Anka likes Cleo
Snowy likes Cleo
Anka likes Hexadecimal
Cleo likes Snowy
1 1 1

8
Snowy likes Anka
Hexadecimal likes Snowy
Troll likes Dracul
Hexadecimal likes Troll
Snowy likes Troll
Anka likes Snowy
Snowy likes Chapay
Anka likes Chapay
70 70 70

3
Chapay likes Hexadecimal
Anka likes Cleo
Troll likes Snowy
15 15000 90

13
Cleo likes Hexadecimal
Cleo likes Snowy
Hexadecimal likes Anka
Anka likes Snowy
Troll likes Snowy
Chapay likes Hexadecimal
Hexadecimal likes Snowy
Snowy likes Chapay
Troll likes Cleo
Anka likes Hexadecimal
Hexadecimal likes Cleo
Chapay likes Dracul
Snowy likes Dracul
1000000000 2000000000 1000000000

12
Cleo likes Hexadecimal
Chapay likes Anka
Hexadecimal likes Cleo
Anka likes Snowy
Anka likes Cleo
Dracul likes Snowy
Anka likes Troll
Snowy likes Anka
Cleo likes Anka
Hexadecimal likes Troll
Hexadecimal likes Chapay
Snowy likes Troll
1000000000 1 2000000000

2
Snowy likes Hexadecimal
Troll likes Dracul
2000000000 2000000000 2000000000

12
Snowy likes Chapay
Cleo likes Dracul
Hexadecimal likes Snowy
Hexadecimal likes Anka
Dracul likes Chapay
Cleo likes Troll
Dracul likes Snowy
Snowy likes Dracul
Troll likes Chapay
Dracul likes Anka
Chapay likes Hexadecimal
Troll likes Dracul
436364663 856574374 347564737

12
Anka likes Dracul
Dracul likes Troll
Cleo likes Troll
Snowy likes Hexadecimal
Hexadecimal likes Chapay
Cleo likes Dracul
Cleo likes Chapay
Hexadecimal likes Anka
Snowy likes Cleo
Hexadecimal likes Snowy
Cleo likes Snowy
Chapay likes Snowy
584329075 428752235 675234087

8
Anka likes Chapay
Dracul likes Snowy
Snowy likes Cleo
Cleo likes Anka
Cleo likes Troll
Hexadecimal likes Troll
Troll likes Cleo
Snowy likes Dracul
325432666 254352394 547360304

18
Snowy likes Troll
Chapay likes Hexadecimal
Cleo likes Snowy
Dracul likes Snowy
Snowy likes Chapay
Troll likes Cleo
Snowy likes Anka
Dracul likes Hexadecimal
Hexadecimal likes Anka
Anka likes Hexadecimal
Anka likes Chapay
Troll likes Anka
Anka likes Snowy
Anka likes Troll
Snowy likes Cleo
Hexadecimal likes Troll
Hexadecimal likes Dracul
Cleo likes Anka
20000 1000 20000

6
Chapay likes Troll
Troll likes Cleo
Cleo likes Troll
Chapay likes Snowy
Anka likes Snowy
Troll likes Dracul
987499608 272739716 133573597

6
Anka likes Troll
Troll likes Chapay
Troll likes Hexadecimal
Hexadecimal likes Cleo
Snowy likes Hexadecimal
Chapay likes Troll
740076959 230477703 987799796

17
Cleo likes Dracul
Troll likes Cleo
Anka likes Chapay
Anka likes Troll
Chapay likes Snowy
Troll likes Snowy
Chapay likes Dracul
Hexadecimal likes Snowy
Dracul likes Snowy
Troll likes Hexadecimal
Hexadecimal likes Anka
Cleo likes Snowy
Hexadecimal likes Dracul
Snowy likes Chapay
Snowy likes Hexadecimal
Snowy likes Dracul
Dracul likes Troll
112909524 619275170 403563648

18
Anka likes Troll
Dracul likes Chapay
Hexadecimal likes Dracul
Chapay likes Dracul
Anka likes Hexadecimal
Snowy likes Cleo
Dracul likes Anka
Snowy likes Anka
Snowy likes Hexadecimal
Dracul likes Troll
Dracul likes Snowy
Hexadecimal likes Anka
Chapay likes Hexadecimal
Snowy likes Dracul
Cleo likes Snowy
Chapay likes Cleo
Anka likes Dracul
Troll likes Anka
838821770 712931449 361810998

18
Hexadecimal likes Chapay
Troll likes Dracul
Troll likes Snowy
Cleo likes Dracul
Chapay likes Snowy
Dracul likes Chapay
Cleo likes Snowy
Dracul likes Hexadecimal
Troll likes Anka
Anka likes Troll
Hexadecimal likes Dracul
Chapay likes Hexadecimal
Cleo likes Chapay
Anka likes Hexadecimal
Snowy likes Dracul
Chapay likes Troll
Anka likes Snowy
Dracul likes Cleo
240256138 922743697 38909902

16
Chapay likes Snowy
Hexadecimal likes Anka
Chapay likes Troll
Dracul likes Cleo
Troll likes Hexadecimal
Hexadecimal likes Dracul
Chapay likes Cleo
Snowy likes Cleo
Snowy likes Anka
Troll likes Chapay
Snowy likes Hexadecimal
Troll likes Snowy
Cleo likes Hexadecimal
Anka likes Snowy
Snowy likes Chapay
Anka likes Dracul
843382501 58524777 503038818

5
Troll likes Chapay
Anka likes Snowy
Anka likes Dracul
Chapay likes Anka
Snowy likes Troll
709201888 431802832 597079932

18
Cleo likes Snowy
Snowy likes Hexadecimal
Cleo likes Hexadecimal
Troll likes Dracul
Hexadecimal likes Snowy
Dracul likes Troll
Chapay likes Anka
Chapay likes Cleo
Troll likes Chapay
Hexadecimal likes Chapay
Anka likes Snowy
Troll likes Snowy
Dracul likes Snowy
Dracul likes Chapay
Chapay likes Troll
Cleo likes Troll
Hexadecimal likes Cleo
Anka likes Chapay
864225278 509037060 402199775

12
Cleo likes Hexadecimal
Troll likes Cleo
Anka likes Cleo
Hexadecimal likes Troll
Anka likes Snowy
Hexadecimal likes Anka
Troll likes Hexadecimal
Troll likes Anka
Dracul likes Cleo
Cleo likes Troll
Dracul likes Troll
Chapay likes Anka
762445890 377707484 324080158

21
Chapay likes Dracul
Snowy likes Chapay
Snowy likes Troll
Cleo likes Chapay
Cleo likes Troll
Chapay likes Cleo
Snowy likes Anka
Dracul likes Anka
Troll likes Snowy
Snowy likes Cleo
Chapay likes Hexadecimal
Cleo likes Anka
Cleo likes Snowy
Hexadecimal likes Cleo
Hexadecimal likes Snowy
Hexadecimal likes Anka
Hexadecimal likes Troll
Anka likes Snowy
Dracul likes Troll
Chapay likes Anka
Snowy likes Hexadecimal
482557397 502108264 750230216

6
Troll likes Chapay
Hexadecimal likes Snowy
Cleo likes Dracul
Cleo likes Anka
Chapay likes Anka
Anka likes Chapay
758376921 432619768 578580897

5
Chapay likes Cleo
Anka likes Hexadecimal
Anka likes Chapay
Cleo likes Troll
Anka likes Cleo
299076810 225593528 36830738

13
Anka likes Cleo
Cleo likes Troll
Chapay likes Cleo
Snowy likes Troll
Chapay likes Anka
Chapay likes Snowy
Snowy likes Chapay
Anka likes Snowy
Snowy likes Dracul
Cleo likes Hexadecimal
Dracul likes Chapay
Anka likes Hexadecimal
Snowy likes Cleo
554338888 280967932 682619964

17
Hexadecimal likes Chapay
Chapay likes Snowy
Chapay likes Troll
Anka likes Hexadecimal
Cleo likes Troll
Snowy likes Cleo
Cleo likes Anka
Cleo likes Hexadecimal
Anka likes Snowy
Chapay likes Hexadecimal
Anka likes Cleo
Dracul likes Snowy
Chapay likes Anka
Troll likes Hexadecimal
Troll likes Anka
Anka likes Dracul
Hexadecimal likes Anka
828886798 548024213 166661324

2
Troll likes Cleo
Anka likes Cleo
14344913 559182022 405430772

22
Cleo likes Snowy
Cleo likes Troll
Chapay likes Dracul
Snowy likes Troll
Dracul likes Chapay
Dracul likes Snowy
Chapay likes Cleo
Snowy likes Chapay
Dracul likes Troll
Anka likes Hexadecimal
Snowy likes Anka
Hexadecimal likes Cleo
Hexadecimal likes Troll
Dracul likes Anka
Cleo likes Hexadecimal
Hexadecimal likes Dracul
Chapay likes Troll
Chapay likes Hexadecimal
Anka likes Snowy
Troll likes Hexadecimal
Snowy likes Hexadecimal
Anka likes Chapay
458053183 602148195 994999698

5
Troll likes Dracul
Anka likes Chapay
Cleo likes Anka
Chapay likes Cleo
Snowy likes Hexadecimal
222 400 400