#include "testlib.h"
#include <algorithm>

using std::min;
using std::max;

const int maxN = 200;

int n, s[maxN], t[maxN];
int ja[maxN], jt, jl, jr, pa[maxN], pt, pl, pr;

int main( int argc, char *argv[] )
{
  setName("ORSPC 2009: problem 'Show'");
  registerTestlibCmd(argc, argv);
  int n = inf.readInt();
  for (int i = 0; i < n; i++)
  {
    s[i] = inf.readInt();
    t[i] = inf.readInt();
  }
  
  for (int i = 0; i < n; i++)
    ja[i] = ans.readInt();
  for (int i = 0; i < n; i++)
    if (ja[i] < 0 || ja[i] > 2)
      quitf(_fail, "Jury: number %d incorrect (%d)", i + 1, ja[i]);
  for (int i = 0; i < n; i++)
    if (ja[i] == 1)
      for (int j = 0; j < n; j++)
        if (ja[j] == 2)
          if (max(s[i], s[j]) < min(s[i] + t[i], s[j] + t[j]))
            quitf(_fail, "Jury: tigers and lions meet during [%d, %d]",
              max(s[i], s[j]), min(s[i] + t[i], s[j] + t[j]));
  jt = jl = 0;
  for (int i = 0; i < n; i++)
    jl += ja[i] == 1, jt += ja[i] == 2;
  jr = min(jl, jt);
  
  for (int i = 0; i < n; i++)
    pa[i] = ouf.readInt();
  for (int i = 0; i < n; i++)
    if (pa[i] < 0 || pa[i] > 2)
      quitf(_wa, "Contestant: number %d incorrect (%d)", i + 1, pa[i]);
  for (int i = 0; i < n; i++)
    if (pa[i] == 1)
      for (int j = 0; j < n; j++)
        if (pa[j] == 2)
          if (max(s[i], s[j]) < min(s[i] + t[i], s[j] + t[j]))
            quitf(_wa, "Contestant: tigers and lions meet during [%d, %d]",
              max(s[i], s[j]), min(s[i] + t[i], s[j] + t[j]));
  pt = pl = 0;
  for (int i = 0; i < n; i++)
    pl += pa[i] == 1, pt += pa[i] == 2;
  pr = min(pl, pt);

  if (jr < pr)
    quitf(_fail, "%d possible, %d found", pr, jr);
  if (jr > pr)
    quitf(_wa, "%d possible, %d found", jr, pr);
  quitf(_ok, "%d", jr);
  return 0;
}
