Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.

In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.

The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.

The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.

The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.

Output

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

Examples
input

Copy
3
2 3 2
2
3 2
2 3
output

Copy
2
input

Copy
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
output

Copy
1
Note

In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.

In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly twoscientists will be very pleased and all the others will be not satisfied.

排序加二分。

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m;
int pe[];
int au[],sub[];
int spe[],c = ;
int index,aun,subn;
int get(int x) {
int l = ,r = c - ;
while(l <= r) {
int mid = (l + r) / ;
if(pe[spe[mid]] < x) l = mid + ;
else if(pe[spe[mid]] > x) r = mid - ;
else return spe[mid + ] - spe[mid];
}
return ;
}
int main() {
scanf("%d",&n);
for(int i = ;i < n;i ++) {
scanf("%d",&pe[i]);
}
sort(pe,pe + n);
for(int i = ;i < n;i ++) {
if(pe[i] == pe[i - ]) continue;
spe[c ++] = i;
}
spe[c] = n;
scanf("%d",&m);
for(int i = ;i < m;i ++) {
scanf("%d",&au[i]);
}
for(int i = ;i < m;i ++) {
scanf("%d",&sub[i]);
}
for(int i = ;i < m;i ++) {
int a = get(au[i]),b = get(sub[i]);
if(aun < a) {
index = i;
aun = a;
subn = b;
}
else if(aun == a && subn < b) {
index = i;
subn = b;
}
}
printf("%d",index + );
}

Codeforces Round #350 (Div. 2) C. Cinema的更多相关文章

  1. Codeforces Round #350 (Div. 2) C. Cinema 水题

    C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...

  2. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  3. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  4. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  5. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)

    题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

  6. Codeforces Round #350 (Div. 2)A,B,C,D1

    A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  7. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  8. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  9. Codeforces Round #350 (Div. 2) B. Game of Robots 水题

    B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...

随机推荐

  1. 一般处理程序、Ajax多图片上传带进度条

    <!DOCTYPE html><html><head>    <meta charset="utf-8" />    <tit ...

  2. spring 中IOC实验(一)

    软件151  王帅 1.三个类,Human(人类)是接口,Chinese(中国人)是一个子类,American(美国人)是另外一个子类. 代码如下: package cn.com.chengang.s ...

  3. es6 - 一共有 6 种声明变量的方法(var, function, let, const, class, import)

    var命令和function命令声明的全局变量,依旧是顶层对象的属性:let命令.const命令.class命令声明的全局变量,不属于顶层对象的属性.也就是说,从 ES6 开始,全局变量将逐步与顶层对 ...

  4. 完全关闭及再次启动cdh集群

    关闭集群 - 关闭集群所有组件 关闭Cloudera Management Service 关闭cdh所有客户端节点 sudo /opt/cloudera-manager/cm-5.11.1/etc/ ...

  5. inner join on (程序测试验证结果。) _学习贴

    inner join on  两张表:机制就是第一张表的每一条数据,都会去和第二章表的每一条数据 依次进行匹配.匹配成功,就会显示出来. (程序测试验证结果.) 数据库连接 1 对 1 create ...

  6. org.apache.commons.vfs 配置文件里面 密码包含 @

    登录ftp的用户名 sftpuser ,密码 @sftpuser 在配置文件里面 需要 把 @ 转义 成 %40 ftppath=sftp://sftpuser:%40sftpuser@127.0.0 ...

  7. CG-ctf WP

    week one 1 /x00 提示:有多种解法,你能找到几种 源码: writer up: 题目直接给出了源码,get 到一个 nctf 这个变量,int ereg(string pattern, ...

  8. 收藏nginx学习

    http://blog.csdn.net/u012186351/article/details/50605672 http://blog.csdn.net/qq_25371579/article/de ...

  9. 泊爷带你学go -- redis连接池的操作

    package main import ( "common" "fmt" "proto" "strconv" " ...

  10. Docker入门教程

    一.入门介绍 Docker是一个开源引擎,类似于一个集装箱,开发者通过它可以为任何应用创建一个轻量级.环境无关可移植的容器.开发者在本地编译测试过的容器可以在不同的环境中部署. 通常适用于如下场景: ...