#include <bits/stdc++.h>
using namespace std;
long long n,cnt=0;
int main(){
cin >> n;
for(int i=0;i<n;i++){
int a;
double b;
bool c;
cin >> a >> b >> c;
if(b and c0)cnt++;
else if(a1)cnt+=1;
else if(a2)cnt+=3;
else if(a3)cnt+=5;
else if(a4)cnt+=7;
else if(a5)cnt+=15;
else if(a==6)cnt+=1440;
}
if(cnt >= 14400)cout << "NO WAY!";
else cout << cnt << endl;
return 0;
}