title: Temple Offerings
signature: temple_offerings <- function(n, templeheight) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, templeheight, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n, templeheight), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          12L, list(3L, 11L, 12L, 15L, 16L, 21L, 24L, 29L, 32L, 39L, 42L, 44L, 51L, 68L, 79L, 81L, 81L, 85L, 92L, 94L), 
          78L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          46L, list(76L, 48L, 88L, 70L, -64L, 66L, -6L, -58L, 26L, -28L, -42L, -94L, 80L, -4L, -56L, -46L, 4L, 90L, -12L, -78L, 64L, 18L, -38L, 26L, 56L, -24L, 66L, -18L, -12L, 0L, -94L, 12L, -10L, 4L, -68L, -20L, 88L, 2L, -58L, 16L, 46L, -80L, -42L, 44L, -86L, 96L, -44L), 
          92L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          16L, list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 
          17L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          9L, list(2L, 95L, 20L, 50L, 2L, 58L, 20L, 14L, 65L, 69L, 78L, 7L), 
          15L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          0L, list(-88L), 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          38L, list(0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L), 
          50L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          28L, list(2L, 3L, 6L, 8L, 9L, 10L, 14L, 17L, 17L, 22L, 25L, 27L, 29L, 29L, 30L, 32L, 33L, 35L, 38L, 42L, 50L, 51L, 51L, 57L, 59L, 59L, 59L, 60L, 62L, 62L, 63L, 67L, 70L, 75L, 76L, 77L, 81L, 81L, 83L, 84L), 
          106L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          9L, list(-52L, 62L, 74L, -62L, -58L, 62L, 38L, 42L, -50L, 20L), 
          16L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          18L, list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 
          19L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          29L, list(96L, 15L, 9L, 9L, 40L, 34L, 17L, 4L, 51L, 49L, 34L, 66L, 97L, 28L, 64L, 65L, 92L, 56L, 74L, 48L, 43L, 17L, 82L, 8L, 21L, 39L, 83L, 35L, 42L, 37L, 64L, 34L, 42L, 59L, 45L, 61L, 55L, 93L, 94L, 29L, 20L, 96L, 77L, 66L), 
          64L
      )))
  
  }
  
  main()
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;
  }