#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
const int MAXN = 100000;
int n, m;
pair<string, int> a[MAXN];
string me;
int my;
int b[MAXN];
bool read() {
  if (!(cin >> n)) return false;
  for (int i = 0; i < n; ++i) {
    char buf[100];
    scanf(" %s %d", buf, &a[i].second);
    a[i].first = buf;
  }
  cin >> m;
  for (int i = 0; i < m; ++i) scanf("%d", &b[i]);
  cin >> me;
  return true;
}
inline bool cmp(const pair<string, int>& a, const pair<string, int>& b) {
  return make_pair(-a.second, a.first) < make_pair(-b.second, b.first);
}
inline bool better(const string& sa, int ca, const string& sb, int cb) {
  return ca > cb || ca == cb && sa < sb;
}
inline bool can_less(int cnt) {
  int us = a[my].second + b[m - 1];
  for (int i = n - 1, c = 0; c < cnt; --i) {
    if (i == my) continue;
    int give = b[cnt - 1 - c];
    if (better(a[i].first, a[i].second + give, me, us)) return false;
    ++c;
  }
  return true;
}
inline bool can_more(int cnt) {
  int us = a[my].second + b[0];
  for (int i = 0, c = 0; c < cnt; ++i) {
    if (i == my) continue;
    int give = b[m - cnt + c];
    if (better(me, us, a[i].first, a[i].second + give)) return false;
    ++c;
  }
  return true;
}
void solve() {
  sort(a, a + n, cmp);
  for (int i = 0; i < n; ++i)
    if (a[i].first == me) my = i;
  while (m < n) b[m++] = 0;
  sort(b, b + m);
  int lt = 0, rt = n - 1;
  while (lt < rt) {
    int mid = (lt + rt + 1) / 2;
    if (can_less(mid))
      lt = mid;
    else
      rt = mid - 1;
  }
  int ans_max = n - lt;
  lt = 0, rt = n - 1;
  while (lt < rt) {
    int mid = (lt + rt + 1) / 2;
    if (can_more(mid))
      lt = mid;
    else
      rt = mid - 1;
  }
  int ans_min = lt + 1;
  cout << ans_max << ' ' << ans_min << endl;
}
int main() {
  while (read()) solve();
}

### Prompt

Construct a cpp code solution to the problem outlined:

Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game! 

n racers take part in the championship, which consists of a number of races. After each race racers are arranged from place first to n-th (no two racers share the same place) and first m places are awarded. Racer gains bi points for i-th awarded place, which are added to total points, obtained by him for previous races. It is known that current summary score of racer i is ai points. In the final standings of championship all the racers will be sorted in descending order of points. Racers with an equal amount of points are sorted by increasing of the name in lexicographical order.

Unfortunately, the championship has come to an end, and there is only one race left. Vasya decided to find out what the highest and lowest place he can take up as a result of the championship.

Input

The first line contains number n (1 ≤ n ≤ 105) — number of racers. Each of the next n lines contains si and ai — nick of the racer (nonempty string, which consist of no more than 20 lowercase Latin letters) and the racer's points (0 ≤ ai ≤ 106). Racers are given in the arbitrary order.

The next line contains the number m (0 ≤ m ≤ n). Then m nonnegative integer numbers bi follow. i-th number is equal to amount of points for the i-th awarded place (0 ≤ bi ≤ 106).

The last line contains Vasya's racer nick.

Output

Output two numbers — the highest and the lowest place Vasya can take up as a result of the championship.

Examples

Input

3
teama 10
teamb 20
teamc 40
2
10 20
teama


Output

2 3

Input

2
teama 10
teamb 10
2
10 10
teamb


Output

2 2

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
const int MAXN = 100000;
int n, m;
pair<string, int> a[MAXN];
string me;
int my;
int b[MAXN];
bool read() {
  if (!(cin >> n)) return false;
  for (int i = 0; i < n; ++i) {
    char buf[100];
    scanf(" %s %d", buf, &a[i].second);
    a[i].first = buf;
  }
  cin >> m;
  for (int i = 0; i < m; ++i) scanf("%d", &b[i]);
  cin >> me;
  return true;
}
inline bool cmp(const pair<string, int>& a, const pair<string, int>& b) {
  return make_pair(-a.second, a.first) < make_pair(-b.second, b.first);
}
inline bool better(const string& sa, int ca, const string& sb, int cb) {
  return ca > cb || ca == cb && sa < sb;
}
inline bool can_less(int cnt) {
  int us = a[my].second + b[m - 1];
  for (int i = n - 1, c = 0; c < cnt; --i) {
    if (i == my) continue;
    int give = b[cnt - 1 - c];
    if (better(a[i].first, a[i].second + give, me, us)) return false;
    ++c;
  }
  return true;
}
inline bool can_more(int cnt) {
  int us = a[my].second + b[0];
  for (int i = 0, c = 0; c < cnt; ++i) {
    if (i == my) continue;
    int give = b[m - cnt + c];
    if (better(me, us, a[i].first, a[i].second + give)) return false;
    ++c;
  }
  return true;
}
void solve() {
  sort(a, a + n, cmp);
  for (int i = 0; i < n; ++i)
    if (a[i].first == me) my = i;
  while (m < n) b[m++] = 0;
  sort(b, b + m);
  int lt = 0, rt = n - 1;
  while (lt < rt) {
    int mid = (lt + rt + 1) / 2;
    if (can_less(mid))
      lt = mid;
    else
      rt = mid - 1;
  }
  int ans_max = n - lt;
  lt = 0, rt = n - 1;
  while (lt < rt) {
    int mid = (lt + rt + 1) / 2;
    if (can_more(mid))
      lt = mid;
    else
      rt = mid - 1;
  }
  int ans_min = lt + 1;
  cout << ans_max << ' ' << ans_min << endl;
}
int main() {
  while (read()) solve();
}

```