#include<bits/stdc++.h>
#include <string>
#include<iostream>
using namespace std;
struct List
{
int is_ture;
int start_time;//头指针计总分等待时间
int end_time;//头指针计最长等待时间
int wait_time;//代表服务了多少人
string name;
struct List *next;
};
void Insert_List(List *head, List *tail, List *L)
{
List *p = tail->next;
tail->next->next = L;
tail->next = L;
if(L->start_time > p->end_time)
{
L->end_time = L->start_time + L->wait_time;
L->wait_time = 0;
}
else
{
L->end_time = p->end_time + L->wait_time;
L->wait_time = p->end_time - L->start_time;
}
head->start_time += L->wait_time;
if(head->end_time < L->wait_time)
head->end_time = L->wait_time;
head->wait_time++;
}
void Get_Friend(List* head_list, List* tail_list, List* list_l, int i,int N, map<string, int> &name_list)
{
// printf("123\n");
Insert_List(head_list, tail_list, &list_l[i]);
list_l[i].is_ture = 0;
if(name_list.count(list_l[i].name) == 0)
return;
int pos = 1, j;
while(pos == 1)
{
pos = -1;
for(j = i + 1; j < N; j++)
{
if(list_l[i].end_time < list_l[j].start_time)
break;
if(name_list.count(list_l[j].name) == 1 && name_list[list_l[i].name] == name_list[list_l[j].name])
{
Insert_List(head_list, tail_list, &list_l[j]);
list_l[j].is_ture = 0;
pos = 1;
break;
}
}
i = j;
}
return;
}
void ListPrint_L(List *L)
{
//输出单链表
List *p=L->next; //p指向第一个元素结点
while(p!=NULL)
{
cout << p->name<< endl;
p=p->next;
}
}
int main()
{
int N, M, m;
string n;
map<string, int> name_list;
// char *name_list[102], name[400];
List head_list, tail_list, *list_l;
head_list.end_time = 0;
head_list.next = NULL;
head_list.start_time = 0;
head_list.wait_time = 0;
tail_list.next = &head_list;
scanf("%d %d", &N, &M);
for(int i = 0 ; i < M; i++)
{
scanf("%d", &m);
for(int j=0; j<m; j++)
{
cin >> n;
name_list[n] = i;
}
}
list_l = new List[N+1];
for(int i = 0; i < N; i++)
{
cin >> list_l[i].name;
scanf("%d %d", &list_l[i].start_time, &list_l[i].wait_time);
list_l[i].end_time = 0;
list_l[i].next = NULL;
list_l[i].is_ture = 1;
if(list_l[i].wait_time > 60)
list_l[i].wait_time = 60;
}
for(int i = 0; i < N; i++)
{
if(list_l[i].is_ture == 1)
{
Get_Friend(&head_list, &tail_list, list_l, i, N, name_list);
}
}
ListPrint_L(&head_list);
printf("%.1lf", double(head_list.start_time)/N);
}