title: Program Find Smallest Difference Angles Two Parts Given Circle
signature: program_find_smallest_difference_angles_two_parts_given_circle <- 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(4L, 4L, 5L, 5L, 13L, 14L, 14L, 16L, 19L, 20L, 30L, 31L, 32L, 33L, 35L, 38L, 38L, 42L, 44L, 44L, 48L, 48L, 52L, 58L, 60L, 64L, 65L, 66L, 68L, 69L, 70L, 70L, 71L, 72L, 73L, 79L, 81L, 83L, 83L, 84L, 86L, 87L, 88L, 88L, 91L, 92L, 95L, 95L, 98L), 27L, 
          2L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-56L, 88L, -50L, 70L, 20L, 58L, 42L, -56L, -52L, -78L, 98L, 20L, -26L, 4L, 20L, -66L, -46L, -58L, 74L, 74L, -72L, 2L, 16L, -78L, -4L, 10L, 58L, 60L, -46L, -2L, 32L, -96L, 24L, -6L, 90L, -64L, -24L, -38L, 26L, 66L, -42L, -86L, 48L, 92L, 28L, 6L, -54L, -6L), 29L, 
          16L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(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), 25L, 
          340L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(52L, 67L, 62L), 1L, 
          256L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-56L, -22L, 32L, 42L, 66L), 4L, 
          360L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L), 10L, 
          354L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(38L, 46L, 58L, 72L), 2L, 
          192L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(16L, 62L, 90L, 40L, 30L, -56L, -92L, -56L, 60L, 42L, -64L, 92L, -30L, -70L, 42L, -48L, -54L, 54L, 48L, 94L, -44L, -46L, 10L, 48L, 22L, -24L, -62L, 34L, 60L, 24L, -60L, 50L, 40L, 34L), 20L, 
          24L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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), 37L, 
          340L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(86L, 43L, 74L, 84L, 86L, 14L, 45L, 7L, 92L, 36L, 79L, 13L, 67L, 18L, 96L, 77L, 13L, 22L, 28L, 36L, 57L, 56L, 99L, 57L, 8L, 48L, 5L, 79L, 65L, 64L, 96L, 6L, 36L, 91L, 53L, 55L, 11L, 12L, 80L, 99L, 50L, 40L, 4L, 9L, 52L, 41L), 40L, 
          0L
      )))
  
  }
  
  main()
source_py: def program_find_smallest_difference_angles_two_parts_given_circle(arr, n):
      l = 0
      _sum = 0
      ans = 360
      for i in range(n):
          _sum += arr[i]
          while (_sum >= 180):
              ans = min(ans, (2 * abs((180 - _sum))))
              _sum -= arr[l]
              l += 1
          ans = min(ans, (2 * abs((180 - _sum))))
      return ans
source_cpp: int program_find_smallest_difference_angles_two_parts_given_circle(vector<int> arr, int n) {
    int l = 0, sum = 0, ans = 360;
    for ( int i = 0;
    i < n;
    i ++ ) {
      sum += arr [ i ];
      while ( sum >= 180 ) {
        ans = min ( ans, 2 * abs ( 180 - sum ) );
        sum -= arr [ l ];
        l ++;
      }
      ans = min ( ans, 2 * abs ( 180 - sum ) );
    }
    return ans;
  }