Time Limit: 8 sec / Memory Limit: 64 MB





Example

Input

2
4 2
4 0.4000000
3 0.5000000
4 1
5 0.3333333
5 3
5 0.7777777
4 0.1111111
2 0.0001111


Output

YES
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int T;

int main() {
  cin >> T;
  vector<double> es;
  for (int i = 0; i < T; i++) {
	int n, m;
	cin >> n >> m;
	vector<int> fs;
	vector<double> ps;
	double q = 0;
	for (int j = 0; j < m; j++) {
	  int face;
	  double p;
	  cin >> face >> p;
	  fs.push_back(face);
	  ps.push_back(p);
	  q += p;
	}
	q = 1 - q;
	double e = 0;
	double p = 1;
	for (int j = 0; j < 100; j++) {
	  for (int k = 0; k < m; k++) {
		e += p * ps[k] * fs[k];
	  }
	  p *= q;
	}
	es.push_back(e);
  }
  int P, Q;
  cin >> P >> Q;
  vector<int> fs;
  vector<double> ps;
  double q = 0;
  for (int i = 0; i < Q; i++) {
	int face;
	double p;
	cin >> face >> p;
	q += p;
	fs.push_back(face);
	ps.push_back(p);
  }
  q = 1 - q;
  double p = 1;
  double e = 0;
  for (int i = 0; i < 100; i++) {
	for (int k = 0; k < Q; k++) {
	  e += p * ps[k] * fs[k];
	}
	p *= q;
  }
  for (int i = 0; i < T; i++) {
	if ((es[i] - e) > 0.0000001) {
	  cout << "YES" << endl;
	  return 0;
	}
  }
  cout << "NO" << endl;
}