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. thinkphp5和thinkphp3.2.3中URL重写出现No input file specified

    查询后解决办法是打开public目录下的.htaccess文件,把:RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 改为:RewriteRule ^(.*)$ i ...

  2. shell脚本实现git和svn统计log代码行

    实现的功能 git 根据传入的三个参数:起始统计日期.结束统计日期.git仓库地址. 脚本统计的是git仓库内的所有分支的log信息. 脚本统计的是指定时间段内.每一个提交人指定的git地址的所有分支 ...

  3. 关于STL的map的注意事项

    关于map是什么,这里就不多叙述了. 直接正题,常用的map插入操作有三种方法:通过pair<key_type,value_type>.通过value_type插入数据.还有一种类似于数组 ...

  4. 201671010142 2017-2 《java第十二十三章学习感悟》

    Swing编程第一步,需要导入Swing相关包,即javax.swing.*. 接下里需要设置界面外观风格,使用到UIManager类. 设置完外观之后一定要调用 SwingUtilities.upd ...

  5. C# Vs2017启动调试,debug或者release调试状态闪一下程序就独立运行了

    最近发现一个没太大影响但是很奇怪的事情,编辑状态下点击调试,发现和之前的项目不一样,调试状态闪一下,程序就“独立了”,不受调试状态的控制了. 找了半天才发现,是在program.cs里加了一段代码引起 ...

  6. 为期一周的C#学习状态与感受

    我,女,28,有娃两岁.博客开张,发发牢骚,进入第二阶段. 我这个年龄我这个状态,我决定重拾以前放弃的行业,打听了很多相关工作的朋友和查阅了很多关于这个问题的网页,有两种声音在交奏,一边是去吧,趁现在 ...

  7. 初学者--oracle安装完后出现的一些问题

    对于初学者安装数据库后,立马回运行数据库,看是否安装成功,但oracle安装完成,其中有些都是默认状态,所以需要手动修改和添加.例如这个问题 1.pl/sql developer was not te ...

  8. jmeter测试计划元素执行顺序

    jmeter测试计划元素执行顺序 测试计划的元素是有序的,通过以下方式执行: 1–配置节点 2–前置处理器 3–定时器 4–取样器 5–后置处理器(只在有结果可用情况下执行) 6–断言(只在有结果可用 ...

  9. 开始 第一个自己的python爬虫程序 爬磁力链

    不能一事无成,这么久了学python还是吊着,要落地,落在博客园好了,好像公司也只能上博客园了 昨天看了一篇用正则爬电影天堂的视频,直接拿来用,爬磁力吧,爬好玩的 #导入模块 import reque ...

  10. 洛谷P1091 合唱队形

    输入输出样例 输入样例#1: 8 186 186 150 200 160 130 197 220 输出样例#1: 4 此题意在先升后降子序列,单调递增子序列,单调递减子序列当中找到最长的一组序列. 因 ...