title: Minimum Time Write Characters Using Insert Delete Copy Operation
signature: int minimumTimeWriteCharactersUsingInsertDeleteCopyOperation(int n, int insrt, int remov, int cpy) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(int n, int insrt, int remov, int cpy, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(n, insrt, remov, cpy), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver(59, 75, 12, 45, 351); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver(66, 68, 32, 41, 382); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver(98, 55, 69, 5, 195); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver(63, 4, 41, 12, 76); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver(99, 37, 98, 55, 460); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver(45, 28, 59, 7, 147); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver(60, 53, 40, 52, 405); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver(11, 96, 50, 50, 392); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver(96, 95, 48, 84, 694); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver(54, 6, 50, 82, 244); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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 ];
  }