title: Minimum Time Write Characters Using Insert Delete Copy Operation
signature: function minimum_time_write_characters_using_insert_delete_copy_operation(n, insrt, remov, cpy)
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, insrt, remov, cpy, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(n, insrt, remov, cpy) 
      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(59, 75, 12, 45, 351)
      print(string.format("TEST-0...%s",result))
  
      result = driver(66, 68, 32, 41, 382)
      print(string.format("TEST-1...%s",result))
  
      result = driver(98, 55, 69, 5, 195)
      print(string.format("TEST-2...%s",result))
  
      result = driver(63, 4, 41, 12, 76)
      print(string.format("TEST-3...%s",result))
  
      result = driver(99, 37, 98, 55, 460)
      print(string.format("TEST-4...%s",result))
  
      result = driver(45, 28, 59, 7, 147)
      print(string.format("TEST-5...%s",result))
  
      result = driver(60, 53, 40, 52, 405)
      print(string.format("TEST-6...%s",result))
  
      result = driver(11, 96, 50, 50, 392)
      print(string.format("TEST-7...%s",result))
  
      result = driver(96, 95, 48, 84, 694)
      print(string.format("TEST-8...%s",result))
  
      result = driver(54, 6, 50, 82, 244)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
source_py: def minimum_time_write_characters_using_insert_delete_copy_operation(N, insrt, remov, cpy):
      if (N == 0):
          return 0
      if (N == 1):
          return insrt
      dp = ([0] * (N + 1))
      for i in range(1, (N + 1)):
          if ((i % 2) == 0):
              dp[i] = min((dp[(i - 1)] + insrt), (dp[(i // 2)] + cpy))
          else:
              dp[i] = min((dp[(i - 1)] + insrt), ((dp[((i + 1) // 2)] + cpy) + remov))
      return dp[N]
source_cpp: int minimum_time_write_characters_using_insert_delete_copy_operation(int N, int insert, int remove, int copy) {
    if ( N == 0 ) return 0;
    if ( N == 1 ) return insert;
    int dp [ N + 1 ];
    memset ( dp, 0, sizeof ( dp ) );
    for ( int i = 1;
    i <= N;
    i ++ ) {
      if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ i / 2 ] + copy );
      else dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ ( i + 1 ) / 2 ] + copy + remove );
    }
    return dp [ N ];
  }