#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
struct frac {
int n, d;
frac(int n_, int d_) : n(n_), d(d_) {
int g = __gcd(n, d);
n /= g, d /= g;
if (d < 0) {
n = -n, d = -d;
}
}
frac(int n_) : frac(n_, 1) {}
frac() : frac(0) {}
friend std::ostream& operator << (std::ostream& o, const frac& f) {
return o << f.n << '/' << f.d;
}
friend bool operator < (const frac& a, const frac& b) { return i64(a.n) * b.d < i64(a.d) * b.n; }
friend bool operator == (const frac& a, const frac& b) { return a.n == b.n && a.d == b.d; }
friend bool operator != (const frac& a, const frac& b) { return !(a == b); }
};
using line_t = pair<int, int>;
const int INF = 1e9;
const int MAXN = 2.1e5;
int N;
line_t L[MAXN];
int Q[MAXN];
frac ans[MAXN];
frac lastBetter(const line_t& a, const line_t& b) {
assert(a.second < b.second);
assert(a.first != b.first);
if (a.first < b.first) {
return INF;
} else {
return frac(b.second - a.second, a.first - b.first);
}
}
deque<pair<line_t, frac>> dq;
void add(const line_t& l) {
while (!dq.empty()) {
frac f = lastBetter(l, dq.front().first);
if (!(f < dq.front().second)) {
dq.pop_front();
} else {
break;
}
}
if (dq.empty()) {
dq.emplace_front(l, INF);
} else {
dq.emplace_front(l, lastBetter(l, dq.front().first));
}
}
frac query(const line_t& l) {
if (l.first <= dq.back().first.first) return -1;
int mi = -1, ma = int(dq.size())-1;
while (ma - mi > 1) {
int md = (mi + ma) / 2;
if (!(dq[md].second < lastBetter(l, dq[md].first))) {
ma = md;
} else {
mi = md;
}
}
return lastBetter(l, dq[ma].first);
}
void go() {
vector<int> lines(N); iota(lines.begin(), lines.end(), 0);
sort(lines.begin(), lines.end(), [&](int i, int j) { return L[i].second > L[j].second; });
dq = {};
for (int i : lines) {
add(L[i]);
if (L[i].second > L[Q[i]].second) {
ans[i] = query(L[Q[i]]);
}
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
L[i].first = -(i+1);
cin >> L[i].second;
}
for (int i = 0; i < N; i++) {
cin >> Q[i]; Q[i]--;
assert(i != Q[i]);
}
go();
for (int i = 0; i < N; i++) {
L[i].first *= -1;
L[i].second *= -1;
}
go();
for (int i = 0; i < N; i++) {
if (ans[i] == -1) {
cout << -1 << '\n';
} else {
cout << ans[i] << '\n';
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp1c2luZyBpNjQgPSBpbnQ2NF90OwoKc3RydWN0IGZyYWMgewoJaW50IG4sIGQ7CglmcmFjKGludCBuXywgaW50IGRfKSA6IG4obl8pLCBkKGRfKSB7CgkJaW50IGcgPSBfX2djZChuLCBkKTsKCQluIC89IGcsIGQgLz0gZzsKCQlpZiAoZCA8IDApIHsKCQkJbiA9IC1uLCBkID0gLWQ7CgkJfQoJfQoJZnJhYyhpbnQgbl8pIDogZnJhYyhuXywgMSkge30KCWZyYWMoKSA6IGZyYWMoMCkge30KCglmcmllbmQgc3RkOjpvc3RyZWFtJiBvcGVyYXRvciA8PCAoc3RkOjpvc3RyZWFtJiBvLCBjb25zdCBmcmFjJiBmKSB7CgkJcmV0dXJuIG8gPDwgZi5uIDw8ICcvJyA8PCBmLmQ7Cgl9CgoJZnJpZW5kIGJvb2wgb3BlcmF0b3IgPCAoY29uc3QgZnJhYyYgYSwgY29uc3QgZnJhYyYgYikgeyByZXR1cm4gaTY0KGEubikgKiBiLmQgPCBpNjQoYS5kKSAqIGIubjsgfQoJZnJpZW5kIGJvb2wgb3BlcmF0b3IgPT0gKGNvbnN0IGZyYWMmIGEsIGNvbnN0IGZyYWMmIGIpIHsgcmV0dXJuIGEubiA9PSBiLm4gJiYgYS5kID09IGIuZDsgfQoJZnJpZW5kIGJvb2wgb3BlcmF0b3IgIT0gKGNvbnN0IGZyYWMmIGEsIGNvbnN0IGZyYWMmIGIpIHsgcmV0dXJuICEoYSA9PSBiKTsgfQp9OwoKdXNpbmcgbGluZV90ID0gcGFpcjxpbnQsIGlud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