title: Temple Offerings
signature: class Solution {
  
      public int TempleOfferings(int n, List<int> templeheight) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(int n, List<int> templeheight, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(n, templeheight); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  12, new List<int>{3, 11, 12, 15, 16, 21, 24, 29, 32, 39, 42, 44, 51, 68, 79, 81, 81, 85, 92, 94}, 
                  78
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  46, new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  16, new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  9, new List<int>{2, 95, 20, 50, 2, 58, 20, 14, 65, 69, 78, 7}, 
                  15
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  0, new List<int>{-88}, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  38, new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  28, new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  9, new List<int>{-52, 62, 74, -62, -58, 62, 38, 42, -50, 20}, 
                  16
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  18, new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
                  19
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  29, new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }