title: Temple Offerings
signature: function temple_offerings(n, templeheight)
source_py: def temple_offerings(n, templeHeight):
      sum = 0
      for i in range(n):
          left = 0
          right = 0
          for j in range((i - 1), (- 1), (- 1)):
              if (templeHeight[j] < templeHeight[(j + 1)]):
                  left += 1
              else:
                  break
          for j in range((i + 1), n):
              if (templeHeight[j] < templeHeight[(j - 1)]):
                  right += 1
              else:
                  break
          sum += (max(right, left) + 1)
      return sum
source_cpp: int temple_offerings(int n, vector<int> templeHeight) {
    int sum = 0;
    for ( int i = 0;
    i < n;
    ++ i ) {
      int left = 0, right = 0;
      for ( int j = i - 1;
      j >= 0;
      -- j ) {
        if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left;
        else break;
      }
      for ( int j = i + 1;
      j < n;
      ++ j ) {
        if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right;
        else break;
      }
      sum += max ( right, left ) + 1;
    }
    return sum;
  }
question_info.entry_fn_name: temple_offerings
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(n, templeheight, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(n, templeheight) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(12, {3, 11, 12, 15, 16, 21, 24, 29, 32, 39, 42, 44, 51, 68, 79, 81, 81, 85, 92, 94}, 78)
      print(string.format("TEST-0...%s",result))
  
      result = driver(46, {76, 48, 88, 70, -64, 66, -6, -58, 26, -28, -42, -94, 80, -4, -56, -46, 4, 90, -12, -78, 64, 18, -38, 26, 56, -24, 66, -18, -12, 0, -94, 12, -10, 4, -68, -20, 88, 2, -58, 16, 46, -80, -42, 44, -86, 96, -44}, 92)
      print(string.format("TEST-1...%s",result))
  
      result = driver(16, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17)
      print(string.format("TEST-2...%s",result))
  
      result = driver(9, {2, 95, 20, 50, 2, 58, 20, 14, 65, 69, 78, 7}, 15)
      print(string.format("TEST-3...%s",result))
  
      result = driver(0, {-88}, 0)
      print(string.format("TEST-4...%s",result))
  
      result = driver(38, {0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0}, 50)
      print(string.format("TEST-5...%s",result))
  
      result = driver(28, {2, 3, 6, 8, 9, 10, 14, 17, 17, 22, 25, 27, 29, 29, 30, 32, 33, 35, 38, 42, 50, 51, 51, 57, 59, 59, 59, 60, 62, 62, 63, 67, 70, 75, 76, 77, 81, 81, 83, 84}, 106)
      print(string.format("TEST-6...%s",result))
  
      result = driver(9, {-52, 62, 74, -62, -58, 62, 38, 42, -50, 20}, 16)
      print(string.format("TEST-7...%s",result))
  
      result = driver(18, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 19)
      print(string.format("TEST-8...%s",result))
  
      result = driver(29, {96, 15, 9, 9, 40, 34, 17, 4, 51, 49, 34, 66, 97, 28, 64, 65, 92, 56, 74, 48, 43, 17, 82, 8, 21, 39, 83, 35, 42, 37, 64, 34, 42, 59, 45, 61, 55, 93, 94, 29, 20, 96, 77, 66}, 64)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 78, "inputs": {"n": 12, "templeheight": [3, 11, 12, 15, 16, 21, 24, 29, 32, 39, 42, 44, 51, 68, 79, 81, 81, 85, 92, 94]}}, {"idx": 1, "outputs": 92, "inputs": {"n": 46, "templeheight": [76, 48, 88, 70, -64, 66, -6, -58, 26, -28, -42, -94, 80, -4, -56, -46, 4, 90, -12, -78, 64, 18, -38, 26, 56, -24, 66, -18, -12, 0, -94, 12, -10, 4, -68, -20, 88, 2, -58, 16, 46, -80, -42, 44, -86, 96, -44]}}, {"idx": 2, "outputs": 17, "inputs": {"n": 16, "templeheight": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}}, {"idx": 3, "outputs": 15, "inputs": {"n": 9, "templeheight": [2, 95, 20, 50, 2, 58, 20, 14, 65, 69, 78, 7]}}, {"idx": 4, "outputs": 0, "inputs": {"n": 0, "templeheight": [-88]}}, {"idx": 5, "outputs": 50, "inputs": {"n": 38, "templeheight": [0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]}}, {"idx": 6, "outputs": 106, "inputs": {"n": 28, "templeheight": [2, 3, 6, 8, 9, 10, 14, 17, 17, 22, 25, 27, 29, 29, 30, 32, 33, 35, 38, 42, 50, 51, 51, 57, 59, 59, 59, 60, 62, 62, 63, 67, 70, 75, 76, 77, 81, 81, 83, 84]}}, {"idx": 7, "outputs": 16, "inputs": {"n": 9, "templeheight": [-52, 62, 74, -62, -58, 62, 38, 42, -50, 20]}}, {"idx": 8, "outputs": 19, "inputs": {"n": 18, "templeheight": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}}, {"idx": 9, "outputs": 64, "inputs": {"n": 29, "templeheight": [96, 15, 9, 9, 40, 34, 17, 4, 51, 49, 34, 66, 97, 28, 64, 65, 92, 56, 74, 48, 43, 17, 82, 8, 21, 39, 83, 35, 42, 37, 64, 34, 42, 59, 45, 61, 55, 93, 94, 29, 20, 96, 77, 66]}}]