cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; cin >> m; blo = n / sqrt(m); for (int i = 1; i <= m; ++i) cin >> Q[i].l >> Q[i].r, Q[i].id = i; sort(Q + 1, Q + m + 1); int l = Q[1].l, r = l - 1; for (int i = 1; i <= m; ++i) { while (r < Q[i].r) add(a[++r]); while (l > Q[i].l) add(a[--l]); while (r > Q[i].r) del(a[r--]); while (l < Q[i].l) del(a[l++]); ans[Q[i].id] = Ans; } for (int i = 1; i <= m; ++i) cout << ans[i] << "\n"; return0; }