Problem:
ラブラブデート大作戦スギノキさん
問題
スギノキさんは彼氏が欲しいと日々ツイートし続けた結果、心優しいフォロワーが良さげな彼氏候補を紹介してくれたため、その人とデートすることになりました。
スギノキさんはその彼氏候補がとてもタイプだったので、確実に彼氏候補を射止めるために惚れ薬を使うことにしました。
スギノキさんは、秘伝のレシピをもとに作った $N$ 個の惚れ薬を所持しています。
$i$ ($1 \leq i \leq N$) 番目の惚れ薬には、使用する対象の自分に対する好感度の初期値を $x$ としたときに、好感度を $a_i x + b_i$ に変化させるという効果があります。
スギノキさんは、惚れ薬を使って彼氏候補のスギノキさんに対する好感度を最大化したいです。
惚れ薬を使うチャンスは、ランチとディナーの $2$ 回あります。
スギノキさんは、確実にデートを成功させるためシミュレーションを行うことにしました。
このとき、以下のクエリが $Q$ 個与えられるので、それらに答えてください。
$j$ ($1 \leq j \leq Q$) 番目のクエリでは、彼氏候補の好感度の初期値 $x_j$ が与えられます。
$N$ 個の惚れ薬から $2$ 個の惚れ薬を選んで使用した場合における、彼氏候補の好感度の最大値を出力してください。
つまり、ランチに $p$ 番目の惚れ薬、ディナーに $q$ 番目の惚れ薬を使用したとします ($p \neq q$) 。このとき、$a_q (a_p  x_j + b_p) + b_q$ の最大値を出力してください。
ただし、これはシミュレーションであり、実際に惚れ薬を使用することはありません。
なお、C++等の高速な言語を使用することを推奨します。
（writerおよびtesterがPythonで想定解を実装したところ、TLEとなることが確認されています。）
制約
$2 \leq N \leq 10^5$
$|a_i| \leq 10^6$
$|b_i| \leq 10^{12}$
$1 \leq Q \leq 10^5$
$|x_j| \leq 10^6$
$j \neq k$ ならば $x_j \neq x_k$
入力は全て整数
入力
$N$  
$a_1$ $b_1$  
$\vdots$  
$a_N$ $b_N$  
$Q$  
$x_1$
$\vdots$
$x_Q$
出力
各クエリに対して、答えを改行区切りで出力してください。
入力例 1
4
-2 3
4 7
5 8
1 20
3
0
10
-10
出力例 1
108
243
123
$1$ 番目のクエリに関しては、ランチに $4$ 番目の惚れ薬を、ディナーに $3$ 番目の惚れ薬を使用したとき、彼氏候補の好感度が最大となります。
このとき、彼氏候補の好感度の最大値は $5 \times (1 \times 0 + 20) + 8 = 108$ となります。
$2$ 番目のクエリに関しては、ランチに $2$ 番目の惚れ薬を、ディナーに $3$ 番目の惚れ薬を使用したとき、彼氏候補の好感度が最大となります。
異なるクエリで同じ惚れ薬を使うことが可能であることに注意してください。

Submitted solutions:

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

struct Point {
	double x, y;
};
struct Line {
	long long int a, b;
	bool is_parallel(const Line other) const {
		return a == other.a;
	}
	double cross_x(const Line other) const {
		long long int n = other.b - b;
		double d = a - other.a;
		return n / d;
	}
	long long int y_at(const long long int x) const {
		return a * x + b;
	}
};

vector<int> calc_max_line_forward(const vector<Line> &lines, const vector<long long int> &position, const vector<int> &void_line) {
	assert(position.size() == void_line.size());
	vector<int> line_indices(lines.size()); 
	iota(line_indices.begin(), line_indices.end(), 0);
	sort(line_indices.begin(), line_indices.end(), [&lines](const int i, const int j) {return lines[i].a == lines[j].a ? lines[i].b < lines[j].b : lines[i].a < lines[j].a; });
	vector<int> stack;
	vector<vector<int>> void_by_line(lines.size());
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] >= 0) void_by_line[void_line[i]].push_back(i);
	}
	vector<int> result(position.size(), -1);
	for (const auto li : line_indices) {
		for (const auto v : void_by_line[li]) {
			const auto pos = position[v];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (lines[stack[mid]].cross_x(lines[stack[mid + 1]]) <= pos) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			if (right >= 0) result[v] = stack[right];
		}
		if (!stack.empty()) {
			if (lines[stack.back()].is_parallel(lines[li])) stack.pop_back();
		}
		if (stack.size() >= 2) {
			auto prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
			auto last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
			while (stack.size() >= 2 && last <= prev) {
				stack.pop_back();
				if (stack.size() >= 2) {
					prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
					last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
				}
			}
		}
		stack.push_back(li);
	}
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] < 0) {
			const auto pos = position[i];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (lines[stack[mid]].cross_x(lines[stack[mid + 1]]) <= pos) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			result[i] = stack[right];
		}
	}
	return result;
}
vector<int> calc_max_line_backward(const vector<Line> &lines, const vector<long long int> &position, const vector<int> &void_line) {
	vector<int> line_indices(lines.size());
	iota(line_indices.begin(), line_indices.end(), 0);
	sort(line_indices.begin(), line_indices.end(), [&lines](const int i, const int j) {return lines[i].a == lines[j].a ? lines[i].b < lines[j].b : lines[i].a > lines[j].a; });
	vector<int> stack;
	vector<vector<int>> void_by_line(lines.size());
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] >= 0) void_by_line[void_line[i]].push_back(i);
	}
	vector<int> result(position.size(), -1);
	for (const auto li : line_indices) {
		for (const auto v : void_by_line[li]) {
			const auto pos = position[v];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (pos <= lines[stack[mid]].cross_x(lines[stack[mid + 1]])) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			if (right >= 0)result[v] = stack[right];
		}
		if (!stack.empty()) {
			if (lines[stack.back()].is_parallel(lines[li])) stack.pop_back();
		}
		if (stack.size() >= 2) {
			auto prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
			auto last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
			while (stack.size() >= 2 && prev <= last) {
				stack.pop_back();
				if (stack.size() >= 2) {
					prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
					last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
				}
			}
		}
		stack.push_back(li);
	}
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] < 0) {
			const auto pos = position[i];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (pos <= lines[stack[mid]].cross_x(lines[stack[mid + 1]])) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			result[i] = stack[right];
		}
	}
	return result;
}
vector<int> calc_min_line_forward(const vector<Line> &lines, const vector<long long int> &position, const vector<int> &void_line) {
	assert(position.size() == void_line.size());
	vector<int> line_indices(lines.size());
	iota(line_indices.begin(), line_indices.end(), 0);
	sort(line_indices.begin(), line_indices.end(), [&lines](const int i, const int j) {return lines[i].a == lines[j].a ? lines[i].b > lines[j].b : lines[i].a > lines[j].a; });
	vector<int> stack;
	vector<vector<int>> void_by_line(lines.size());
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] >= 0) void_by_line[void_line[i]].push_back(i);
	}
	vector<int> result(position.size(), -1);
	for (const auto li : line_indices) {
		for (const auto v : void_by_line[li]) {
			const auto pos = position[v];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (lines[stack[mid]].cross_x(lines[stack[mid + 1]]) <= pos) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			if (right >= 0)result[v] = stack[right];
		}
		if (!stack.empty()) {
			if (lines[stack.back()].is_parallel(lines[li])) stack.pop_back();
		}
		if (stack.size() >= 2) {
			auto prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
			auto last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
			while (stack.size() >= 2 && last <= prev) {
				stack.pop_back();
				if (stack.size() >= 2) {
					prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
					last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
				}
			}
		}
		stack.push_back(li);
	}
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] < 0) {
			const auto pos = position[i];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (lines[stack[mid]].cross_x(lines[stack[mid + 1]]) <= pos) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			result[i] = stack[right];
		}
	}
	return result;
}
vector<int> calc_min_line_backward(const vector<Line> &lines, const vector<long long int> &position, const vector<int> &void_line) {
	vector<int> line_indices(lines.size());
	iota(line_indices.begin(), line_indices.end(), 0);
	sort(line_indices.begin(), line_indices.end(), [&lines](const int i, const int j) {return lines[i].a == lines[j].a ? lines[i].b > lines[j].b : lines[i].a < lines[j].a; });
	vector<int> stack;
	vector<vector<int>> void_by_line(lines.size());
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] >= 0) void_by_line[void_line[i]].push_back(i);
	}
	vector<int> result(position.size(), -1);
	for (const auto li : line_indices) {
		for (const auto v : void_by_line[li]) {
			const auto pos = position[v];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (pos <= lines[stack[mid]].cross_x(lines[stack[mid + 1]])) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			if (right >= 0) result[v] = stack[right];
		}
		if (!stack.empty()) {
			if (lines[stack.back()].is_parallel(lines[li])) stack.pop_back();
		}
		if (stack.size() >= 2) {
			auto prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
			auto last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
			while (stack.size() >= 2 && prev <= last) {
				stack.pop_back();
				if (stack.size() >= 2) {
					prev = lines[stack[stack.size() - 2]].cross_x(lines[stack.back()]);
					last = lines[stack[stack.size() - 2]].cross_x(lines[li]);
				}
			}
		}
		stack.push_back(li);
	}
	for (auto i = 0; i < void_line.size(); ++i) {
		if (void_line[i] < 0) {
			const auto pos = position[i];
			int left = 0;
			int right = (int)stack.size() - 1;
			while (left < right) {
				const auto mid = (left + right) >> 1;
				if (pos <= lines[stack[mid]].cross_x(lines[stack[mid + 1]])) {
					left = mid + 1;
				}
				else {
					right = mid;
				}
			}
			result[i] = stack[right];
		}
	}
	return result;
}

vector<int> calc_max(const vector<Line>& lines, const vector<long long int>& position) {
	return calc_max_line_forward(lines, position, vector<int>(position.size(), -1));
}
vector<int> calc_min(const vector<Line>& lines, const vector<long long int>& position) {
	return calc_min_line_forward(lines, position, vector<int>(position.size(), -1));
}
vector<int> calc_max_with_void(const vector<Line>& lines, const vector<long long int>& position, const vector<int>& void_line) {
	auto forward = calc_max_line_forward(lines, position, void_line);
	const auto backward = calc_max_line_backward(lines, position, void_line);
	for (auto i = 0; i < backward.size(); ++i) {
		if (backward[i] >= 0 && (forward[i] < 0 || lines[forward[i]].y_at(position[i]) < lines[backward[i]].y_at(position[i]))) {
			forward[i] = backward[i];
		}
	}
	return forward;
}
vector<int> calc_min_with_void(const vector<Line>& lines, const vector<long long int>& position, const vector<int>& void_line) {
	auto forward = calc_min_line_forward(lines, position, void_line);
	const auto backward = calc_min_line_backward(lines, position, void_line);
	for (auto i = 0; i < backward.size(); ++i) {
		if (backward[i] >= 0 && (forward[i] < 0 || lines[forward[i]].y_at(position[i]) > lines[backward[i]].y_at(position[i]))) {
			forward[i] = backward[i];
		}
	}
	return forward;
}

vector<long long int> solve(const vector<Line> lines, const vector<long long int> initial) {
	const auto first_max = calc_max(lines, initial);
	const auto first_min = calc_min(lines, initial);
	vector<long long int> first_max_pos(initial.size()), first_min_pos(initial.size());
	for (auto i = 0; i < initial.size(); ++i) {
		first_max_pos[i] = lines[first_max[i]].y_at(initial[i]);
		first_min_pos[i] = lines[first_min[i]].y_at(initial[i]);
	}
	const auto first_sus1 = calc_max_with_void(lines, first_max_pos, first_max);
	const auto first_sus2 = calc_max_with_void(lines, first_min_pos, first_min);
	const auto second_max_max = calc_max_with_void(lines, initial, first_max);
	const auto second_min_max = calc_min_with_void(lines, initial, first_max);
	const auto second_max_min = calc_max_with_void(lines, initial, first_min);
	const auto second_min_min = calc_min_with_void(lines, initial, first_min);
	vector<long long int> result(initial.size());
	for (auto i = 0; i < result.size(); ++i) {
		const auto sus1 = lines[first_max[i]].y_at(lines[second_max_max[i]].y_at(initial[i]));
		const auto sus2 = lines[first_max[i]].y_at(lines[second_min_max[i]].y_at(initial[i]));
		const auto sus3 = lines[first_min[i]].y_at(lines[second_max_min[i]].y_at(initial[i]));
		const auto sus4 = lines[first_min[i]].y_at(lines[second_min_min[i]].y_at(initial[i]));
		const auto sus5 = lines[first_sus1[i]].y_at(first_max_pos[i]);
		const auto sus6 = lines[first_sus2[i]].y_at(first_min_pos[i]);
		result[i] = max({ sus1, sus2, sus3, sus4, sus5, sus6 });
	}
	return result;
}

int main() {
	int n; cin >> n;
	vector<Line> lines(n);
	for (auto& [a, b] : lines) {
		cin >> a >> b;
	}
	int q; cin >> q;
	vector<long long int> initial(q);
	for (auto& p : initial) {
		cin >> p;
	}
	const auto result = solve(lines, initial);
	for (const auto r : result) {
		cout << r << '\n';
	}
}
accuracy: 1
time_ms: 230
memory_kb: 17068
final_rank: 2

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
struct modint {
    ll n;
    modint() :n(0) { ; }
    modint(ll m) :n(m) {
        if (n >= mod)n %= mod;
        else if (n < 0)n = (n % mod + mod) % mod;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}

mt19937 mt(time(0));
uniform_int_distribution<> ud(0, 1000000000);

struct CHT {
    vector<LP> v;
    vector<LP> memo;
    int l;
    bool check(LP a, LP b, LP c) {
        return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);
    }
    //一気に作る
    void build(vector<LP> a) {
        l = 0;
        sort(a.begin(),a.end());
        per(i, (int)a.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], a[i]))v.pop_back();
            v.push_back(a[i]);
        }
    }
    //傾きが小さい順に追加して作る
    void build() {
        per(i, (int)memo.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], memo[i]))v.pop_back();
            v.push_back(memo[i]);
        }
        memo.clear();
    }
    void add(LP a) {
        memo.push_back(a);
    }
    //xは単調増加
    ll f(LP a, ll x) {
        return a.first * x + a.second;
    }
    ll query(ll x) {
        while (l + 1 < v.size() && f(v[l], x) > f(v[l + 1], x))l++;
        return f(v[l], x);
    }
};

void solve() {
    int n; cin >> n;
    int d = n / 2;
    vector<ll> a(n), b(n);
    rep(i, n)cin >> a[i] >> b[i];
    int q; cin >> q;
    vector<P> v(q);
    rep(i, q) {
        int x; cin >> x;
        v[i] = { x,i };
    }
    sort(all(v));
    vector<ll> ans(q, -8*INF);
    rep(aa, 40) {
        vector<P> vs;
        rep(i, n) {
            vs.push_back({ ud(mt),i });
        }
        sort(all(vs));
        vector<ll> ca(n), cb(n);
        rep(i, n) {
            ca[vs[i].second] = a[i];
            cb[vs[i].second] = b[i];
        }
        swap(ca, a); swap(cb, b);
        CHT le,le2, ri;
        vector<LP>vl,vl2, vr;
        rep(i, n) {
            if (i < d) {
                vl.push_back({ -a[i],-b[i] });
                vl2.push_back({ a[i],b[i] });
            }
            else {
                vr.push_back({ -a[i],-b[i] });
            }
        }
        le.build(vl);
        le2.build(vl2);
        ri.build(vr);

        vector<LP> qv;
        rep(i, q) {
            int id = v[i].second;
            ll x = v[i].first;
            x = -le.query(x);
            qv.push_back({ x,id });
        }
        rep(i, q) {
            int id = v[i].second;
            ll x = v[i].first;
            x = le2.query(x);
            qv.push_back({ x,id });
        }
        sort(all(qv));
        for (LP p : qv) {
            int id = p.second;
            ll x = p.first;
            x = -ri.query(x);
            ans[id] = max(ans[id], x);
        }
    }
    rep(i, q)cout << ans[i] << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(15);
    //init_f();
    //init();
    //expr();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}
accuracy: 1
time_ms: 1490
memory_kb: 36556
final_rank: 6

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
struct modint {
    ll n;
    modint() :n(0) { ; }
    modint(ll m) :n(m) {
        if (n >= mod)n %= mod;
        else if (n < 0)n = (n % mod + mod) % mod;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}

mt19937 mt(time(0));
uniform_int_distribution<> ud(0, 1000000000);

struct CHT {
    vector<LP> v;
    vector<LP> memo;
    int l;
    bool check(LP a, LP b, LP c) {
        return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);
    }
    //一気に作る
    void build(vector<LP> a) {
        l = 0;
        sort(a.begin(),a.end());
        per(i, (int)a.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], a[i]))v.pop_back();
            v.push_back(a[i]);
        }
    }
    //傾きが小さい順に追加して作る
    void build() {
        per(i, (int)memo.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], memo[i]))v.pop_back();
            v.push_back(memo[i]);
        }
        memo.clear();
    }
    void add(LP a) {
        memo.push_back(a);
    }
    //xは単調増加
    ll f(LP a, ll x) {
        return a.first * x + a.second;
    }
    ll query(ll x) {
        while (l + 1 < v.size() && f(v[l], x) > f(v[l + 1], x))l++;
        return f(v[l], x);
    }
};

void solve() {
    int n; cin >> n;
    int d = n / 2;
    vector<ll> a(n), b(n);
    rep(i, n)cin >> a[i] >> b[i];
    int q; cin >> q;
    vector<P> v(q);
    rep(i, q) {
        int x; cin >> x;
        v[i] = { x,i };
    }
    sort(all(v));
    vector<ll> ans(q, -8*INF);
    rep(aa, 100) {
        vector<P> vs;
        rep(i, n) {
            vs.push_back({ ud(mt),i });
        }
        sort(all(vs));
        vector<ll> ca(n), cb(n);
        rep(i, n) {
            ca[vs[i].second] = a[i];
            cb[vs[i].second] = b[i];
        }
        swap(ca, a); swap(cb, b);
        CHT le, ri;
        vector<LP>vl, vr;
        rep(i, n) {
            if (i < d) {
                vl.push_back({ -a[i],-b[i] });
            }
            else {
                vr.push_back({ -a[i],-b[i] });
            }
        }
        le.build(vl);
        ri.build(vr);

        vector<LP> qv;
        rep(i, q) {
            int id = v[i].second;
            ll x = v[i].first;
            x = -le.query(x);
            qv.push_back({ x,id });
        }
        sort(all(qv));
        for (LP p : qv) {
            int id = p.second;
            ll x = p.first;
            x = -ri.query(x);
            ans[id] = max(ans[id], x);
        }
    }
    rep(i, q)cout << ans[i] << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(15);
    //init_f();
    //init();
    //expr();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}
accuracy: 0.019417475728155338
time_ms: 1960
memory_kb: 28112
final_rank: 20

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
struct modint {
    ll n;
    modint() :n(0) { ; }
    modint(ll m) :n(m) {
        if (n >= mod)n %= mod;
        else if (n < 0)n = (n % mod + mod) % mod;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}

mt19937 mt(time(0));
uniform_int_distribution<> ud(0, 1000000000);

struct CHT {
    vector<LP> v;
    vector<LP> memo;
    int l;
    bool check(LP a, LP b, LP c) {
        return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);
    }
    //一気に作る
    void build(vector<LP> a) {
        l = 0;
        sort(a.begin(),a.end());
        per(i, (int)a.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], a[i]))v.pop_back();
            v.push_back(a[i]);
        }
    }
    //傾きが小さい順に追加して作る
    void build() {
        per(i, (int)memo.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], memo[i]))v.pop_back();
            v.push_back(memo[i]);
        }
        memo.clear();
    }
    void add(LP a) {
        memo.push_back(a);
    }
    //xは単調増加
    ll f(LP a, ll x) {
        return a.first * x + a.second;
    }
    ll query(ll x) {
        while (l + 1 < v.size() && f(v[l], x) > f(v[l + 1], x))l++;
        return f(v[l], x);
    }
};

void solve() {
    int n; cin >> n;
    int d = n / 2;
    vector<ll> a(n), b(n);
    rep(i, n)cin >> a[i] >> b[i];
    int q; cin >> q;
    vector<P> v(q);
    rep(i, q) {
        int x; cin >> x;
        v[i] = { x,i };
    }
    sort(all(v));
    vector<ll> ans(q, -8*INF);
    rep(aa, 100) {
        vector<P> vs;
        rep(i, n) {
            vs.push_back({ ud(mt),i });
        }
        sort(all(vs));
        vector<ll> ca(n), cb(n);
        rep(i, n) {
            ca[vs[i].second] = a[i];
            cb[vs[i].second] = b[i];
        }
        swap(ca, a); swap(cb, b);
        CHT le, ri;
        vector<LP>vl, vr;
        rep(i, n) {
            if (i < d) {
                vl.push_back({ -a[i],-b[i] });
            }
            else {
                vr.push_back({ -a[i],-b[i] });
            }
        }
        le.build(vl);
        ri.build(vr);
        rep(i, q) {
            int id = v[i].second;
            ll x = v[i].first;
            x = -le.query(x);
            x = -ri.query(x);
            ans[id] = max(ans[id], x);
        }
    }
    rep(i, q)cout << ans[i] << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(15);
    //init_f();
    //init();
    //expr();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}
accuracy: 0.019417475728155338
time_ms: 1820
memory_kb: 28192
final_rank: 19

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
struct modint {
    ll n;
    modint() :n(0) { ; }
    modint(ll m) :n(m) {
        if (n >= mod)n %= mod;
        else if (n < 0)n = (n % mod + mod) % mod;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}

mt19937 mt(time(0));
uniform_int_distribution<> ud(0, 1000000000);

struct CHT {
    vector<LP> v;
    vector<LP> memo;
    int l;
    bool check(LP a, LP b, LP c) {
        return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);
    }
    //一気に作る
    void build(vector<LP> a) {
        l = 0;
        sort(a.begin(),a.end());
        per(i, (int)a.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], a[i]))v.pop_back();
            v.push_back(a[i]);
        }
    }
    //傾きが小さい順に追加して作る
    void build() {
        per(i, (int)memo.size()) {
            while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], memo[i]))v.pop_back();
            v.push_back(memo[i]);
        }
        memo.clear();
    }
    void add(LP a) {
        memo.push_back(a);
    }
    //xは単調増加
    ll f(LP a, ll x) {
        return a.first * x + a.second;
    }
    ll query(ll x) {
        while (l + 1 < v.size() && f(v[l], x) > f(v[l + 1], x))l++;
        return f(v[l], x);
    }
};

void solve() {
    int n; cin >> n;
    int d = n / 2;
    vector<ll> a(n), b(n);
    rep(i, n)cin >> a[i] >> b[i];
    int q; cin >> q;
    vector<P> v(q);
    rep(i, q) {
        int x; cin >> x;
        v[i] = { x,i };
    }
    sort(all(v));
    vector<ll> ans(q, -4*INF);
    rep(aa, 100) {
        vector<P> vs;
        rep(i, n) {
            vs.push_back({ ud(mt),i });
        }
        sort(all(vs));
        vector<ll> ca(n), cb(n);
        rep(i, n) {
            ca[vs[i].second] = a[i];
            cb[vs[i].second] = b[i];
        }
        swap(ca, a); swap(cb, b);
        CHT le, ri;
        vector<LP>vl, vr;
        rep(i, n) {
            if (i < d) {
                vl.push_back({ -a[i],-b[i] });
            }
            else {
                vr.push_back({ -a[i],-b[i] });
            }
        }
        le.build(vl);
        ri.build(vr);
        rep(i, q) {
            int id = v[i].second;
            ll x = v[i].first;
            x = -le.query(x);
            x = -ri.query(x);
            ans[id] = max(ans[id], x);
        }
    }
    rep(i, q)cout << ans[i] << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(15);
    //init_f();
    //init();
    //expr();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}
accuracy: 0.019417475728155338
time_ms: 1820
memory_kb: 28092
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#else
#define dbg(x) {}
#endif

// Convex Hull Trick for monotone increasing queries, monotone decreasing slopes
// Each operation is amortized O(1)
// - add_line(a, b): Add `y = ax + b`, a must be monotone decreasing (if is_minimizer == true) / increasing (otherwise)
// - add_convex_parabola(c, a, b): Add `y = c(x - a)^2 + b`, c is constant, a is monotone increasing (if is_minimizer == true) / decreasing (otherwise)
// - get(x): Calculate min/max. value of `y = ax + b`'s at point x, x must be monotone increasing FOR BOTH CASES.
// - parabola_get(c, x): Caclculate min/max. value of `y = c(x - a)^2 + b`'s, x must be monotone increasing FOR BOTH CASES.
// Verified: <https://yukicoder.me/submissions/409156>
// template<typename T_CHT>
using T_CHT = long long int;
struct MonotoneConvexHullTrick : std::deque<std::pair<T_CHT, T_CHT>> // (a, b) means `y = ax + b`
{
    using T_MP = __int128_t;
    bool is_minimizer; // If true, this instance calculates min. Otherwise, calculates max.
    MonotoneConvexHullTrick(bool is_minimizer) : is_minimizer(is_minimizer) {}
    void add_line(T_CHT a, T_CHT b) { // Add y = ax + b
        if (!is_minimizer) a = -a, b = -b;
        assert(this->empty() or this->back().first >= a);
        while (this->size() > 1u) {
            if (this->back().first == a) {
                if (this->back().second <= b) {
                    return;
                } else {
                    this->pop_back();
                    continue;
                }
            }
            int sz = this->size();
            T_MP l = (T_MP)(this->back().second - (*this)[sz - 2].second) * (this->back().first - a); // Overflow might occur here.
            T_MP r = (T_MP)(b - this->back().second) * ((*this)[sz - 2].first - this->back().first);
            if (l < r) break;
            this->pop_back();
        }
        this->emplace_back(a, b);
    }
    T_CHT get(T_CHT x) {
        while (this->size() > 1u and (*this)[0].first * x + (*this)[0].second >= (*this)[1].first * x + (*this)[1].second) { this->pop_front(); }
        return ((*this)[0].first * x + (*this)[0].second) * (is_minimizer ? 1 : -1);
    }
    void add_convex_parabola(T_CHT c, T_CHT a, T_CHT b) { add_line(c * a * (-2), c * a * a + b); } // Add y = c(x - a)^2 + b
    T_CHT parabola_get(T_CHT c, T_CHT x) { return get(x) + c * x * x; }
};

uint32_t rand_int() // XorShift random integer generator
{
    static uint32_t x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    uint32_t t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

int main()
{
    int N;
    cin >> N;
    vector<plint> ab(N);
    for (auto &p : ab) cin >> p.first >> p.second;
    sort(ab.begin(), ab.end());
    vector<int> status(N);

    int Q;
    cin >> Q;
    vector<lint> XQ(Q);
    cin >> XQ;
    const vector<lint> xs = sort_unique(XQ);
    vector<lint> ret(xs.size(), -4e18);

    vector<lint> lo1(xs.size()), hi1(xs.size());
    REP(_, 100) {
        MonotoneConvexHullTrick max1(false), max2(false), min1(true);
        for (auto &x : status) x = rand_int() & 1;
        REP(i, N) (status[i] ? max1 : max2).add_line(ab[i].first, ab[i].second);
        IREP(i, N) if (status[i]) min1.add_line(ab[i].first, ab[i].second);
        {
            int tot = accumulate(status.begin(), status.end(), 0);
            if (tot == 0 or tot == N) continue;
        }

        vector<pair<lint, int>> v2i;
        REP(i, xs.size()) {
            v2i.emplace_back(max1.get(xs[i]), i);
            v2i.emplace_back(min1.get(xs[i]), i);
        }
        sort(v2i.begin(), v2i.end());
        for (auto [v, i] : v2i) chmax(ret[i], max2.get(v));
    }
    for (auto x : XQ) cout << ret[lower_bound(xs.begin(), xs.end(), x) - xs.begin()] << '\n';
}
accuracy: 1
time_ms: 1270
memory_kb: 17216
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#else
#define dbg(x) {}
#endif

// Convex Hull Trick for monotone increasing queries, monotone decreasing slopes
// Each operation is amortized O(1)
// - add_line(a, b): Add `y = ax + b`, a must be monotone decreasing (if is_minimizer == true) / increasing (otherwise)
// - add_convex_parabola(c, a, b): Add `y = c(x - a)^2 + b`, c is constant, a is monotone increasing (if is_minimizer == true) / decreasing (otherwise)
// - get(x): Calculate min/max. value of `y = ax + b`'s at point x, x must be monotone increasing FOR BOTH CASES.
// - parabola_get(c, x): Caclculate min/max. value of `y = c(x - a)^2 + b`'s, x must be monotone increasing FOR BOTH CASES.
// Verified: <https://yukicoder.me/submissions/409156>
// template<typename T_CHT>
using T_CHT = long long;
struct MonotoneConvexHullTrick : std::deque<std::pair<T_CHT, T_CHT>> // (a, b) means `y = ax + b`
{
    using T_MP = __int128_t;
    bool is_minimizer; // If true, this instance calculates min. Otherwise, calculates max.
    MonotoneConvexHullTrick(bool is_minimizer) : is_minimizer(is_minimizer) {}
    void add_line(T_CHT a, T_CHT b) { // Add y = ax + b
        if (!is_minimizer) a = -a, b = -b;
        assert(this->empty() or this->back().first >= a);
        while (this->size() > 1u) {
            int sz = this->size();
            T_MP l = (T_MP)(this->back().second - (*this)[sz - 2].second) * (this->back().first - a); // Overflow might occur here.
            T_MP r = (T_MP)(b - this->back().second) * ((*this)[sz - 2].first - this->back().first);
            if (l < r) break;
            this->pop_back();
        }
        this->emplace_back(a, b);
    }
    T_CHT get(T_CHT x) {
        while (this->size() > 1u and (*this)[0].first * x + (*this)[0].second >= (*this)[1].first * x + (*this)[1].second) { this->pop_front(); }
        return ((*this)[0].first * x + (*this)[0].second) * (is_minimizer ? 1 : -1);
    }
    plint aget(T_CHT x) {
        while (this->size() > 1u and (*this)[0].first * x + (*this)[0].second >= (*this)[1].first * x + (*this)[1].second) { this->pop_front(); }
        return make_pair((*this)[0].first * (is_minimizer ? 1 : -1), (*this)[0].second * (is_minimizer ? 1 : -1));
    }
};

uint32_t rand_int() // XorShift random integer generator
{
    static uint32_t x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    uint32_t t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

int main()
{
    int N;
    cin >> N;
    vector<plint> ab(N);
    for (auto &p : ab) cin >> p.first >> p.second;
    sort(ab.begin(), ab.end());
    vector<int> status(N);

    int Q;
    cin >> Q;
    vector<lint> XQ(Q);
    cin >> XQ;
    const vector<lint> xs = sort_unique(XQ);
    vector<lint> ret(xs.size(), -4e18);

    vector<lint> lo1(xs.size()), hi1(xs.size());
    REP(_, 100) {
        MonotoneConvexHullTrick max1(false), max2(false), min1(true);
        for (auto &x : status) x = rand_int() & 1;
        REP(i, N) (status[i] ? max1 : max2).add_line(ab[i].first, ab[i].second);
        IREP(i, N) if (status[i]) min1.add_line(ab[i].first, ab[i].second);
        {
            int tot = accumulate(status.begin(), status.end(), 0);
            if (tot == 0 or tot == N) continue;
        }

        vector<pair<lint, int>> v2i;
        REP(i, xs.size()) {
            v2i.emplace_back(max1.get(xs[i]), i);
            v2i.emplace_back(min1.get(xs[i]), i);
        }
        sort(v2i.begin(), v2i.end());
        for (auto [v, i] : v2i) chmax(ret[i], max2.get(v));
    }
    for (auto x : XQ) cout << ret[lower_bound(xs.begin(), xs.end(), x) - xs.begin()] << '\n';
}
accuracy: 1
time_ms: 1260
memory_kb: 16768
final_rank: 3

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);

        if (!lines.empty() && lines.back().a == line.a) {
            if (lines.back().b > line.b) {
                lines.pop_back();
            } else {
                return;
            }
        }

        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 62;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) cin >> a >> b;
    sort(ls.begin(), ls.end());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 30; t--;) {
        vector<ConvexHullTrick<lint, false>> minchts(2), maxchts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            minchts[i].add(a, b);
            maxchts[i].add(-a, -b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -maxchts[0](minchts[1](xs[i])),
                          -maxchts[0](-maxchts[1](xs[i])),
                          -maxchts[1](minchts[0](xs[i])),
                          -maxchts[1](-maxchts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 490
memory_kb: 6280
final_rank: 1

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 62;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) cin >> a >> b;

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 30; t--;) {
        vector<map<lint, lint>> pss(2);
        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            if (!pss[i].count(a)) pss[i][a] = b;
            pss[i][a] = max(pss[i][a], b);
        }

        if (pss[0].empty() || pss[1].empty()) continue;

        vector<ConvexHullTrick<lint, false>> chts(2);
        for (int i = 0; i < 2; ++i) {
            for (auto [a, b] : pss[i]) {
                chts[i].add(-a, -b);
            }
        }

        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -chts[0](-chts[1](xs[i])),
                          -chts[1](-chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 1280
memory_kb: 11524
final_rank: 14

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 62;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) {
        cin >> a >> b;
        a = -a;
    }
    sort(ls.begin(), ls.end());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 100; t--;) {
        vector<ConvexHullTrick<lint, false>> chts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            chts[i].add(a, -b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -chts[0](-chts[1](xs[i])),
                          -chts[1](-chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 440
memory_kb: 5572
final_rank: 12

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 62;

Random rng;

void solve() {
    int n;
    cin >> n;

    map<lint, lint> ps;
    while (n--) {
        lint a, b;
        cin >> a >> b;
        a = -a, b = -b;

        if (!ps.count(a)) ps[a] = b;
        ps[a] = min(ps[a], b);
    }
    vector<pair<lint, lint>> ls(ps.begin(), ps.end());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 100; t--;) {
        vector<ConvexHullTrick<lint, false>> chts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            chts[i].add(a, b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -chts[0](-chts[1](xs[i])),
                          -chts[1](-chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 470
memory_kb: 11156
final_rank: 13

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 62;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) cin >> a >> b;
    sort(ls.rbegin(), ls.rend());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 50; t;) {
        vector<ConvexHullTrick<lint, false>> chts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            chts[i].add(-a, -b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        --t;
        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -chts[0](-chts[1](xs[i])),
                          -chts[1](-chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 230
memory_kb: 5612
final_rank: 7

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 62;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) cin >> a >> b;
    sort(ls.begin(), ls.end());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 50; t;) {
        vector<ConvexHullTrick<lint, false>> chts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            chts[i].add(-a, -b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        --t;
        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -chts[0](-chts[1](xs[i])),
                          -chts[1](-chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 260
memory_kb: 5664
final_rank: 10

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 60;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) cin >> a >> b;
    sort(ls.begin(), ls.end());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 50; t;) {
        vector<ConvexHullTrick<lint, false>> chts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            chts[i].add(-a, -b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        --t;
        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -chts[0](-chts[1](xs[i])),
                          -chts[1](-chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 250
memory_kb: 5496
final_rank: 8

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) < (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最小値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) > lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) > l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) > lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 60;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) cin >> a >> b;
    sort(ls.begin(), ls.end());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 50; t--;) {
        vector<ConvexHullTrick<lint, false>> chts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            chts[i].add(-a, -b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          -chts[0](-chts[1](xs[i])),
                          -chts[1](-chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 260
memory_kb: 5748
final_rank: 11

code_snippet: #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/random.hpp"

#include <chrono>

struct Random {
    using ulint = uint64_t;
    ulint x;

    explicit Random() {
        x = std::chrono::steady_clock::now()
                .time_since_epoch()
                .count();
    }

    ulint next() {
        x ^= (x << 13);
        x ^= (x >> 7);
        x ^= (x << 17);
        return x;
    }
};
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class T, bool isMonotonicX>
struct ConvexHullTrick {
    struct Line {
        T a, b;
        Line(const T& a, const T& b) : a(a), b(b){};
        T operator()(const T& x) const { return a * x + b; }
    };

    std::vector<Line> lines;

    ConvexHullTrick() = default;

    // l2が必要か否か
    bool isneeded(Line l1, Line l2, Line l3) const {
        if (l1.a < l3.a) std::swap(l1, l3);
        return (l3.b - l2.b) * (l2.a - l1.a) > (l3.a - l2.a) * (l2.b - l1.b);
    }

    // 直線y = ax + bを追加  aは単調であることを要求
    void add(const T& a, const T& b) {
        Line line(a, b);
        while (lines.size() >= 2 &&
               !isneeded(*(lines.end() - 2), lines.back(), line)) lines.pop_back();
        lines.push_back(line);
    }

    // xにおける最大値を返す
    T operator()(const T& x) const {
        if (isMonotonicX) {
            static int itr = 0;
            while (itr + 1 < (int)lines.size() &&
                   lines[itr](x) < lines[itr + 1](x)) ++itr;
            return lines[itr](x);
        } else {
            // l[ok - 1](x) < l[ok](x)
            int ok = 0, ng = lines.size();
            while (ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if (lines[mid - 1](x) < lines[mid](x)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            return lines[ok](x);
        }
    }
};

using namespace std;

using lint = long long;
constexpr lint INF = 1LL << 60;

Random rng;

void solve() {
    int n;
    cin >> n;

    vector<pair<lint, lint>> ls(n);
    for (auto& [a, b] : ls) cin >> a >> b;
    sort(ls.begin(), ls.end());

    int q;
    cin >> q;
    vector<lint> xs(q);
    for (auto& x : xs) cin >> x;

    vector<lint> ans(q, -INF);

    for (int t = 50; t--;) {
        vector<ConvexHullTrick<lint, false>> chts(2);
        vector<bool> empty(2, true);

        for (auto [a, b] : ls) {
            int i = rng.next() % 2;
            chts[i].add(a, b);
            empty[i] = false;
        }

        if (empty[0] || empty[1]) continue;

        for (int i = 0; i < q; ++i) {
            ans[i] = max({ans[i],
                          chts[0](chts[1](xs[i])),
                          chts[1](chts[0](xs[i]))});
        }
    }

    for (auto a : ans) cout << a << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.019417475728155338
time_ms: 260
memory_kb: 5496
final_rank: 9

code_snippet: #line 1 "other/oupc/h.cc"
/**
 * @file template.cpp
 * @brief Template
 */

// #undef _GLIBCXX_DEBUG
#include <bits/extc++.h>

#line 2 "Library/lib/alias"

/*
 * @file alias
 * @brief Alias
 */

#line 13 "Library/lib/alias"

namespace workspace {

constexpr char eol = '\n';

using namespace std;

using i32 = int_least32_t;
using u32 = uint_least32_t;
using i64 = int_least64_t;
using u64 = uint_least64_t;

#ifdef __SIZEOF_INT128__
using i128 = __int128_t;
using u128 = __uint128_t;
#else
#warning 128bit integer is not available.
#endif

template <class T, class Comp = less<T>>
using priority_queue = std::priority_queue<T, vector<T>, Comp>;

template <class T> using stack = std::stack<T, vector<T>>;

}  // namespace workspace
#line 10 "other/oupc/h.cc"
// #include "lib/cxx20"
// #include "lib/direct"
#line 2 "Library/src/opt/binary_search.hpp"

/*
 * @file binary_search.hpp
 * @brief Binary Search
 */

#line 12 "Library/src/opt/binary_search.hpp"

namespace workspace {

/*
 * @fn binary_search
 * @brief binary search on a discrete range.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param pred the predicate
 * @return the closest point to (ng) where pred is true
 */
template <class Iter, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Iter>())),
                        bool>::value,
    Iter>::type
binary_search(Iter ok, Iter ng, Pred pred) {
  assert(ok != ng);
  typename std::make_signed<decltype(ng - ok)>::type dist(ng - ok);
  while (1 < dist || dist < -1) {
    const Iter mid(ok + dist / 2);
    if (pred(mid))
      ok = mid, dist -= dist / 2;
    else
      ng = mid, dist /= 2;
  }
  return ok;
}

/*
 * @fn binary_search
 * @brief binary search on the real number line.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary point
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
binary_search(Real ok, Real ng, const Real eps, Pred pred) {
  assert(ok != ng);
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits &&
                       (ok + eps < ng || ng + eps < ok);
       ++loops) {
    const Real mid{(ok + ng) / 2};
    (pred(mid) ? ok : ng) = mid;
  }
  return ok;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on discrete ranges.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param pred the predicate
 * @return the closest points to (second) where pred is true
 */
template <class Array,
          class Iter = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Iter>>())[0]),
        bool>::value,
    std::vector<Iter>>::type
parallel_binary_search(Array ends, Pred pred) {
  std::vector<Iter> mids(std::size(ends));
  for (;;) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Iter &ok = std::get<0>(ends[i]);
      const Iter &ng = std::get<1>(ends[i]);
      const Iter mid(
          ok + typename std::make_signed<decltype(ng - ok)>::type(ng - ok) / 2);
      if (mids[i] != mid) {
        all_found = false;
        mids[i] = mid;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on the real number line.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary points
 */
template <class Array,
          class Real = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Real>>())[0]),
        bool>::value,
    std::vector<Real>>::type
parallel_binary_search(Array ends, const Real eps, Pred pred) {
  std::vector<Real> mids(std::size(ends));
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits; ++loops) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Real ok = std::get<0>(ends[i]);
      const Real ng = std::get<1>(ends[i]);
      if (ok + eps < ng || ng + eps < ok) {
        all_found = false;
        mids[i] = (ok + ng) / 2;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

}  // namespace workspace
#line 2 "Library/src/opt/exponential_search.hpp"

/*
 * @file exponential_search.hpp
 * @brief Exponential Search
 */

#line 9 "Library/src/opt/exponential_search.hpp"

namespace workspace {

/*
 * @fn exponential_search
 * @brief Exponential search on a discrete range.
 * @param range Range of search, exclusive
 * @param pred Predicate
 * @return Minimum non-negative integer where pred is false.
 */
template <class Index, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Index>())),
                        bool>::value,
    Index>::type
exponential_search(Index range, Pred pred) {
  Index step(1);
  while (step < range && pred(step)) step <<= 1;
  if (range < step) step = range;
  return binary_search(Index(0), step, pred);
}

/*
 * @fn exponential_search
 * @brief Exponential search on the real number line.
 * @param range Range of search
 * @param eps Error tolerance
 * @param pred Predicate
 * @return Boundary point.
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
exponential_search(Real range, Real const &eps, Pred pred) {
  Real step(1);
  while (step < range && pred(step)) step += step;
  if (range < step) step = range;
  return binary_search(Real(0), step, eps, pred);
}

}  // namespace workspace
#line 2 "Library/src/opt/trinary_search.hpp"

/*
 * @file trinary_search.hpp
 * @brief Trinary Search
 */

#line 9 "Library/src/opt/trinary_search.hpp"
#include <type_traits>

namespace workspace {

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Iter, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Iter>(),
                                                      std::declval<Iter>())),
                        bool>::value,
    Iter>::type
trinary_search(Iter first, Iter last, Comp comp) {
  assert(first < last);
  typename std::make_signed<decltype(last - first)>::type dist(last - first);
  while (2 < dist) {
    Iter left(first + dist / 3), right(first + dist * 2 / 3);
    if (comp(left, right))
      last = right, dist = (dist + dist) / 3;
    else
      first = left, dist -= dist / 3;
  }
  if (1 < dist && comp(first + 1, first)) ++first;
  return first;
}

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param func Function
 * @return Local minimal point.
 */
template <class Iter, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Iter>()), nullptr),
                 std::nullptr_t>::value,
    Iter>::type
trinary_search(Iter const &first, Iter const &last, Func func) {
  return trinary_search(first, last, [&](Iter const &__i, Iter const &__j) {
    return func(__i) < func(__j);
  });
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Real, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Real>(),
                                                      std::declval<Real>())),
                        bool>::value,
    Real>::type
trinary_search(Real first, Real last, Real const &eps, Comp comp) {
  assert(first < last);
  while (eps < last - first) {
    Real left{(first * 2 + last) / 3}, right{(first + last * 2) / 3};
    if (comp(left, right))
      last = right;
    else
      first = left;
  }
  return first;
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param func Function
 * @return Local minimal point.
 */
template <class Real, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Real>()), nullptr),
                 std::nullptr_t>::value,
    Real>::type
trinary_search(Real const &first, Real const &last, Real const &eps,
               Func func) {
  return trinary_search(
      first, last, eps,
      [&](Real const &__i, Real const &__j) { return func(__i) < func(__j); });
}

}  // namespace workspace
#line 2 "Library/src/sys/ejection.hpp"

/*
 * @file ejection.hpp
 * @brief Ejection
 */

#line 9 "Library/src/sys/ejection.hpp"

namespace workspace {

struct ejection {
  bool exit = 0;
};

/*
 * @brief eject from a try block, throw nullptr
 * @param arg output
 */
template <class Tp> void eject(Tp const &arg) {
  std::cout << arg << "\n";
  throw ejection{};
}

void exit() { throw ejection{true}; }

}  // namespace workspace
#line 2 "Library/src/sys/iteration.hpp"

/*
 * @file iteration.hpp
 * @brief Case Iteration
 */

#line 9 "Library/src/sys/iteration.hpp"

#line 11 "Library/src/sys/iteration.hpp"

namespace workspace {

void main();

struct {
  unsigned current{0}, total{1};

  void read() { (std::cin >> total).ignore(); }

  int iterate() {
    static bool once = false;
    assert(!once);
    once = true;
    while (current++ < total) {
      try {
        main();
      } catch (ejection const& status) {
        if (status.exit) break;
      }
    }
    return 0;
  }
} case_info;

}  // namespace workspace
#line 14 "other/oupc/h.cc"
// #include "lib/utils"
#line 2 "Library/src/utils/chval.hpp"

/*
 * @file chval.hpp
 * @brief Change Less/Greater
 */

#line 9 "Library/src/utils/chval.hpp"

namespace workspace {

/*
 * @fn chle
 * @brief Substitute y for x if comp(y, x) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chle(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(y, x) ? x = y, true : false;
}

/*
 * @fn chge
 * @brief Substitute y for x if comp(x, y) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chge(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(x, y) ? x = y, true : false;
}

}  // namespace workspace
#line 2 "Library/src/utils/clock.hpp"

/*
 * @fn clock.hpp
 * @brief Clock
 */

#line 9 "Library/src/utils/clock.hpp"

namespace workspace {

using namespace std::chrono;

namespace internal {
// The start time of the program.
const auto start_time{system_clock::now()};
}  // namespace internal

/*
 * @fn elapsed
 * @return elapsed time of the program
 */
int64_t elapsed() {
  const auto end_time{system_clock::now()};
  return duration_cast<milliseconds>(end_time - internal::start_time).count();
}

}  // namespace workspace
#line 2 "Library/src/utils/io/setup.hpp"

/*
 * @file setup.hpp
 * @brief I/O Setup
 */

#line 10 "Library/src/utils/io/setup.hpp"

namespace workspace {

/*
 * @fn io_setup
 * @brief Setup I/O.
 * @param precision Standard output precision
 */
void io_setup(int precision) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(precision);

#ifdef _buffer_check
  atexit([] {
    char bufc;
    if (std::cin >> bufc)
      std::cerr << "\n\033[43m\033[30mwarning: buffer not empty.\033[0m\n\n";
  });
#endif
}

}  // namespace workspace
#line 2 "Library/src/utils/py-like/zip.hpp"

/*
 * @file zip.hpp
 * @brief Zip
 */

#line 11 "Library/src/utils/py-like/zip.hpp"

#line 2 "Library/src/utils/iterator/category.hpp"

/*
 * @file category.hpp
 * @brief Iterator Category
 */

#line 10 "Library/src/utils/iterator/category.hpp"

namespace workspace {

/*
 * @tparam Tuple Tuple of iterator types
 */
template <class Tuple, size_t N = std::tuple_size<Tuple>::value - 1>
struct common_iterator_category {
  using type = typename std::common_type<
      typename common_iterator_category<Tuple, N - 1>::type,
      typename std::iterator_traits<typename std::tuple_element<
          N, Tuple>::type>::iterator_category>::type;
};

template <class Tuple> struct common_iterator_category<Tuple, 0> {
  using type = typename std::iterator_traits<
      typename std::tuple_element<0, Tuple>::type>::iterator_category;
};

}  // namespace workspace
#line 2 "Library/src/utils/iterator/reverse.hpp"

/*
 * @file reverse_iterator.hpp
 * @brief Reverse Iterator
 */

#if __cplusplus >= 201703L

#include <iterator>
#include <optional>

namespace workspace {

/*
 * @class reverse_iterator
 * @brief Wrapper class for `std::reverse_iterator`.
 * @see http://gcc.gnu.org/PR51823
 */
template <class Iterator>
class reverse_iterator : public std::reverse_iterator<Iterator> {
  using base_std = std::reverse_iterator<Iterator>;
  std::optional<typename base_std::value_type> deref;

 public:
  using base_std::reverse_iterator;

  constexpr typename base_std::reference operator*() noexcept {
    if (!deref) {
      Iterator tmp = base_std::current;
      deref = *--tmp;
    }
    return deref.value();
  }

  constexpr reverse_iterator &operator++() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator &operator--() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator++(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator--(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
};

}  // namespace workspace

#endif
#line 14 "Library/src/utils/py-like/zip.hpp"

#if __cplusplus >= 201703L

namespace workspace {

template <class> struct zipped_iterator;

template <class...> struct zipped_iterator_tuple;

template <class... Args> class zipped {
  using ref_tuple = std::tuple<Args...>;
  ref_tuple args;

  template <size_t N = 0> constexpr auto begin_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::begin(std::get<N>(args))),
                            begin_cat<N + 1>());
    } else
      return std::tuple<>();
  }

  template <size_t N = 0> constexpr auto end_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::end(std::get<N>(args))),
                            end_cat<N + 1>());
    } else
      return std::tuple<>();
  }

 public:
  constexpr zipped(Args &&... args) noexcept : args(args...) {}

  class iterator {
    using base_tuple = typename zipped_iterator_tuple<Args...>::type;

   public:
    using iterator_category =
        typename common_iterator_category<base_tuple>::type;
    using difference_type = std::ptrdiff_t;
    using value_type = zipped_iterator<base_tuple>;
    using reference = zipped_iterator<base_tuple> &;
    using pointer = iterator;

   protected:
    value_type current;

    template <size_t N = 0>
    constexpr bool equal(const iterator &rhs) const noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        return std::get<N>(current) == std::get<N>(rhs.current) ||
               equal<N + 1>(rhs);
      } else
        return false;
    }

    template <size_t N = 0> constexpr void increment() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        ++std::get<N>(current);
        increment<N + 1>();
      }
    }

    template <size_t N = 0> constexpr void decrement() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        --std::get<N>(current);
        decrement<N + 1>();
      }
    }

   public:
    constexpr iterator() noexcept = default;
    constexpr iterator(base_tuple const &current) noexcept : current(current) {}

    constexpr bool operator==(const iterator &rhs) const noexcept {
      return equal(rhs);
    }
    constexpr bool operator!=(const iterator &rhs) const noexcept {
      return !equal(rhs);
    }

    constexpr iterator &operator++() noexcept {
      increment();
      return *this;
    }
    constexpr iterator &operator--() noexcept {
      decrement();
      return *this;
    }

    constexpr reference operator*() noexcept { return current; }
  };

  constexpr iterator begin() const noexcept { return iterator{begin_cat()}; }
  constexpr iterator end() const noexcept { return iterator{end_cat()}; }

  constexpr reverse_iterator<iterator> rbegin() const noexcept {
    return reverse_iterator<iterator>{end()};
  }
  constexpr reverse_iterator<iterator> rend() const noexcept {
    return reverse_iterator<iterator>{begin()};
  }
};

template <class Tp, class... Args> struct zipped_iterator_tuple<Tp, Args...> {
  using type = decltype(std::tuple_cat(
      std::declval<std::tuple<decltype(std::begin(std::declval<Tp>()))>>(),
      std::declval<typename zipped_iterator_tuple<Args...>::type>()));
};

template <> struct zipped_iterator_tuple<> { using type = std::tuple<>; };

template <class Iter_tuple> struct zipped_iterator : Iter_tuple {
  constexpr zipped_iterator(Iter_tuple const &__t) noexcept
      : Iter_tuple::tuple(__t) {}

  template <size_t N>
  friend constexpr auto &get(zipped_iterator<Iter_tuple> const &__z) noexcept {
    return *std::get<N>(__z);
  }

  template <size_t N>
  friend constexpr auto get(zipped_iterator<Iter_tuple> const &&__z) noexcept {
    return std::move(*std::get<N>(__z));
  }
};

}  // namespace workspace

namespace std {

template <size_t N, class Iter_tuple>
struct tuple_element<N, workspace::zipped_iterator<Iter_tuple>> {
  using type = typename remove_reference<typename iterator_traits<
      typename tuple_element<N, Iter_tuple>::type>::reference>::type;
};

template <class Iter_tuple>
struct tuple_size<workspace::zipped_iterator<Iter_tuple>>
    : tuple_size<Iter_tuple> {};

}  // namespace std

namespace workspace {

template <class... Args> constexpr auto zip(Args &&... args) noexcept {
  return zipped<Args...>(std::forward<Args>(args)...);
}

template <class... Args>
constexpr auto zip(std::initializer_list<Args> const &... args) noexcept {
  return zipped<std::vector<Args>...>(args...);
}

}  // namespace workspace

#endif
#line 19 "other/oupc/h.cc"

int main() {
  using namespace workspace;

  io_setup(15);

  /* given
  case_info.read();  //*/

  /* unspecified
  case_info.total = -1; //*/

  return case_info.iterate();
}

#line 2 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

/*
 * @file Li_Chao_tree.hpp
 * @brief Li-Chao Tree
 */

#line 10 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

namespace workspace {

/*
 * @struct Li_Chao_tree
 * @tparam T Ordered ring.
 * @tparam Comp Comparison function object type
 * @tparam Infinity Identity element for 'Comp'.
 * @tparam Eps Error tolerance
 */
template <class T, class Comp = std::less<T>,
          T Infinity = std::numeric_limits<T>::max() / 2, T Eps = 1>
struct Li_Chao_tree {
  constexpr static T infinity = Infinity;
  constexpr static T eps = Eps;

  struct line {
    T slope = 0, intercept = Infinity;
    T eval(const T x) const { return slope * x + intercept; }
  };

  /*
   * @param begin Lower bound of domain
   * @param end Upper bound of domain
   * @param comp Comparison function object
   */
  Li_Chao_tree(const T begin, const T end, Comp comp = Comp())
      : begin(begin), end(end), comp(comp) {}

  ~Li_Chao_tree() { delete root; }

  bool empty() const { return !root; }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param ln Line
   */
  void insert(line const &ln) { root = insert(root, begin, end, ln); }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param slope Slope
   * @param intercept Intercept
   */
  void insert(const T slope, const T intercept) {
    insert(line{slope, intercept});
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param seg Segment
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(line const &seg, const T __begin, const T __end) {
    if (__begin < __end) root = insert(root, begin, end, seg, __begin, __end);
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param slope Slope
   * @param intercept Intercept
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(const T slope, const T intercept, const T __begin,
              const T __end) {
    insert(line{slope, intercept}, __begin, __end);
  }

  /*
   * @fn eval
   * @param x Position
   * @return The optimum at given position.
   */
  T eval(const T x) const {
    node *p = root;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return opt;
  }

  /*
   * @fn argmin
   * @param x Position
   * @return The line achieving the optimum at given position.
   */
  line get(const T x) const {
    assert(!empty());
    node *p = root, *arg = nullptr;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval, arg = p;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return arg->__line;
  }

 protected:
  struct node {
    line __line;
    node *__left = nullptr, *__right = nullptr;
    node(node const &) = delete;
    node &operator=(node const &) = delete;
    ~node() {
      delete __left;
      delete __right;
    }
  };

  const T begin, end;
  Comp comp;
  node *root = nullptr;

  node *insert(node *const p, const T l, const T r, line const &ln) {
    if (!p) return new node{ln};
    line &cur = p->__line;
    const bool left_low = comp(ln.eval(l), cur.eval(l));
    if (r - l <= Eps || left_low == comp(ln.eval(r), cur.eval(r))) {
      if (left_low) cur = ln;
      return p;
    }
    const T mid = (l + r) / 2;
    if (comp(ln.eval(mid), cur.eval(mid))) {
      if (left_low)
        p->__right = insert(p->__right, mid, r, cur);
      else
        p->__left = insert(p->__left, l, mid, cur);
      cur = ln;
    } else {
      if (left_low)
        p->__left = insert(p->__left, l, mid, ln);
      else
        p->__right = insert(p->__right, mid, r, ln);
    }
    return p;
  }

  node *insert(node *p, const T l, const T r, line const &seg, const T s,
               const T t) {
    if (s < l + Eps && r < t + Eps) return insert(p, l, r, seg);
    if (l < t && s < r) {
      if (!p) p = new node{};
      p->__left = insert(p->__left, l, (l + r) / 2, seg, s, t);
      p->__right = insert(p->__right, (l + r) / 2, r, seg, s, t);
    }
    return p;
  }
};

}  // namespace workspace
#line 3 "Library/src/utils/random_number_generator.hpp"
template <typename num_type> class random_number_generator {
  typename std::conditional<std::is_integral<num_type>::value,
                            std::uniform_int_distribution<num_type>,
                            std::uniform_real_distribution<num_type>>::type
      unif;

  std::mt19937 engine;

 public:
  random_number_generator(num_type min = std::numeric_limits<num_type>::min(),
                          num_type max = std::numeric_limits<num_type>::max())
      : unif(min, max), engine(std::random_device{}()) {}

  num_type min() const { return unif.min(); }

  num_type max() const { return unif.max(); }

  // generate a random number in [min(), max()].
  num_type operator()() { return unif(engine); }
};
#line 36 "other/oupc/h.cc"

namespace workspace {

void solve() {}

void main() {
  // start here!

  constexpr i64 inf = 3e18;
  random_number_generator rng(0, 1);

  int n;
  cin >> n;
  vector<pair<i64, i64>> lns(n);
  for (auto i = 0; i < n; ++i) {
    i64 a, b;
    cin >> a >> b;
    lns[i] = {a, b};
  }
  int q;
  cin >> q;
  vector<i64> qs(q), ans(q, -inf);
  for (auto &&x : qs) {
    cin >> x;
  }
  int loops = 0;
  while (elapsed() < 1900) {
    ++loops;
    Li_Chao_tree<i64> mi(-3e12, 3e12);
    Li_Chao_tree<i64, greater<i64>, -inf> mx(-3e12, 3e12), mx2(mx);
    for (auto &&[s, t] : lns) {
      if (rng()) {
        mi.insert(s, t);
        mx.insert(s, t);
      } else {
        mx2.insert(s, t);
      }
    }
    if (mx.empty() || mx2.empty()) continue;
    for (auto &&[z, x] : zip(ans, qs)) {
      chge(z, mx2.eval(mi.eval(x)));
      chge(z, mx2.eval(mx.eval(x)));
    }
  }
  for (auto &&e : ans) {
    cout << e << eol;
  }

  // cerr << "\t" << loops << endl;
}

}  // namespace workspace
accuracy: 1
time_ms: 1920
memory_kb: 6300
final_rank: 5

code_snippet: #line 1 "other/oupc/h.cc"
/**
 * @file template.cpp
 * @brief Template
 */

// #undef _GLIBCXX_DEBUG
#include <bits/extc++.h>

#line 2 "Library/lib/alias"

/*
 * @file alias
 * @brief Alias
 */

#line 13 "Library/lib/alias"

namespace workspace {

constexpr char eol = '\n';

using namespace std;

using i32 = int_least32_t;
using u32 = uint_least32_t;
using i64 = int_least64_t;
using u64 = uint_least64_t;

#ifdef __SIZEOF_INT128__
using i128 = __int128_t;
using u128 = __uint128_t;
#else
#warning 128bit integer is not available.
#endif

template <class T, class Comp = less<T>>
using priority_queue = std::priority_queue<T, vector<T>, Comp>;

template <class T> using stack = std::stack<T, vector<T>>;

}  // namespace workspace
#line 10 "other/oupc/h.cc"
// #include "lib/cxx20"
// #include "lib/direct"
#line 2 "Library/src/opt/binary_search.hpp"

/*
 * @file binary_search.hpp
 * @brief Binary Search
 */

#line 12 "Library/src/opt/binary_search.hpp"

namespace workspace {

/*
 * @fn binary_search
 * @brief binary search on a discrete range.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param pred the predicate
 * @return the closest point to (ng) where pred is true
 */
template <class Iter, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Iter>())),
                        bool>::value,
    Iter>::type
binary_search(Iter ok, Iter ng, Pred pred) {
  assert(ok != ng);
  typename std::make_signed<decltype(ng - ok)>::type dist(ng - ok);
  while (1 < dist || dist < -1) {
    const Iter mid(ok + dist / 2);
    if (pred(mid))
      ok = mid, dist -= dist / 2;
    else
      ng = mid, dist /= 2;
  }
  return ok;
}

/*
 * @fn binary_search
 * @brief binary search on the real number line.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary point
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
binary_search(Real ok, Real ng, const Real eps, Pred pred) {
  assert(ok != ng);
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits &&
                       (ok + eps < ng || ng + eps < ok);
       ++loops) {
    const Real mid{(ok + ng) / 2};
    (pred(mid) ? ok : ng) = mid;
  }
  return ok;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on discrete ranges.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param pred the predicate
 * @return the closest points to (second) where pred is true
 */
template <class Array,
          class Iter = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Iter>>())[0]),
        bool>::value,
    std::vector<Iter>>::type
parallel_binary_search(Array ends, Pred pred) {
  std::vector<Iter> mids(std::size(ends));
  for (;;) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Iter &ok = std::get<0>(ends[i]);
      const Iter &ng = std::get<1>(ends[i]);
      const Iter mid(
          ok + typename std::make_signed<decltype(ng - ok)>::type(ng - ok) / 2);
      if (mids[i] != mid) {
        all_found = false;
        mids[i] = mid;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on the real number line.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary points
 */
template <class Array,
          class Real = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Real>>())[0]),
        bool>::value,
    std::vector<Real>>::type
parallel_binary_search(Array ends, const Real eps, Pred pred) {
  std::vector<Real> mids(std::size(ends));
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits; ++loops) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Real ok = std::get<0>(ends[i]);
      const Real ng = std::get<1>(ends[i]);
      if (ok + eps < ng || ng + eps < ok) {
        all_found = false;
        mids[i] = (ok + ng) / 2;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

}  // namespace workspace
#line 2 "Library/src/opt/exponential_search.hpp"

/*
 * @file exponential_search.hpp
 * @brief Exponential Search
 */

#line 9 "Library/src/opt/exponential_search.hpp"

namespace workspace {

/*
 * @fn exponential_search
 * @brief Exponential search on a discrete range.
 * @param range Range of search, exclusive
 * @param pred Predicate
 * @return Minimum non-negative integer where pred is false.
 */
template <class Index, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Index>())),
                        bool>::value,
    Index>::type
exponential_search(Index range, Pred pred) {
  Index step(1);
  while (step < range && pred(step)) step <<= 1;
  if (range < step) step = range;
  return binary_search(Index(0), step, pred);
}

/*
 * @fn exponential_search
 * @brief Exponential search on the real number line.
 * @param range Range of search
 * @param eps Error tolerance
 * @param pred Predicate
 * @return Boundary point.
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
exponential_search(Real range, Real const &eps, Pred pred) {
  Real step(1);
  while (step < range && pred(step)) step += step;
  if (range < step) step = range;
  return binary_search(Real(0), step, eps, pred);
}

}  // namespace workspace
#line 2 "Library/src/opt/trinary_search.hpp"

/*
 * @file trinary_search.hpp
 * @brief Trinary Search
 */

#line 9 "Library/src/opt/trinary_search.hpp"
#include <type_traits>

namespace workspace {

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Iter, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Iter>(),
                                                      std::declval<Iter>())),
                        bool>::value,
    Iter>::type
trinary_search(Iter first, Iter last, Comp comp) {
  assert(first < last);
  typename std::make_signed<decltype(last - first)>::type dist(last - first);
  while (2 < dist) {
    Iter left(first + dist / 3), right(first + dist * 2 / 3);
    if (comp(left, right))
      last = right, dist = (dist + dist) / 3;
    else
      first = left, dist -= dist / 3;
  }
  if (1 < dist && comp(first + 1, first)) ++first;
  return first;
}

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param func Function
 * @return Local minimal point.
 */
template <class Iter, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Iter>()), nullptr),
                 std::nullptr_t>::value,
    Iter>::type
trinary_search(Iter const &first, Iter const &last, Func func) {
  return trinary_search(first, last, [&](Iter const &__i, Iter const &__j) {
    return func(__i) < func(__j);
  });
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Real, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Real>(),
                                                      std::declval<Real>())),
                        bool>::value,
    Real>::type
trinary_search(Real first, Real last, Real const &eps, Comp comp) {
  assert(first < last);
  while (eps < last - first) {
    Real left{(first * 2 + last) / 3}, right{(first + last * 2) / 3};
    if (comp(left, right))
      last = right;
    else
      first = left;
  }
  return first;
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param func Function
 * @return Local minimal point.
 */
template <class Real, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Real>()), nullptr),
                 std::nullptr_t>::value,
    Real>::type
trinary_search(Real const &first, Real const &last, Real const &eps,
               Func func) {
  return trinary_search(
      first, last, eps,
      [&](Real const &__i, Real const &__j) { return func(__i) < func(__j); });
}

}  // namespace workspace
#line 2 "Library/src/sys/ejection.hpp"

/*
 * @file ejection.hpp
 * @brief Ejection
 */

#line 9 "Library/src/sys/ejection.hpp"

namespace workspace {

struct ejection {
  bool exit = 0;
};

/*
 * @brief eject from a try block, throw nullptr
 * @param arg output
 */
template <class Tp> void eject(Tp const &arg) {
  std::cout << arg << "\n";
  throw ejection{};
}

void exit() { throw ejection{true}; }

}  // namespace workspace
#line 2 "Library/src/sys/iteration.hpp"

/*
 * @file iteration.hpp
 * @brief Case Iteration
 */

#line 9 "Library/src/sys/iteration.hpp"

#line 11 "Library/src/sys/iteration.hpp"

namespace workspace {

void main();

struct {
  unsigned current{0}, total{1};

  void read() { (std::cin >> total).ignore(); }

  int iterate() {
    static bool once = false;
    assert(!once);
    once = true;
    while (current++ < total) {
      try {
        main();
      } catch (ejection const& status) {
        if (status.exit) break;
      }
    }
    return 0;
  }
} case_info;

}  // namespace workspace
#line 14 "other/oupc/h.cc"
// #include "lib/utils"
#line 2 "Library/src/utils/chval.hpp"

/*
 * @file chval.hpp
 * @brief Change Less/Greater
 */

#line 9 "Library/src/utils/chval.hpp"

namespace workspace {

/*
 * @fn chle
 * @brief Substitute y for x if comp(y, x) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chle(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(y, x) ? x = y, true : false;
}

/*
 * @fn chge
 * @brief Substitute y for x if comp(x, y) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chge(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(x, y) ? x = y, true : false;
}

}  // namespace workspace
#line 2 "Library/src/utils/clock.hpp"

/*
 * @fn clock.hpp
 * @brief Clock
 */

#line 9 "Library/src/utils/clock.hpp"

namespace workspace {

using namespace std::chrono;

namespace internal {
// The start time of the program.
const auto start_time{system_clock::now()};
}  // namespace internal

/*
 * @fn elapsed
 * @return elapsed time of the program
 */
int64_t elapsed() {
  const auto end_time{system_clock::now()};
  return duration_cast<milliseconds>(end_time - internal::start_time).count();
}

}  // namespace workspace
#line 2 "Library/src/utils/io/setup.hpp"

/*
 * @file setup.hpp
 * @brief I/O Setup
 */

#line 10 "Library/src/utils/io/setup.hpp"

namespace workspace {

/*
 * @fn io_setup
 * @brief Setup I/O.
 * @param precision Standard output precision
 */
void io_setup(int precision) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(precision);

#ifdef _buffer_check
  atexit([] {
    char bufc;
    if (std::cin >> bufc)
      std::cerr << "\n\033[43m\033[30mwarning: buffer not empty.\033[0m\n\n";
  });
#endif
}

}  // namespace workspace
#line 2 "Library/src/utils/py-like/zip.hpp"

/*
 * @file zip.hpp
 * @brief Zip
 */

#line 11 "Library/src/utils/py-like/zip.hpp"

#line 2 "Library/src/utils/iterator/category.hpp"

/*
 * @file category.hpp
 * @brief Iterator Category
 */

#line 10 "Library/src/utils/iterator/category.hpp"

namespace workspace {

/*
 * @tparam Tuple Tuple of iterator types
 */
template <class Tuple, size_t N = std::tuple_size<Tuple>::value - 1>
struct common_iterator_category {
  using type = typename std::common_type<
      typename common_iterator_category<Tuple, N - 1>::type,
      typename std::iterator_traits<typename std::tuple_element<
          N, Tuple>::type>::iterator_category>::type;
};

template <class Tuple> struct common_iterator_category<Tuple, 0> {
  using type = typename std::iterator_traits<
      typename std::tuple_element<0, Tuple>::type>::iterator_category;
};

}  // namespace workspace
#line 2 "Library/src/utils/iterator/reverse.hpp"

/*
 * @file reverse_iterator.hpp
 * @brief Reverse Iterator
 */

#if __cplusplus >= 201703L

#include <iterator>
#include <optional>

namespace workspace {

/*
 * @class reverse_iterator
 * @brief Wrapper class for `std::reverse_iterator`.
 * @see http://gcc.gnu.org/PR51823
 */
template <class Iterator>
class reverse_iterator : public std::reverse_iterator<Iterator> {
  using base_std = std::reverse_iterator<Iterator>;
  std::optional<typename base_std::value_type> deref;

 public:
  using base_std::reverse_iterator;

  constexpr typename base_std::reference operator*() noexcept {
    if (!deref) {
      Iterator tmp = base_std::current;
      deref = *--tmp;
    }
    return deref.value();
  }

  constexpr reverse_iterator &operator++() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator &operator--() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator++(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator--(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
};

}  // namespace workspace

#endif
#line 14 "Library/src/utils/py-like/zip.hpp"

#if __cplusplus >= 201703L

namespace workspace {

template <class> struct zipped_iterator;

template <class...> struct zipped_iterator_tuple;

template <class... Args> class zipped {
  using ref_tuple = std::tuple<Args...>;
  ref_tuple args;

  template <size_t N = 0> constexpr auto begin_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::begin(std::get<N>(args))),
                            begin_cat<N + 1>());
    } else
      return std::tuple<>();
  }

  template <size_t N = 0> constexpr auto end_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::end(std::get<N>(args))),
                            end_cat<N + 1>());
    } else
      return std::tuple<>();
  }

 public:
  constexpr zipped(Args &&... args) noexcept : args(args...) {}

  class iterator {
    using base_tuple = typename zipped_iterator_tuple<Args...>::type;

   public:
    using iterator_category =
        typename common_iterator_category<base_tuple>::type;
    using difference_type = std::ptrdiff_t;
    using value_type = zipped_iterator<base_tuple>;
    using reference = zipped_iterator<base_tuple> &;
    using pointer = iterator;

   protected:
    value_type current;

    template <size_t N = 0>
    constexpr bool equal(const iterator &rhs) const noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        return std::get<N>(current) == std::get<N>(rhs.current) ||
               equal<N + 1>(rhs);
      } else
        return false;
    }

    template <size_t N = 0> constexpr void increment() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        ++std::get<N>(current);
        increment<N + 1>();
      }
    }

    template <size_t N = 0> constexpr void decrement() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        --std::get<N>(current);
        decrement<N + 1>();
      }
    }

   public:
    constexpr iterator() noexcept = default;
    constexpr iterator(base_tuple const &current) noexcept : current(current) {}

    constexpr bool operator==(const iterator &rhs) const noexcept {
      return equal(rhs);
    }
    constexpr bool operator!=(const iterator &rhs) const noexcept {
      return !equal(rhs);
    }

    constexpr iterator &operator++() noexcept {
      increment();
      return *this;
    }
    constexpr iterator &operator--() noexcept {
      decrement();
      return *this;
    }

    constexpr reference operator*() noexcept { return current; }
  };

  constexpr iterator begin() const noexcept { return iterator{begin_cat()}; }
  constexpr iterator end() const noexcept { return iterator{end_cat()}; }

  constexpr reverse_iterator<iterator> rbegin() const noexcept {
    return reverse_iterator<iterator>{end()};
  }
  constexpr reverse_iterator<iterator> rend() const noexcept {
    return reverse_iterator<iterator>{begin()};
  }
};

template <class Tp, class... Args> struct zipped_iterator_tuple<Tp, Args...> {
  using type = decltype(std::tuple_cat(
      std::declval<std::tuple<decltype(std::begin(std::declval<Tp>()))>>(),
      std::declval<typename zipped_iterator_tuple<Args...>::type>()));
};

template <> struct zipped_iterator_tuple<> { using type = std::tuple<>; };

template <class Iter_tuple> struct zipped_iterator : Iter_tuple {
  constexpr zipped_iterator(Iter_tuple const &__t) noexcept
      : Iter_tuple::tuple(__t) {}

  template <size_t N>
  friend constexpr auto &get(zipped_iterator<Iter_tuple> const &__z) noexcept {
    return *std::get<N>(__z);
  }

  template <size_t N>
  friend constexpr auto get(zipped_iterator<Iter_tuple> const &&__z) noexcept {
    return std::move(*std::get<N>(__z));
  }
};

}  // namespace workspace

namespace std {

template <size_t N, class Iter_tuple>
struct tuple_element<N, workspace::zipped_iterator<Iter_tuple>> {
  using type = typename remove_reference<typename iterator_traits<
      typename tuple_element<N, Iter_tuple>::type>::reference>::type;
};

template <class Iter_tuple>
struct tuple_size<workspace::zipped_iterator<Iter_tuple>>
    : tuple_size<Iter_tuple> {};

}  // namespace std

namespace workspace {

template <class... Args> constexpr auto zip(Args &&... args) noexcept {
  return zipped<Args...>(std::forward<Args>(args)...);
}

template <class... Args>
constexpr auto zip(std::initializer_list<Args> const &... args) noexcept {
  return zipped<std::vector<Args>...>(args...);
}

}  // namespace workspace

#endif
#line 19 "other/oupc/h.cc"

int main() {
  using namespace workspace;

  io_setup(15);

  /* given
  case_info.read();  //*/

  /* unspecified
  case_info.total = -1; //*/

  return case_info.iterate();
}

#line 2 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

/*
 * @file Li_Chao_tree.hpp
 * @brief Li-Chao Tree
 */

#line 10 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

namespace workspace {

/*
 * @struct Li_Chao_tree
 * @tparam T Ordered ring.
 * @tparam Comp Comparison function object type
 * @tparam Infinity Identity element for 'Comp'.
 * @tparam Eps Error tolerance
 */
template <class T, class Comp = std::less<T>,
          T Infinity = std::numeric_limits<T>::max() / 2, T Eps = 1>
struct Li_Chao_tree {
  constexpr static T infinity = Infinity;
  constexpr static T eps = Eps;

  struct line {
    T slope = 0, intercept = Infinity;
    T eval(const T x) const { return slope * x + intercept; }
  };

  /*
   * @param begin Lower bound of domain
   * @param end Upper bound of domain
   * @param comp Comparison function object
   */
  Li_Chao_tree(const T begin, const T end, Comp comp = Comp())
      : begin(begin), end(end), comp(comp) {}

  ~Li_Chao_tree() { delete root; }

  bool empty() const { return !root; }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param ln Line
   */
  void insert(line const &ln) { root = insert(root, begin, end, ln); }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param slope Slope
   * @param intercept Intercept
   */
  void insert(const T slope, const T intercept) {
    insert(line{slope, intercept});
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param seg Segment
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(line const &seg, const T __begin, const T __end) {
    if (__begin < __end) root = insert(root, begin, end, seg, __begin, __end);
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param slope Slope
   * @param intercept Intercept
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(const T slope, const T intercept, const T __begin,
              const T __end) {
    insert(line{slope, intercept}, __begin, __end);
  }

  /*
   * @fn eval
   * @param x Position
   * @return The optimum at given position.
   */
  T eval(const T x) const {
    node *p = root;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return opt;
  }

  /*
   * @fn argmin
   * @param x Position
   * @return The line achieving the optimum at given position.
   */
  line get(const T x) const {
    assert(!empty());
    node *p = root, *arg = nullptr;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval, arg = p;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return arg->__line;
  }

 protected:
  struct node {
    line __line;
    node *__left = nullptr, *__right = nullptr;
    node(node const &) = delete;
    node &operator=(node const &) = delete;
    ~node() {
      delete __left;
      delete __right;
    }
  };

  const T begin, end;
  Comp comp;
  node *root = nullptr;

  node *insert(node *const p, const T l, const T r, line const &ln) {
    if (!p) return new node{ln};
    line &cur = p->__line;
    const bool left_low = comp(ln.eval(l), cur.eval(l));
    if (r - l <= Eps || left_low == comp(ln.eval(r), cur.eval(r))) {
      if (left_low) cur = ln;
      return p;
    }
    const T mid = (l + r) / 2;
    if (comp(ln.eval(mid), cur.eval(mid))) {
      if (left_low)
        p->__right = insert(p->__right, mid, r, cur);
      else
        p->__left = insert(p->__left, l, mid, cur);
      cur = ln;
    } else {
      if (left_low)
        p->__left = insert(p->__left, l, mid, ln);
      else
        p->__right = insert(p->__right, mid, r, ln);
    }
    return p;
  }

  node *insert(node *p, const T l, const T r, line const &seg, const T s,
               const T t) {
    if (s < l + Eps && r < t + Eps) return insert(p, l, r, seg);
    if (l < t && s < r) {
      if (!p) p = new node{};
      p->__left = insert(p->__left, l, (l + r) / 2, seg, s, t);
      p->__right = insert(p->__right, (l + r) / 2, r, seg, s, t);
    }
    return p;
  }
};

}  // namespace workspace
#line 35 "other/oupc/h.cc"

namespace workspace {

void solve() {}

void main() {
  // start here!

  constexpr i64 inf = 3e18;

  int n;
  cin >> n;
  vector<pair<i64, i64>> lns(n);
  for (auto i = 0; i < n; ++i) {
    i64 a, b;
    cin >> a >> b;
    lns[i] = {a, b};
  }
  int q;
  cin >> q;
  vector<i64> qs(q), ans(q, -inf);
  for (auto &&x : qs) {
    cin >> x;
  }
  int loops = 0;
  while (elapsed() < 1900) {
    ++loops;
    Li_Chao_tree<i64> mi(-3e12, 3e12);
    Li_Chao_tree<i64, greater<i64>, -inf> mx(-3e12, 3e12), mx2(mx);
    for (auto &&[s, t] : lns) {
      if (elapsed() % 2) {
        mi.insert(s, t);
        mx.insert(s, t);
      } else {
        mx2.insert(s, t);
      }
    }
    if (mx.empty() || mx2.empty()) continue;
    for (auto &&[z, x] : zip(ans, qs)) {
      chge(z, mx2.eval(mi.eval(x)));
      chge(z, mx2.eval(mx.eval(x)));
    }
  }
  for (auto &&e : ans) {
    cout << e << eol;
  }

  // cerr << "\t" << loops << endl;
}

}  // namespace workspace
accuracy: 0.019417475728155338
time_ms: 1900
memory_kb: 5636
final_rank: 16

code_snippet: #line 1 "other/oupc/h.cc"
/**
 * @file template.cpp
 * @brief Template
 */

// #undef _GLIBCXX_DEBUG
#include <bits/extc++.h>

#line 2 "Library/lib/alias"

/*
 * @file alias
 * @brief Alias
 */

#line 13 "Library/lib/alias"

namespace workspace {

constexpr char eol = '\n';

using namespace std;

using i32 = int_least32_t;
using u32 = uint_least32_t;
using i64 = int_least64_t;
using u64 = uint_least64_t;

#ifdef __SIZEOF_INT128__
using i128 = __int128_t;
using u128 = __uint128_t;
#else
#warning 128bit integer is not available.
#endif

template <class T, class Comp = less<T>>
using priority_queue = std::priority_queue<T, vector<T>, Comp>;

template <class T> using stack = std::stack<T, vector<T>>;

}  // namespace workspace
#line 10 "other/oupc/h.cc"
// #include "lib/cxx20"
// #include "lib/direct"
#line 2 "Library/src/opt/binary_search.hpp"

/*
 * @file binary_search.hpp
 * @brief Binary Search
 */

#line 12 "Library/src/opt/binary_search.hpp"

namespace workspace {

/*
 * @fn binary_search
 * @brief binary search on a discrete range.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param pred the predicate
 * @return the closest point to (ng) where pred is true
 */
template <class Iter, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Iter>())),
                        bool>::value,
    Iter>::type
binary_search(Iter ok, Iter ng, Pred pred) {
  assert(ok != ng);
  typename std::make_signed<decltype(ng - ok)>::type dist(ng - ok);
  while (1 < dist || dist < -1) {
    const Iter mid(ok + dist / 2);
    if (pred(mid))
      ok = mid, dist -= dist / 2;
    else
      ng = mid, dist /= 2;
  }
  return ok;
}

/*
 * @fn binary_search
 * @brief binary search on the real number line.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary point
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
binary_search(Real ok, Real ng, const Real eps, Pred pred) {
  assert(ok != ng);
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits &&
                       (ok + eps < ng || ng + eps < ok);
       ++loops) {
    const Real mid{(ok + ng) / 2};
    (pred(mid) ? ok : ng) = mid;
  }
  return ok;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on discrete ranges.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param pred the predicate
 * @return the closest points to (second) where pred is true
 */
template <class Array,
          class Iter = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Iter>>())[0]),
        bool>::value,
    std::vector<Iter>>::type
parallel_binary_search(Array ends, Pred pred) {
  std::vector<Iter> mids(std::size(ends));
  for (;;) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Iter &ok = std::get<0>(ends[i]);
      const Iter &ng = std::get<1>(ends[i]);
      const Iter mid(
          ok + typename std::make_signed<decltype(ng - ok)>::type(ng - ok) / 2);
      if (mids[i] != mid) {
        all_found = false;
        mids[i] = mid;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on the real number line.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary points
 */
template <class Array,
          class Real = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Real>>())[0]),
        bool>::value,
    std::vector<Real>>::type
parallel_binary_search(Array ends, const Real eps, Pred pred) {
  std::vector<Real> mids(std::size(ends));
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits; ++loops) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Real ok = std::get<0>(ends[i]);
      const Real ng = std::get<1>(ends[i]);
      if (ok + eps < ng || ng + eps < ok) {
        all_found = false;
        mids[i] = (ok + ng) / 2;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

}  // namespace workspace
#line 2 "Library/src/opt/exponential_search.hpp"

/*
 * @file exponential_search.hpp
 * @brief Exponential Search
 */

#line 9 "Library/src/opt/exponential_search.hpp"

namespace workspace {

/*
 * @fn exponential_search
 * @brief Exponential search on a discrete range.
 * @param range Range of search, exclusive
 * @param pred Predicate
 * @return Minimum non-negative integer where pred is false.
 */
template <class Index, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Index>())),
                        bool>::value,
    Index>::type
exponential_search(Index range, Pred pred) {
  Index step(1);
  while (step < range && pred(step)) step <<= 1;
  if (range < step) step = range;
  return binary_search(Index(0), step, pred);
}

/*
 * @fn exponential_search
 * @brief Exponential search on the real number line.
 * @param range Range of search
 * @param eps Error tolerance
 * @param pred Predicate
 * @return Boundary point.
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
exponential_search(Real range, Real const &eps, Pred pred) {
  Real step(1);
  while (step < range && pred(step)) step += step;
  if (range < step) step = range;
  return binary_search(Real(0), step, eps, pred);
}

}  // namespace workspace
#line 2 "Library/src/opt/trinary_search.hpp"

/*
 * @file trinary_search.hpp
 * @brief Trinary Search
 */

#line 9 "Library/src/opt/trinary_search.hpp"
#include <type_traits>

namespace workspace {

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Iter, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Iter>(),
                                                      std::declval<Iter>())),
                        bool>::value,
    Iter>::type
trinary_search(Iter first, Iter last, Comp comp) {
  assert(first < last);
  typename std::make_signed<decltype(last - first)>::type dist(last - first);
  while (2 < dist) {
    Iter left(first + dist / 3), right(first + dist * 2 / 3);
    if (comp(left, right))
      last = right, dist = (dist + dist) / 3;
    else
      first = left, dist -= dist / 3;
  }
  if (1 < dist && comp(first + 1, first)) ++first;
  return first;
}

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param func Function
 * @return Local minimal point.
 */
template <class Iter, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Iter>()), nullptr),
                 std::nullptr_t>::value,
    Iter>::type
trinary_search(Iter const &first, Iter const &last, Func func) {
  return trinary_search(first, last, [&](Iter const &__i, Iter const &__j) {
    return func(__i) < func(__j);
  });
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Real, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Real>(),
                                                      std::declval<Real>())),
                        bool>::value,
    Real>::type
trinary_search(Real first, Real last, Real const &eps, Comp comp) {
  assert(first < last);
  while (eps < last - first) {
    Real left{(first * 2 + last) / 3}, right{(first + last * 2) / 3};
    if (comp(left, right))
      last = right;
    else
      first = left;
  }
  return first;
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param func Function
 * @return Local minimal point.
 */
template <class Real, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Real>()), nullptr),
                 std::nullptr_t>::value,
    Real>::type
trinary_search(Real const &first, Real const &last, Real const &eps,
               Func func) {
  return trinary_search(
      first, last, eps,
      [&](Real const &__i, Real const &__j) { return func(__i) < func(__j); });
}

}  // namespace workspace
#line 2 "Library/src/sys/ejection.hpp"

/*
 * @file ejection.hpp
 * @brief Ejection
 */

#line 9 "Library/src/sys/ejection.hpp"

namespace workspace {

struct ejection {
  bool exit = 0;
};

/*
 * @brief eject from a try block, throw nullptr
 * @param arg output
 */
template <class Tp> void eject(Tp const &arg) {
  std::cout << arg << "\n";
  throw ejection{};
}

void exit() { throw ejection{true}; }

}  // namespace workspace
#line 2 "Library/src/sys/iteration.hpp"

/*
 * @file iteration.hpp
 * @brief Case Iteration
 */

#line 9 "Library/src/sys/iteration.hpp"

#line 11 "Library/src/sys/iteration.hpp"

namespace workspace {

void main();

struct {
  unsigned current{0}, total{1};

  void read() { (std::cin >> total).ignore(); }

  int iterate() {
    static bool once = false;
    assert(!once);
    once = true;
    while (current++ < total) {
      try {
        main();
      } catch (ejection const& status) {
        if (status.exit) break;
      }
    }
    return 0;
  }
} case_info;

}  // namespace workspace
#line 14 "other/oupc/h.cc"
// #include "lib/utils"
#line 2 "Library/src/utils/chval.hpp"

/*
 * @file chval.hpp
 * @brief Change Less/Greater
 */

#line 9 "Library/src/utils/chval.hpp"

namespace workspace {

/*
 * @fn chle
 * @brief Substitute y for x if comp(y, x) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chle(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(y, x) ? x = y, true : false;
}

/*
 * @fn chge
 * @brief Substitute y for x if comp(x, y) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chge(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(x, y) ? x = y, true : false;
}

}  // namespace workspace
#line 2 "Library/src/utils/clock.hpp"

/*
 * @fn clock.hpp
 * @brief Clock
 */

#line 9 "Library/src/utils/clock.hpp"

namespace workspace {

using namespace std::chrono;

namespace internal {
// The start time of the program.
const auto start_time{system_clock::now()};
}  // namespace internal

/*
 * @fn elapsed
 * @return elapsed time of the program
 */
int64_t elapsed() {
  const auto end_time{system_clock::now()};
  return duration_cast<milliseconds>(end_time - internal::start_time).count();
}

}  // namespace workspace
#line 2 "Library/src/utils/io/setup.hpp"

/*
 * @file setup.hpp
 * @brief I/O Setup
 */

#line 10 "Library/src/utils/io/setup.hpp"

namespace workspace {

/*
 * @fn io_setup
 * @brief Setup I/O.
 * @param precision Standard output precision
 */
void io_setup(int precision) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(precision);

#ifdef _buffer_check
  atexit([] {
    char bufc;
    if (std::cin >> bufc)
      std::cerr << "\n\033[43m\033[30mwarning: buffer not empty.\033[0m\n\n";
  });
#endif
}

}  // namespace workspace
#line 2 "Library/src/utils/py-like/zip.hpp"

/*
 * @file zip.hpp
 * @brief Zip
 */

#line 11 "Library/src/utils/py-like/zip.hpp"

#line 2 "Library/src/utils/iterator/category.hpp"

/*
 * @file category.hpp
 * @brief Iterator Category
 */

#line 10 "Library/src/utils/iterator/category.hpp"

namespace workspace {

/*
 * @tparam Tuple Tuple of iterator types
 */
template <class Tuple, size_t N = std::tuple_size<Tuple>::value - 1>
struct common_iterator_category {
  using type = typename std::common_type<
      typename common_iterator_category<Tuple, N - 1>::type,
      typename std::iterator_traits<typename std::tuple_element<
          N, Tuple>::type>::iterator_category>::type;
};

template <class Tuple> struct common_iterator_category<Tuple, 0> {
  using type = typename std::iterator_traits<
      typename std::tuple_element<0, Tuple>::type>::iterator_category;
};

}  // namespace workspace
#line 2 "Library/src/utils/iterator/reverse.hpp"

/*
 * @file reverse_iterator.hpp
 * @brief Reverse Iterator
 */

#if __cplusplus >= 201703L

#include <iterator>
#include <optional>

namespace workspace {

/*
 * @class reverse_iterator
 * @brief Wrapper class for `std::reverse_iterator`.
 * @see http://gcc.gnu.org/PR51823
 */
template <class Iterator>
class reverse_iterator : public std::reverse_iterator<Iterator> {
  using base_std = std::reverse_iterator<Iterator>;
  std::optional<typename base_std::value_type> deref;

 public:
  using base_std::reverse_iterator;

  constexpr typename base_std::reference operator*() noexcept {
    if (!deref) {
      Iterator tmp = base_std::current;
      deref = *--tmp;
    }
    return deref.value();
  }

  constexpr reverse_iterator &operator++() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator &operator--() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator++(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator--(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
};

}  // namespace workspace

#endif
#line 14 "Library/src/utils/py-like/zip.hpp"

#if __cplusplus >= 201703L

namespace workspace {

template <class> struct zipped_iterator;

template <class...> struct zipped_iterator_tuple;

template <class... Args> class zipped {
  using ref_tuple = std::tuple<Args...>;
  ref_tuple args;

  template <size_t N = 0> constexpr auto begin_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::begin(std::get<N>(args))),
                            begin_cat<N + 1>());
    } else
      return std::tuple<>();
  }

  template <size_t N = 0> constexpr auto end_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::end(std::get<N>(args))),
                            end_cat<N + 1>());
    } else
      return std::tuple<>();
  }

 public:
  constexpr zipped(Args &&... args) noexcept : args(args...) {}

  class iterator {
    using base_tuple = typename zipped_iterator_tuple<Args...>::type;

   public:
    using iterator_category =
        typename common_iterator_category<base_tuple>::type;
    using difference_type = std::ptrdiff_t;
    using value_type = zipped_iterator<base_tuple>;
    using reference = zipped_iterator<base_tuple> &;
    using pointer = iterator;

   protected:
    value_type current;

    template <size_t N = 0>
    constexpr bool equal(const iterator &rhs) const noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        return std::get<N>(current) == std::get<N>(rhs.current) ||
               equal<N + 1>(rhs);
      } else
        return false;
    }

    template <size_t N = 0> constexpr void increment() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        ++std::get<N>(current);
        increment<N + 1>();
      }
    }

    template <size_t N = 0> constexpr void decrement() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        --std::get<N>(current);
        decrement<N + 1>();
      }
    }

   public:
    constexpr iterator() noexcept = default;
    constexpr iterator(base_tuple const &current) noexcept : current(current) {}

    constexpr bool operator==(const iterator &rhs) const noexcept {
      return equal(rhs);
    }
    constexpr bool operator!=(const iterator &rhs) const noexcept {
      return !equal(rhs);
    }

    constexpr iterator &operator++() noexcept {
      increment();
      return *this;
    }
    constexpr iterator &operator--() noexcept {
      decrement();
      return *this;
    }

    constexpr reference operator*() noexcept { return current; }
  };

  constexpr iterator begin() const noexcept { return iterator{begin_cat()}; }
  constexpr iterator end() const noexcept { return iterator{end_cat()}; }

  constexpr reverse_iterator<iterator> rbegin() const noexcept {
    return reverse_iterator<iterator>{end()};
  }
  constexpr reverse_iterator<iterator> rend() const noexcept {
    return reverse_iterator<iterator>{begin()};
  }
};

template <class Tp, class... Args> struct zipped_iterator_tuple<Tp, Args...> {
  using type = decltype(std::tuple_cat(
      std::declval<std::tuple<decltype(std::begin(std::declval<Tp>()))>>(),
      std::declval<typename zipped_iterator_tuple<Args...>::type>()));
};

template <> struct zipped_iterator_tuple<> { using type = std::tuple<>; };

template <class Iter_tuple> struct zipped_iterator : Iter_tuple {
  constexpr zipped_iterator(Iter_tuple const &__t) noexcept
      : Iter_tuple::tuple(__t) {}

  template <size_t N>
  friend constexpr auto &get(zipped_iterator<Iter_tuple> const &__z) noexcept {
    return *std::get<N>(__z);
  }

  template <size_t N>
  friend constexpr auto get(zipped_iterator<Iter_tuple> const &&__z) noexcept {
    return std::move(*std::get<N>(__z));
  }
};

}  // namespace workspace

namespace std {

template <size_t N, class Iter_tuple>
struct tuple_element<N, workspace::zipped_iterator<Iter_tuple>> {
  using type = typename remove_reference<typename iterator_traits<
      typename tuple_element<N, Iter_tuple>::type>::reference>::type;
};

template <class Iter_tuple>
struct tuple_size<workspace::zipped_iterator<Iter_tuple>>
    : tuple_size<Iter_tuple> {};

}  // namespace std

namespace workspace {

template <class... Args> constexpr auto zip(Args &&... args) noexcept {
  return zipped<Args...>(std::forward<Args>(args)...);
}

template <class... Args>
constexpr auto zip(std::initializer_list<Args> const &... args) noexcept {
  return zipped<std::vector<Args>...>(args...);
}

}  // namespace workspace

#endif
#line 19 "other/oupc/h.cc"

int main() {
  using namespace workspace;

  io_setup(15);

  /* given
  case_info.read();  //*/

  /* unspecified
  case_info.total = -1; //*/

  return case_info.iterate();
}

#line 2 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

/*
 * @file Li_Chao_tree.hpp
 * @brief Li-Chao Tree
 */

#line 10 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

namespace workspace {

/*
 * @struct Li_Chao_tree
 * @tparam T Ordered ring.
 * @tparam Comp Comparison function object type
 * @tparam Infinity Identity element for 'Comp'.
 * @tparam Eps Error tolerance
 */
template <class T, class Comp = std::less<T>,
          T Infinity = std::numeric_limits<T>::max() / 2, T Eps = 1>
struct Li_Chao_tree {
  constexpr static T infinity = Infinity;
  constexpr static T eps = Eps;

  struct line {
    T slope = 0, intercept = Infinity;
    T eval(const T x) const { return slope * x + intercept; }
  };

  /*
   * @param begin Lower bound of domain
   * @param end Upper bound of domain
   * @param comp Comparison function object
   */
  Li_Chao_tree(const T begin, const T end, Comp comp = Comp())
      : begin(begin), end(end), comp(comp) {}

  ~Li_Chao_tree() { delete root; }

  bool empty() const { return !root; }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param ln Line
   */
  void insert(line const &ln) { root = insert(root, begin, end, ln); }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param slope Slope
   * @param intercept Intercept
   */
  void insert(const T slope, const T intercept) {
    insert(line{slope, intercept});
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param seg Segment
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(line const &seg, const T __begin, const T __end) {
    if (__begin < __end) root = insert(root, begin, end, seg, __begin, __end);
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param slope Slope
   * @param intercept Intercept
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(const T slope, const T intercept, const T __begin,
              const T __end) {
    insert(line{slope, intercept}, __begin, __end);
  }

  /*
   * @fn eval
   * @param x Position
   * @return The optimum at given position.
   */
  T eval(const T x) const {
    node *p = root;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return opt;
  }

  /*
   * @fn argmin
   * @param x Position
   * @return The line achieving the optimum at given position.
   */
  line get(const T x) const {
    assert(!empty());
    node *p = root, *arg = nullptr;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval, arg = p;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return arg->__line;
  }

 protected:
  struct node {
    line __line;
    node *__left = nullptr, *__right = nullptr;
    node(node const &) = delete;
    node &operator=(node const &) = delete;
    ~node() {
      delete __left;
      delete __right;
    }
  };

  const T begin, end;
  Comp comp;
  node *root = nullptr;

  node *insert(node *const p, const T l, const T r, line const &ln) {
    if (!p) return new node{ln};
    line &cur = p->__line;
    const bool left_low = comp(ln.eval(l), cur.eval(l));
    if (r - l <= Eps || left_low == comp(ln.eval(r), cur.eval(r))) {
      if (left_low) cur = ln;
      return p;
    }
    const T mid = (l + r) / 2;
    if (comp(ln.eval(mid), cur.eval(mid))) {
      if (left_low)
        p->__right = insert(p->__right, mid, r, cur);
      else
        p->__left = insert(p->__left, l, mid, cur);
      cur = ln;
    } else {
      if (left_low)
        p->__left = insert(p->__left, l, mid, ln);
      else
        p->__right = insert(p->__right, mid, r, ln);
    }
    return p;
  }

  node *insert(node *p, const T l, const T r, line const &seg, const T s,
               const T t) {
    if (s < l + Eps && r < t + Eps) return insert(p, l, r, seg);
    if (l < t && s < r) {
      if (!p) p = new node{};
      p->__left = insert(p->__left, l, (l + r) / 2, seg, s, t);
      p->__right = insert(p->__right, (l + r) / 2, r, seg, s, t);
    }
    return p;
  }
};

}  // namespace workspace
#line 35 "other/oupc/h.cc"

namespace workspace {

void solve() {}

void main() {
  // start here!

  constexpr i64 inf = 2e18;

  int n;
  cin >> n;
  vector<pair<i64, i64>> lns(n);
  for (auto i = 0; i < n; ++i) {
    i64 a, b;
    cin >> a >> b;
    lns[i] = {a, b};
  }
  int q;
  cin >> q;
  vector<i64> qs(q), ans(q, -inf);
  for (auto &&x : qs) {
    cin >> x;
  }
  int loops = 0;
  while (elapsed() < 1900) {
    ++loops;
    Li_Chao_tree<i64> mi(-3e12, 3e12);
    Li_Chao_tree<i64, greater<i64>, -inf> mx(-3e12, 3e12), mx2(mx);
    for (auto &&[s, t] : lns) {
      if (elapsed() % 2) {
        mi.insert(s, t);
        mx.insert(s, t);
      } else {
        mx2.insert(s, t);
      }
    }
    if (mx.empty() || mx2.empty()) continue;
    for (auto &&[z, x] : zip(ans, qs)) {
      chge(z, mx2.eval(mi.eval(x)));
      chge(z, mx2.eval(mx.eval(x)));
    }
  }
  for (auto &&e : ans) {
    cout << e << eol;
  }

  // cerr << "\t" << loops << endl;
}

}  // namespace workspace
accuracy: 0.019417475728155338
time_ms: 1900
memory_kb: 5672
final_rank: 17

code_snippet: #line 1 "other/oupc/h.cc"
/**
 * @file template.cpp
 * @brief Template
 */

// #undef _GLIBCXX_DEBUG
#include <bits/extc++.h>

#line 2 "Library/lib/alias"

/*
 * @file alias
 * @brief Alias
 */

#line 13 "Library/lib/alias"

namespace workspace {

constexpr char eol = '\n';

using namespace std;

using i32 = int_least32_t;
using u32 = uint_least32_t;
using i64 = int_least64_t;
using u64 = uint_least64_t;

#ifdef __SIZEOF_INT128__
using i128 = __int128_t;
using u128 = __uint128_t;
#else
#warning 128bit integer is not available.
#endif

template <class T, class Comp = less<T>>
using priority_queue = std::priority_queue<T, vector<T>, Comp>;

template <class T> using stack = std::stack<T, vector<T>>;

}  // namespace workspace
#line 10 "other/oupc/h.cc"
// #include "lib/cxx20"
// #include "lib/direct"
#line 2 "Library/src/opt/binary_search.hpp"

/*
 * @file binary_search.hpp
 * @brief Binary Search
 */

#line 12 "Library/src/opt/binary_search.hpp"

namespace workspace {

/*
 * @fn binary_search
 * @brief binary search on a discrete range.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param pred the predicate
 * @return the closest point to (ng) where pred is true
 */
template <class Iter, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Iter>())),
                        bool>::value,
    Iter>::type
binary_search(Iter ok, Iter ng, Pred pred) {
  assert(ok != ng);
  typename std::make_signed<decltype(ng - ok)>::type dist(ng - ok);
  while (1 < dist || dist < -1) {
    const Iter mid(ok + dist / 2);
    if (pred(mid))
      ok = mid, dist -= dist / 2;
    else
      ng = mid, dist /= 2;
  }
  return ok;
}

/*
 * @fn binary_search
 * @brief binary search on the real number line.
 * @param ok pred(ok) is true
 * @param ng pred(ng) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary point
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
binary_search(Real ok, Real ng, const Real eps, Pred pred) {
  assert(ok != ng);
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits &&
                       (ok + eps < ng || ng + eps < ok);
       ++loops) {
    const Real mid{(ok + ng) / 2};
    (pred(mid) ? ok : ng) = mid;
  }
  return ok;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on discrete ranges.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param pred the predicate
 * @return the closest points to (second) where pred is true
 */
template <class Array,
          class Iter = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Iter>>())[0]),
        bool>::value,
    std::vector<Iter>>::type
parallel_binary_search(Array ends, Pred pred) {
  std::vector<Iter> mids(std::size(ends));
  for (;;) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Iter &ok = std::get<0>(ends[i]);
      const Iter &ng = std::get<1>(ends[i]);
      const Iter mid(
          ok + typename std::make_signed<decltype(ng - ok)>::type(ng - ok) / 2);
      if (mids[i] != mid) {
        all_found = false;
        mids[i] = mid;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

/*
 * @fn parallel_binary_search
 * @brief parallel binary search on the real number line.
 * @param ends a vector of pairs; pred(first) is true, pred(second) is false
 * @param eps the error tolerance
 * @param pred the predicate
 * @return the boundary points
 */
template <class Array,
          class Real = typename std::decay<
              decltype(std::get<0>(std::declval<Array>()[0]))>::type,
          class Pred>
typename std::enable_if<
    std::is_convertible<
        decltype(std::declval<Pred>()(std::declval<std::vector<Real>>())[0]),
        bool>::value,
    std::vector<Real>>::type
parallel_binary_search(Array ends, const Real eps, Pred pred) {
  std::vector<Real> mids(std::size(ends));
  for (auto loops = 0; loops != std::numeric_limits<Real>::digits; ++loops) {
    bool all_found = true;
    for (size_t i{}; i != std::size(ends); ++i) {
      const Real ok = std::get<0>(ends[i]);
      const Real ng = std::get<1>(ends[i]);
      if (ok + eps < ng || ng + eps < ok) {
        all_found = false;
        mids[i] = (ok + ng) / 2;
      }
    }
    if (all_found) break;
    const auto res = pred(mids);
    for (size_t i{}; i != std::size(ends); ++i) {
      (res[i] ? std::get<0>(ends[i]) : std::get<1>(ends[i])) = mids[i];
    }
  }
  return mids;
}

}  // namespace workspace
#line 2 "Library/src/opt/exponential_search.hpp"

/*
 * @file exponential_search.hpp
 * @brief Exponential Search
 */

#line 9 "Library/src/opt/exponential_search.hpp"

namespace workspace {

/*
 * @fn exponential_search
 * @brief Exponential search on a discrete range.
 * @param range Range of search, exclusive
 * @param pred Predicate
 * @return Minimum non-negative integer where pred is false.
 */
template <class Index, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Index>())),
                        bool>::value,
    Index>::type
exponential_search(Index range, Pred pred) {
  Index step(1);
  while (step < range && pred(step)) step <<= 1;
  if (range < step) step = range;
  return binary_search(Index(0), step, pred);
}

/*
 * @fn exponential_search
 * @brief Exponential search on the real number line.
 * @param range Range of search
 * @param eps Error tolerance
 * @param pred Predicate
 * @return Boundary point.
 */
template <class Real, class Pred>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Pred>()(std::declval<Real>())),
                        bool>::value,
    Real>::type
exponential_search(Real range, Real const &eps, Pred pred) {
  Real step(1);
  while (step < range && pred(step)) step += step;
  if (range < step) step = range;
  return binary_search(Real(0), step, eps, pred);
}

}  // namespace workspace
#line 2 "Library/src/opt/trinary_search.hpp"

/*
 * @file trinary_search.hpp
 * @brief Trinary Search
 */

#line 9 "Library/src/opt/trinary_search.hpp"
#include <type_traits>

namespace workspace {

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Iter, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Iter>(),
                                                      std::declval<Iter>())),
                        bool>::value,
    Iter>::type
trinary_search(Iter first, Iter last, Comp comp) {
  assert(first < last);
  typename std::make_signed<decltype(last - first)>::type dist(last - first);
  while (2 < dist) {
    Iter left(first + dist / 3), right(first + dist * 2 / 3);
    if (comp(left, right))
      last = right, dist = (dist + dist) / 3;
    else
      first = left, dist -= dist / 3;
  }
  if (1 < dist && comp(first + 1, first)) ++first;
  return first;
}

/*
 * @brief Trinary search on discrete range.
 * @param first Left end, inclusive
 * @param last Right end, exclusive
 * @param func Function
 * @return Local minimal point.
 */
template <class Iter, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Iter>()), nullptr),
                 std::nullptr_t>::value,
    Iter>::type
trinary_search(Iter const &first, Iter const &last, Func func) {
  return trinary_search(first, last, [&](Iter const &__i, Iter const &__j) {
    return func(__i) < func(__j);
  });
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param comp Compare function
 * @return Local minimal point.
 */
template <class Real, class Comp>
typename std::enable_if<
    std::is_convertible<decltype(std::declval<Comp>()(std::declval<Real>(),
                                                      std::declval<Real>())),
                        bool>::value,
    Real>::type
trinary_search(Real first, Real last, Real const &eps, Comp comp) {
  assert(first < last);
  while (eps < last - first) {
    Real left{(first * 2 + last) / 3}, right{(first + last * 2) / 3};
    if (comp(left, right))
      last = right;
    else
      first = left;
  }
  return first;
}

/*
 * @brief Trinary search on the real number line.
 * @param first Left end
 * @param last Right end
 * @param eps Error tolerance
 * @param func Function
 * @return Local minimal point.
 */
template <class Real, class Func>
typename std::enable_if<
    std::is_same<decltype(std::declval<Func>()(std::declval<Real>()), nullptr),
                 std::nullptr_t>::value,
    Real>::type
trinary_search(Real const &first, Real const &last, Real const &eps,
               Func func) {
  return trinary_search(
      first, last, eps,
      [&](Real const &__i, Real const &__j) { return func(__i) < func(__j); });
}

}  // namespace workspace
#line 2 "Library/src/sys/ejection.hpp"

/*
 * @file ejection.hpp
 * @brief Ejection
 */

#line 9 "Library/src/sys/ejection.hpp"

namespace workspace {

struct ejection {
  bool exit = 0;
};

/*
 * @brief eject from a try block, throw nullptr
 * @param arg output
 */
template <class Tp> void eject(Tp const &arg) {
  std::cout << arg << "\n";
  throw ejection{};
}

void exit() { throw ejection{true}; }

}  // namespace workspace
#line 2 "Library/src/sys/iteration.hpp"

/*
 * @file iteration.hpp
 * @brief Case Iteration
 */

#line 9 "Library/src/sys/iteration.hpp"

#line 11 "Library/src/sys/iteration.hpp"

namespace workspace {

void main();

struct {
  unsigned current{0}, total{1};

  void read() { (std::cin >> total).ignore(); }

  int iterate() {
    static bool once = false;
    assert(!once);
    once = true;
    while (current++ < total) {
      try {
        main();
      } catch (ejection const& status) {
        if (status.exit) break;
      }
    }
    return 0;
  }
} case_info;

}  // namespace workspace
#line 14 "other/oupc/h.cc"
// #include "lib/utils"
#line 2 "Library/src/utils/chval.hpp"

/*
 * @file chval.hpp
 * @brief Change Less/Greater
 */

#line 9 "Library/src/utils/chval.hpp"

namespace workspace {

/*
 * @fn chle
 * @brief Substitute y for x if comp(y, x) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chle(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(y, x) ? x = y, true : false;
}

/*
 * @fn chge
 * @brief Substitute y for x if comp(x, y) is true.
 * @param x Reference
 * @param y Const reference
 * @param comp Compare function
 * @return Whether or not x is updated
 */
template <class Tp, class Comp = std::less<Tp>>
bool chge(Tp &x, const Tp &y, Comp comp = Comp()) {
  return comp(x, y) ? x = y, true : false;
}

}  // namespace workspace
#line 2 "Library/src/utils/clock.hpp"

/*
 * @fn clock.hpp
 * @brief Clock
 */

#line 9 "Library/src/utils/clock.hpp"

namespace workspace {

using namespace std::chrono;

namespace internal {
// The start time of the program.
const auto start_time{system_clock::now()};
}  // namespace internal

/*
 * @fn elapsed
 * @return elapsed time of the program
 */
int64_t elapsed() {
  const auto end_time{system_clock::now()};
  return duration_cast<milliseconds>(end_time - internal::start_time).count();
}

}  // namespace workspace
#line 2 "Library/src/utils/io/setup.hpp"

/*
 * @file setup.hpp
 * @brief I/O Setup
 */

#line 10 "Library/src/utils/io/setup.hpp"

namespace workspace {

/*
 * @fn io_setup
 * @brief Setup I/O.
 * @param precision Standard output precision
 */
void io_setup(int precision) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(precision);

#ifdef _buffer_check
  atexit([] {
    char bufc;
    if (std::cin >> bufc)
      std::cerr << "\n\033[43m\033[30mwarning: buffer not empty.\033[0m\n\n";
  });
#endif
}

}  // namespace workspace
#line 2 "Library/src/utils/py-like/zip.hpp"

/*
 * @file zip.hpp
 * @brief Zip
 */

#line 11 "Library/src/utils/py-like/zip.hpp"

#line 2 "Library/src/utils/iterator/category.hpp"

/*
 * @file category.hpp
 * @brief Iterator Category
 */

#line 10 "Library/src/utils/iterator/category.hpp"

namespace workspace {

/*
 * @tparam Tuple Tuple of iterator types
 */
template <class Tuple, size_t N = std::tuple_size<Tuple>::value - 1>
struct common_iterator_category {
  using type = typename std::common_type<
      typename common_iterator_category<Tuple, N - 1>::type,
      typename std::iterator_traits<typename std::tuple_element<
          N, Tuple>::type>::iterator_category>::type;
};

template <class Tuple> struct common_iterator_category<Tuple, 0> {
  using type = typename std::iterator_traits<
      typename std::tuple_element<0, Tuple>::type>::iterator_category;
};

}  // namespace workspace
#line 2 "Library/src/utils/iterator/reverse.hpp"

/*
 * @file reverse_iterator.hpp
 * @brief Reverse Iterator
 */

#if __cplusplus >= 201703L

#include <iterator>
#include <optional>

namespace workspace {

/*
 * @class reverse_iterator
 * @brief Wrapper class for `std::reverse_iterator`.
 * @see http://gcc.gnu.org/PR51823
 */
template <class Iterator>
class reverse_iterator : public std::reverse_iterator<Iterator> {
  using base_std = std::reverse_iterator<Iterator>;
  std::optional<typename base_std::value_type> deref;

 public:
  using base_std::reverse_iterator;

  constexpr typename base_std::reference operator*() noexcept {
    if (!deref) {
      Iterator tmp = base_std::current;
      deref = *--tmp;
    }
    return deref.value();
  }

  constexpr reverse_iterator &operator++() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator &operator--() noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator++(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
  constexpr reverse_iterator operator--(int) noexcept {
    base_std::operator++();
    deref.reset();
    return *this;
  }
};

}  // namespace workspace

#endif
#line 14 "Library/src/utils/py-like/zip.hpp"

#if __cplusplus >= 201703L

namespace workspace {

template <class> struct zipped_iterator;

template <class...> struct zipped_iterator_tuple;

template <class... Args> class zipped {
  using ref_tuple = std::tuple<Args...>;
  ref_tuple args;

  template <size_t N = 0> constexpr auto begin_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::begin(std::get<N>(args))),
                            begin_cat<N + 1>());
    } else
      return std::tuple<>();
  }

  template <size_t N = 0> constexpr auto end_cat() const noexcept {
    if constexpr (N != std::tuple_size<ref_tuple>::value) {
      return std::tuple_cat(std::tuple(std::end(std::get<N>(args))),
                            end_cat<N + 1>());
    } else
      return std::tuple<>();
  }

 public:
  constexpr zipped(Args &&... args) noexcept : args(args...) {}

  class iterator {
    using base_tuple = typename zipped_iterator_tuple<Args...>::type;

   public:
    using iterator_category =
        typename common_iterator_category<base_tuple>::type;
    using difference_type = std::ptrdiff_t;
    using value_type = zipped_iterator<base_tuple>;
    using reference = zipped_iterator<base_tuple> &;
    using pointer = iterator;

   protected:
    value_type current;

    template <size_t N = 0>
    constexpr bool equal(const iterator &rhs) const noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        return std::get<N>(current) == std::get<N>(rhs.current) ||
               equal<N + 1>(rhs);
      } else
        return false;
    }

    template <size_t N = 0> constexpr void increment() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        ++std::get<N>(current);
        increment<N + 1>();
      }
    }

    template <size_t N = 0> constexpr void decrement() noexcept {
      if constexpr (N != std::tuple_size<base_tuple>::value) {
        --std::get<N>(current);
        decrement<N + 1>();
      }
    }

   public:
    constexpr iterator() noexcept = default;
    constexpr iterator(base_tuple const &current) noexcept : current(current) {}

    constexpr bool operator==(const iterator &rhs) const noexcept {
      return equal(rhs);
    }
    constexpr bool operator!=(const iterator &rhs) const noexcept {
      return !equal(rhs);
    }

    constexpr iterator &operator++() noexcept {
      increment();
      return *this;
    }
    constexpr iterator &operator--() noexcept {
      decrement();
      return *this;
    }

    constexpr reference operator*() noexcept { return current; }
  };

  constexpr iterator begin() const noexcept { return iterator{begin_cat()}; }
  constexpr iterator end() const noexcept { return iterator{end_cat()}; }

  constexpr reverse_iterator<iterator> rbegin() const noexcept {
    return reverse_iterator<iterator>{end()};
  }
  constexpr reverse_iterator<iterator> rend() const noexcept {
    return reverse_iterator<iterator>{begin()};
  }
};

template <class Tp, class... Args> struct zipped_iterator_tuple<Tp, Args...> {
  using type = decltype(std::tuple_cat(
      std::declval<std::tuple<decltype(std::begin(std::declval<Tp>()))>>(),
      std::declval<typename zipped_iterator_tuple<Args...>::type>()));
};

template <> struct zipped_iterator_tuple<> { using type = std::tuple<>; };

template <class Iter_tuple> struct zipped_iterator : Iter_tuple {
  constexpr zipped_iterator(Iter_tuple const &__t) noexcept
      : Iter_tuple::tuple(__t) {}

  template <size_t N>
  friend constexpr auto &get(zipped_iterator<Iter_tuple> const &__z) noexcept {
    return *std::get<N>(__z);
  }

  template <size_t N>
  friend constexpr auto get(zipped_iterator<Iter_tuple> const &&__z) noexcept {
    return std::move(*std::get<N>(__z));
  }
};

}  // namespace workspace

namespace std {

template <size_t N, class Iter_tuple>
struct tuple_element<N, workspace::zipped_iterator<Iter_tuple>> {
  using type = typename remove_reference<typename iterator_traits<
      typename tuple_element<N, Iter_tuple>::type>::reference>::type;
};

template <class Iter_tuple>
struct tuple_size<workspace::zipped_iterator<Iter_tuple>>
    : tuple_size<Iter_tuple> {};

}  // namespace std

namespace workspace {

template <class... Args> constexpr auto zip(Args &&... args) noexcept {
  return zipped<Args...>(std::forward<Args>(args)...);
}

template <class... Args>
constexpr auto zip(std::initializer_list<Args> const &... args) noexcept {
  return zipped<std::vector<Args>...>(args...);
}

}  // namespace workspace

#endif
#line 19 "other/oupc/h.cc"

int main() {
  using namespace workspace;

  io_setup(15);

  /* given
  case_info.read();  //*/

  /* unspecified
  case_info.total = -1; //*/

  return case_info.iterate();
}

#line 2 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

/*
 * @file Li_Chao_tree.hpp
 * @brief Li-Chao Tree
 */

#line 10 "Library/src/data_structure/convex_hull_trick/Li_Chao_tree.hpp"

namespace workspace {

/*
 * @struct Li_Chao_tree
 * @tparam T Ordered ring.
 * @tparam Comp Comparison function object type
 * @tparam Infinity Identity element for 'Comp'.
 * @tparam Eps Error tolerance
 */
template <class T, class Comp = std::less<T>,
          T Infinity = std::numeric_limits<T>::max() / 2, T Eps = 1>
struct Li_Chao_tree {
  constexpr static T infinity = Infinity;
  constexpr static T eps = Eps;

  struct line {
    T slope = 0, intercept = Infinity;
    T eval(const T x) const { return slope * x + intercept; }
  };

  /*
   * @param begin Lower bound of domain
   * @param end Upper bound of domain
   * @param comp Comparison function object
   */
  Li_Chao_tree(const T begin, const T end, Comp comp = Comp())
      : begin(begin), end(end), comp(comp) {}

  ~Li_Chao_tree() { delete root; }

  bool empty() const { return !root; }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param ln Line
   */
  void insert(line const &ln) { root = insert(root, begin, end, ln); }

  /*
   * @fn insert
   * @brief Insert a line.
   * @param slope Slope
   * @param intercept Intercept
   */
  void insert(const T slope, const T intercept) {
    insert(line{slope, intercept});
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param seg Segment
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(line const &seg, const T __begin, const T __end) {
    if (__begin < __end) root = insert(root, begin, end, seg, __begin, __end);
  }

  /*
   * @fn insert
   * @brief Insert a segment.
   * @param slope Slope
   * @param intercept Intercept
   * @param __begin Left end, inclusive
   * @param __end Right end, exclusive
   */
  void insert(const T slope, const T intercept, const T __begin,
              const T __end) {
    insert(line{slope, intercept}, __begin, __end);
  }

  /*
   * @fn eval
   * @param x Position
   * @return The optimum at given position.
   */
  T eval(const T x) const {
    node *p = root;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return opt;
  }

  /*
   * @fn argmin
   * @param x Position
   * @return The line achieving the optimum at given position.
   */
  line get(const T x) const {
    assert(!empty());
    node *p = root, *arg = nullptr;
    T l = begin, r = end, opt = Infinity;
    while (p) {
      const T nval = p->__line.eval(x);
      if (comp(nval, opt)) opt = nval, arg = p;
      if (r - l <= Eps) break;
      const T mid = (l + r) / 2;
      if (x < mid) {
        p = p->__left;
        r = mid;
      } else {
        p = p->__right;
        l = mid;
      }
    }
    return arg->__line;
  }

 protected:
  struct node {
    line __line;
    node *__left = nullptr, *__right = nullptr;
    node(node const &) = delete;
    node &operator=(node const &) = delete;
    ~node() {
      delete __left;
      delete __right;
    }
  };

  const T begin, end;
  Comp comp;
  node *root = nullptr;

  node *insert(node *const p, const T l, const T r, line const &ln) {
    if (!p) return new node{ln};
    line &cur = p->__line;
    const bool left_low = comp(ln.eval(l), cur.eval(l));
    if (r - l <= Eps || left_low == comp(ln.eval(r), cur.eval(r))) {
      if (left_low) cur = ln;
      return p;
    }
    const T mid = (l + r) / 2;
    if (comp(ln.eval(mid), cur.eval(mid))) {
      if (left_low)
        p->__right = insert(p->__right, mid, r, cur);
      else
        p->__left = insert(p->__left, l, mid, cur);
      cur = ln;
    } else {
      if (left_low)
        p->__left = insert(p->__left, l, mid, ln);
      else
        p->__right = insert(p->__right, mid, r, ln);
    }
    return p;
  }

  node *insert(node *p, const T l, const T r, line const &seg, const T s,
               const T t) {
    if (s < l + Eps && r < t + Eps) return insert(p, l, r, seg);
    if (l < t && s < r) {
      if (!p) p = new node{};
      p->__left = insert(p->__left, l, (l + r) / 2, seg, s, t);
      p->__right = insert(p->__right, (l + r) / 2, r, seg, s, t);
    }
    return p;
  }
};

}  // namespace workspace
#line 35 "other/oupc/h.cc"

namespace workspace {

void solve() {}

void main() {
  // start here!

  constexpr i64 inf = 2e18;

  int n;
  cin >> n;
  vector<pair<i64, i64>> lns(n);
  for (auto i = 0; i < n; ++i) {
    i64 a, b;
    cin >> a >> b;
    lns[i] = {a, b};
  }
  int q;
  cin >> q;
  vector<i64> qs(q), ans(q, -inf);
  for (auto &&x : qs) {
    cin >> x;
  }
  int loops = 0;
  while (elapsed() < 1700) {
    ++loops;
    Li_Chao_tree<i64> mi(-1e12, 1e12 + 1);
    Li_Chao_tree<i64, greater<i64>, -inf> mx(-1e12, 1e12 + 1), mx2(mx);
    for (auto &&[s, t] : lns) {
      if (elapsed() % 2) {
        mi.insert(s, t);
        mx.insert(s, t);
      } else {
        mx2.insert(s, t);
      }
    }
    if (mx.empty() || mx2.empty()) continue;
    for (auto &&[z, x] : zip(ans, qs)) {
      chge(z, mx2.eval(mi.eval(x)));
      chge(z, mx2.eval(mx.eval(x)));
    }
  }
  for (auto &&e : ans) {
    cout << e << eol;
  }

  // cerr << "\t" << loops << endl;
}

}  // namespace workspace
accuracy: 0.019417475728155338
time_ms: 1700
memory_kb: 5740
final_rank: 15