#include <iostream>
using namespace std;
const int MAX_SIZE = 1000000;
int main() {
int n, arr[MAX_SIZE + 1];
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> arr[i];
}
int m;
cin >> m;
int x;
int positions[m];
for (int j = 0; j < m; ++j) {
cin >> x;
int left = 1, right = n, lastPosition = -1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == x) {
lastPosition = mid;
left = mid + 1;
} else if (arr[mid] < x) {
left = mid + 1;
} else {
right = mid - 1;
}
}
positions[j] = lastPosition;
}
for (int j = 0; j < m; ++j) {
cout << positions[j] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gMTAwMDAwMDsKCmludCBtYWluKCkgewogICAgaW50IG4sIGFycltNQVhfU0laRSArIDFdOwogICAgY2luID4+IG47CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKICAgICAgICBjaW4gPj4gYXJyW2ldOwogICAgfQogICAgaW50IG07CiAgICBjaW4gPj4gbTsKICAgIGludCB4OwogICAgaW50IHBvc2l0aW9uc1ttXTsKICAgIGZvciAoaW50IGogPSAwOyBqIDwgbTsgKytqKSB7IAogICAgICAgIGNpbiA+PiB4OwogICAgICAgIGludCBsZWZ0ID0gMSwgcmlnaHQgPSBuLCBsYXN0UG9zaXRpb24gPSAtMTsKICAgICAgICB3aGlsZSAobGVmdCA8PSByaWdodCkgewogICAgICAgICAgICBpbnQgbWlkID0gbGVmdCArIChyaWdodCAtIGxlZnQpIC8gMjsKICAgICAgICAgICAgaWYgKGFyclttaWRdID09IHgpIHsKICAgICAgICAgICAgICAgIGxhc3RQb3NpdGlvbiA9IG1pZDsgCiAgICAgICAgICAgICAgICBsZWZ0ID0gbWlkICsgMTsgCiAgICAgICAgICAgIH0gZWxzZSBpZiAoYXJyW21pZF0gPCB4KSB7CiAgICAgICAgICAgICAgICBsZWZ0ID0gbWlkICsgMTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJpZ2h0ID0gbWlkIC0gMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBwb3NpdGlvbnNbal0gPSBsYXN0UG9zaXRpb247ICAKICAgIH0KICAgIGZvciAoaW50IGogPSAwOyBqIDwgbTsgKytqKSB7CiAgICAgICAgY291dCA8PCBwb3NpdGlvbnNbal0gPDwgIiAiOwogICAgfQogICAgcmV0dXJuIDA7Cn0=