시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.4 초 1024 MB148524335.537%

문제

You are given two positive integers n, m and two sequences of positive integers A and B. The sequence A consists of n elements, each one in the interval [1, m], while the sequence B consists of m elements, each one in the interval [1, n].

Write a program, which finds a nonempty subsequence of A and a nonempty subsequence of B, which have equal sums of elements.

Definition: For a sequence C = C0, C1, …, Cp, a subsequence of C is a sequence of elements Ci1, Ci2, …, Cik of C for which 0 ≤ i1 < i2 < ...< ik ≤ p.

입력

From the first line of the standard input, your program reads a positive integer n – the size of sequence A. From the second line, your program reads n positive integers – the elements of A. From the third line of the standard input, your program reads a positive integer m – the size of sequence B. From the fourth line, your program reads m positive integers – the elements of B.

출력

On the first line of the standard output, your program should print a positive integer p – the size of the chosen subsequence of A. On the second line, your program should print p integers – the indices of the chosen elements from A. On the third line of the standard output, your program should print a positive integer q – the size of the chosen subsequence of B. On the fourth line, your program should print q integers – the indices of the chosen elements from B.

Attention: Indices start from 0. The order in which your program prints the chosen indices doesn’t matter. It is guaranteed that at least one solution exists. If more than one solution exists, print any one of them.

제한

  • 1 ≤ n, m ≤ 1 000 000

서브태스크

번호배점제한
110

n, m ≤ 20

225

n, m ≤ 300

365

No additional constraints.

예제 입력 1

5
2 3 3 2 3
3
4 5 5

예제 출력 1

3
1 2 4
2
0 1

힌트

a[1] + a[2] + a[4] = 3 + 3 + 3 = 9

b[0] + b[1] = 4 + 5 = 9.

Another possible solution is: a[2] +a[3] = 3 + 2 = 5 = b[1].

채점 및 기타 정보

  • 예제는 채점하지 않는다.