title: Minimum Time Write Characters Using Insert Delete Copy Operation
signature: class Solution {
  
      public int MinimumTimeWriteCharactersUsingInsertDeleteCopyOperation(int n, int insrt, int remov, int cpy) {
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, int insrt, int remov, int cpy, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(n, insrt, remov, cpy); 
                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(
                  59, 75, 12, 45, 
                  351
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  66, 68, 32, 41, 
                  382
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  98, 55, 69, 5, 
                  195
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  63, 4, 41, 12, 
                  76
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  99, 37, 98, 55, 
                  460
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  45, 28, 59, 7, 
                  147
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  60, 53, 40, 52, 
                  405
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  11, 96, 50, 50, 
                  392
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  96, 95, 48, 84, 
                  694
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  54, 6, 50, 82, 
                  244
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 ];
  }