title: Find Maximum Sum Possible Equal Sum Three Stacks
signature: func findMaximumSumPossibleEqualSumThreeStacks(stack1 []int, stack2 []int, stack3 []int, n1 int, n2 int, n3 int) int {
source_py: def find_maximum_sum_possible_equal_sum_three_stacks(stack1, stack2, stack3, n1, n2, n3):
      (sum1, sum2, sum3) = (0, 0, 0)
      for i in range(n1):
          sum1 += stack1[i]
      for i in range(n2):
          sum2 += stack2[i]
      for i in range(n3):
          sum3 += stack3[i]
      (top1, top2, top3) = (0, 0, 0)
      ans = 0
      while 1:
          if ((top1 == n1) or (top2 == n2) or (top3 == n3)):
              return 0
          if ((sum1 == sum2) and (sum2 == sum3)):
              return sum1
          if ((sum1 >= sum2) and (sum1 >= sum3)):
              sum1 -= stack1[top1]
              top1 = (top1 + 1)
          elif ((sum2 >= sum3) and (sum2 >= sum3)):
              sum2 -= stack2[top2]
              top2 = (top2 + 1)
          elif ((sum3 >= sum2) and (sum3 >= sum1)):
              sum3 -= stack3[top3]
              top3 = (top3 + 1)
source_cpp: int find_maximum_sum_possible_equal_sum_three_stacks(vector<int> stack1, vector<int> stack2, vector<int> stack3, int n1, int n2, int n3) {
    int sum1 = 0, sum2 = 0, sum3 = 0;
    for ( int i = 0;
    i < n1;
    i ++ ) sum1 += stack1 [ i ];
    for ( int i = 0;
    i < n2;
    i ++ ) sum2 += stack2 [ i ];
    for ( int i = 0;
    i < n3;
    i ++ ) sum3 += stack3 [ i ];
    int top1 = 0, top2 = 0, top3 = 0;
    int ans = 0;
    while ( 1 ) {
      if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0;
      if ( sum1 == sum2 && sum2 == sum3 ) return sum1;
      if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ];
      else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ];
      else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ];
    }
  }