[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]:
let mat be a logical matrix of size 7x7
in int function calc which takes string s
    let r = 0 = integer
    for i = 0 to 7 exlusive
        for j = 0 to 7 exclusive
            if s at i is same as s at j and mat at i and j is not 0 then increment r
        end of the block
    end of the block
    return r
end of the block
define the main function
    let n, ans, temp, lans, ltemp be int with ans = temp = lans = ltemp = INT_MAX
    read n
    let arr, t be long long arrays of size 3 both with all 0
    for i = 0 to 7 exclusive
        for j = 0 to 7 exclusive, set mat[i][j] to false
    let hero be a map form string to int
    set hero at "Anka" to 0
    set hero at "Chapay" to 1
    set hero["Cleo"] = 2
    set hero["Dracul"] to 3
    set hero["Dracul"] tp 4
    hero["Snowy"] = 5
    set hero at Hexadecimal = 6
    let x, y, z, q be strings
    for i = 0 to n exclusive
        read x, y, z
        set mat[hero[x]][hero[z]] to true
    end of the block
    read arr at 0, arra at 1, arr at 2
    sort the first 3 elements of arr
    let h be a set of strings
    let it be a set string iterator
    set t at 2 = arr[2] / 5
    t[1] = arr[1]
    set t at 0 to arr[0]
    sort the first 3 elements of t
    set temp to t[2] - t[0]
    if temp is less than ans
        set ans to temp
        call insert on h with arg "aaaaabc"
    end of the block
    set t at 2 = arr[2]/4
    set t at 1 = arr[1]/2
    set t at 0 to arr at 0
    sort the first three elements of arr
    set temp = t[2] - t[0]
    if temp is less than ans
        set ans to temp
        clear h
        insert "aaaabbc" in h
    else if temp is same as ans
        insert "aaaabbc" in h
    end of the block
    set t[2] = arr[2] / 3
    set t[1] = arr[1] / 3
    set t at 0 to arr at 0
    sort the first 3 elements of t
    set tempo to t[2] - t[0]
    if temp < ans
        set ans to temp
        clear h
        insert "aaaabbc" in h
    else if temp is same as ans
        insert "aaaabbc" in h
    end of the block
    set t[2] to arr[2] / 3
    set t[1] to arr[1] / 2
    set t[0] to arr[0] / 2
    sort the first 3 elements of t
    set temp to t[2] - t[0]
    if temp is less than ans
        set ans to temp
        clear h
        insert "aaabbcc" in h
    if temp = ans
        insert "aaabbcc" in h
    end of the block
    while h is not empty
        set q to be q * the first element of h
        do loop
            set ltemp to calc of q
            if ltemp is greater than lans then set lans to ltemp
        while the result of calling next_permutation with args start of q and end of q is not 0
        erase q from h
    end of the block
    print ans and space and lans
    return to indicate successful execution
end of the block

[CODE]:

bool mat[7][7];
int calc(string s) {
    int r = 0;
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            if (s[i] == s[j] && mat[i][j]) r++;
        }
    }
    return r;
}
int main() {
    int n, ans = INT_MAX, temp = INT_MAX, lans = 0, ltemp = 0;
    cin >> n;
    long long arr[3], t[3] = {0, 0, 0};
    for (int i = 0; i < 7; i++)
        for (int j = 0; j < 7; j++) mat[i][j] = false;
    map<string, int> hero;
    hero["Anka"] = 0;
    hero["Chapay"] = 1;
    hero["Cleo"] = 2;
    hero["Troll"] = 3;
    hero["Dracul"] = 4;
    hero["Snowy"] = 5;
    hero["Hexadecimal"] = 6;
    string x, y, z, q;
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> z;
        mat[hero[x]][hero[z]] = true;
    }
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr, arr + 3);
    set<string> h;
    set<string>::iterator it;
    t[2] = arr[2] / 5;
    t[1] = arr[1];
    t[0] = arr[0];
    sort(t, t + 3);
    temp = t[2] - t[0];
    if (temp < ans) {
        ans = temp;
        h.insert("aaaaabc");
    }
    t[2] = arr[2] / 4;
    t[1] = arr[1] / 2;
    t[0] = arr[0];
    sort(t, t + 3);
    temp = t[2] - t[0];
    if (temp < ans) {
        ans = temp;
        h.clear();
        h.insert("aaaabbc");
    } else if (temp == ans) {
        h.insert("aaaabbc");
    }
    t[2] = arr[2] / 3;
    t[1] = arr[1] / 3;
    t[0] = arr[0];
    sort(t, t + 3);
    temp = t[2] - t[0];
    if (temp < ans) {
        ans = temp;
        h.clear();
        h.insert("aaabbbc");
    } else if (temp == ans) {
        h.insert("aaabbbc");
    }
    t[2] = arr[2] / 3;
    t[1] = arr[1] / 2;
    t[0] = arr[0] / 2;
    sort(t, t + 3);
    temp = t[2] - t[0];
    if (temp < ans) {
        ans = temp;
        h.clear();
        h.insert("aaabbcc");
    } else if (temp == ans) {
        h.insert("aaabbcc");
    }
    while (!h.empty()) {
        q = *(h.begin());
        do {
            ltemp = calc(q);
            if (ltemp > lans) lans = ltemp;
        } while (next_permutation(q.begin(), q.end()));
        h.erase(q);
    }
    cout << ans << " " << lans << endl;
    return 0;
}