#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define sz size
#define all(x) x.begin(),x.end()
#define boost ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
// solve it
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const int inf = 1e9 + 7;
ll n, a, b, c;
ll hpp[26][26]={};
char names[7]={'A', 'B', 'C', 'T', 'D', 'S', 'H'};
ll mx=inf, mn=-inf, fr=0;
vector <char> cnt1, cnt2, cnt3;
void f(ll k) {
if(k==-1 && (cnt1.sz()==0 || cnt2.sz()==0 || cnt3.sz()==0)) {
int none;
none=1;
} else if(k==-1) {
ll lx=0, ln=0, lr=0;
for(ll i=0; i<cnt1.sz(); i++) {
for(ll j=0; j<cnt1.sz(); j++) {
if(hpp[cnt1[i]-'A'][cnt1[j]-'A'] != 0) lr++;
}
}
for(ll i=0; i<cnt2.sz(); i++) {
for(ll j=0; j<cnt2.sz(); j++) {
if(hpp[cnt2[i]-'A'][cnt2[j]-'A'] != 0) lr++;
}
}
for(ll i=0; i<cnt3.sz(); i++) {
for(ll j=0; j<cnt3.sz(); j++) {
if(hpp[cnt3[i]-'A'][cnt3[j]-'A'] != 0) lr++;
}
}
lx = max(a/cnt1.sz(), max(b/cnt2.sz(), c/cnt3.sz()));
ln = min(a/cnt1.sz(), min(b/cnt2.sz(), c/cnt3.sz()));
if((mx-mn) >= (lx-ln)) {
if(mx-mn==lx-ln) fr=max(fr,lr);
else fr=lr;
mx=lx, mn=ln;
}
} else {
for(int i=1; i<=3; i++) {
if(i==1) {
cnt1.pb(names[k]);
f(k-1);
cnt1.pop_back();
} else if(i==2) {
cnt2.pb(names[k]);
f(k-1);
cnt2.pop_back();
} else {
cnt3.pb(names[k]);
f(k-1);
cnt3.pop_back();
}
}
}
}
void solve() {
cin >> n;
for(int i=1; i<=n; i++) {
string s1,s2,s3;
cin >> s1 >> s2 >> s3;
if(s1=="Chapay") s1[0]='B';
if(s3=="Chapay") s3[0]='B';
hpp[s1[0]-'A'][s3[0]-'A']=1;
}
cin >> a >> b >> c;
f(6);
cout << mx-mn << " " << fr;
}
int main() {
boost;
srand(time(0));
//freopen("sparse.in", "r", stdin);
//freopen("sparse.out", "w", stdout);
int ttt;
ttt=1;
while(ttt--){
solve();
}
return 0;
}
1920. Build Array from Permutation | 494. Target Sum |
797. All Paths From Source to Target | 1547B - Alphabetical Strings |
1550A - Find The Array | 118B - Present from Lena |
27A - Next Test | 785. Is Graph Bipartite |
90. Subsets II | 1560A - Dislike of Threes |
36. Valid Sudoku | 557. Reverse Words in a String III |
566. Reshape the Matrix | 167. Two Sum II - Input array is sorted |
387. First Unique Character in a String | 383. Ransom Note |
242. Valid Anagram | 141. Linked List Cycle |
21. Merge Two Sorted Lists | 203. Remove Linked List Elements |
733. Flood Fill | 206. Reverse Linked List |
83. Remove Duplicates from Sorted List | 116. Populating Next Right Pointers in Each Node |
145. Binary Tree Postorder Traversal | 94. Binary Tree Inorder Traversal |
101. Symmetric Tree | 77. Combinations |
46. Permutations | 226. Invert Binary Tree |