import java.io.*;
import java.util.*;
class GFG {
static void printAns(int x, int y, int num)
{
System.out.print("Indices in array " + num + " : ");
for (int i = x; i < y; ++i) {
System.out.print(i + ", ");
}
System.out.println(y);
}
static void findSubarray(int N, int a[], int b[], Boolean swap)
{
HashMap<Integer,ArrayList<Integer>> index = new HashMap<>();
int difference;
index.put(0 , new ArrayList<Integer>(Arrays.asList(-1, -1)));
int j = 0;
for (int i = 0; i < N; ++i) {
while (b[j] < a[i]) {
j++;
}
difference = b[j] - a[i];
if (index.containsKey(difference)) {
if (swap) {
ArrayList<Integer> idx = index.get(b[j] - a[i]);
printAns(idx.get(1) + 1, j, 1);
printAns(idx.get(0) + 1, i, 2);
}
else {
ArrayList<Integer> idx = index.get(b[j] - a[i]);
printAns(idx.get(0) + 1, i, 1);
printAns(idx.get(1) + 1, j, 2);
}
return;
}
ArrayList<Integer>arr = new ArrayList<>(Arrays.asList(i,j));
}
System.out.print("-1");
}
static void cumulativeSum(int arr[], int n)
{
for (int i = 1; i < n; ++i)
arr[i] += arr[i - 1];
}
public static void main(String args[])
{
int a[] = { 1, 2, 3, 4, 5 };
int b[] = { 6, 2, 1, 5, 4 };
int N = a.length;
cumulativeSum(a, N);
cumulativeSum(b, N);
if (b[N - 1] > a[N - 1]) {
findSubarray(N, a, b, false);
}
else {
findSubarray(N, b, a, true);
}
}
}