#include #include #include #include #include using namespace std; const int N = 5; int main() { array cs, bs{}; vector rs[3]; map m; for (int i = 0; i < N; i++) { string s; cin >> s >> cs[i]; m[s] = i; } for (int i = 0; i < 3; i++) { int n; cin >> n; for (int j = 0; j < n; j++) { string s; cin >> s; rs[i].emplace_back(m[s]); } } for (int i = 0; i < 3; i++) { rs[i].emplace_back(rs[i][0]); rs[i].emplace_back(rs[i][1]); } for (int i = 0; i < rs[0].size()-2; i++) { for (int j = 0; j < rs[1].size()-2; j++) { for (int k = 0; k < rs[2].size()-2; k++) { if (rs[0][i] == rs[1][j] && rs[1][j] == rs[2][k]) { bs[rs[0][i]]++; } if (rs[0][i + 1] == rs[1][j + 1] && rs[1][j + 1] == rs[2][k + 1]) { bs[rs[0][i+1]]++; } if (rs[0][i + 2] == rs[1][j + 2] && rs[1][j + 2] == rs[2][k + 2]) { bs[rs[0][i+2]]++; } if (rs[0][i] == rs[1][j + 1] && rs[1][j + 1] == rs[2][k + 2]) { bs[rs[0][i]]++; } if (rs[0][i + 2] == rs[1][j + 1] && rs[1][j + 1] == rs[2][k]){ bs[rs[0][i+2]]++; } } } } double a = rs[0].size() - 2; double b = rs[1].size() - 2; double c = rs[2].size() - 2; double exp=0; for (int i = 0; i < N; i++) { exp += cs[i] / a * bs[i] / b; } exp /= c; cout << exp << endl; for (int i : bs) { cout << i << endl; } return 0; }