title: Maximum Sum Iarri Among Rotations Given Array
signature: maximum_sum_iarri_among_rotations_given_array <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(11L, 12L, 16L, 26L, 29L, 40L, 54L, 59L, 65L, 70L, 71L, 73L, 78L, 81L, 87L, 87L, 88L, 90L, 95L, 97L), 11L, 
          3035L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-46L, -32L, 54L, 96L, -72L, -58L, -36L, -44L, 26L, -2L, -68L, 42L, 90L, 26L, -92L, -96L, 88L, -42L, -18L, 46L, -70L, 24L, 0L, 24L, 34L, 34L, -52L, 50L, 94L, -60L, 64L, 58L), 22L, 
          592L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 33L, 
          392L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(48L, 2L, 79L, 98L, 28L, 17L, 41L, 47L, 61L, 76L, 82L, 5L, 74L, 4L, 80L, 51L, 22L, 45L, 91L, 75L, 91L, 93L, 42L, 45L, 69L, 98L, 76L, 74L, 83L, 17L, 30L, 88L, 53L, 25L, 35L, 19L, 26L), 20L, 
          10714L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-88L, -84L, -82L, -74L, -44L, -34L, -32L, -20L, -20L, -14L, 6L, 6L, 10L, 12L, 16L, 24L, 32L, 34L, 38L, 46L, 54L, 54L, 56L, 60L, 82L, 88L, 90L, 94L, 98L), 24L, 
          7026L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 7L, 
          19L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(10L, 14L, 14L, 14L, 19L, 20L, 22L, 26L, 35L, 36L, 40L, 53L, 54L, 55L, 55L, 57L, 57L, 67L, 72L, 72L, 77L, 78L, 83L, 84L, 95L, 96L), 16L, 
          5149L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-80L, 18L, -76L, 48L, -52L, -38L, 52L, -82L, 40L, -44L, -90L, 86L, -86L, -36L, -32L, -2L, 56L, -12L, -88L, 14L, -16L, 8L, 52L, 24L, 46L, 56L, 84L, -36L, 84L, -60L, 72L, -46L, 32L, -16L, -20L, 68L, -86L, -62L, 58L, 8L, 78L, -52L, 22L, -28L, -22L, -42L, 12L, -48L), 30L, 
          4226L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 14L, 
          46L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(20L, 94L, 36L, 2L, 50L, 62L, 84L, 50L, 66L, 75L, 1L, 18L, 41L, 48L, 72L, 61L, 86L, 22L, 54L, 6L, 71L, 46L, 92L, 68L, 59L, 51L, 89L, 31L, 58L, 78L, 82L, 84L), 25L, 
          16847L
      )))
  
  }
  
  main()
source_py: def maximum_sum_iarri_among_rotations_given_array(arr, n):
      res = (- sys.maxsize)
      for i in range(0, n):
          curr_sum = 0
          for j in range(0, n):
              index = int(((i + j) % n))
              curr_sum += (j * arr[index])
          res = max(res, curr_sum)
      return res
source_cpp: int maximum_sum_iarri_among_rotations_given_array(vector<int> arr, int n) {
    int res = INT_MIN;
    for ( int i = 0;
    i < n;
    i ++ ) {
      int curr_sum = 0;
      for ( int j = 0;
      j < n;
      j ++ ) {
        int index = ( i + j ) % n;
        curr_sum += j * arr [ index ];
      }
      res = max ( res, curr_sum );
    }
    return res;
  }