class Result {
public static int equalStacks(List<Integer> h1, List<Integer> h2, List<Integer> h3) {
int sum1 = h1.stream().mapToInt(Integer::intValue).sum();
int sum2 = h2.stream().mapToInt(Integer::intValue).sum();
int sum3 = h3.stream().mapToInt(Integer::intValue).sum();
int i1 = 0, i2 = 0, i3 = 0;
while (true) {
if (sum1 == sum2 && sum2 == sum3) return sum1;
if (sum1 >= sum2 && sum1 >= sum3) {
sum1 -= h1.get(i1++);
} else if (sum2 >= sum1 && sum2 >= sum3) {
sum2 -= h2.get(i2++);
} else {
sum3 -= h3.get(i3++);
}
}
}
}