title: Painting Fence Algorithm
signature: painting_fence_algorithm <- function(n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          6L, 30L, 
          725841870L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          23L, 87L, 
          370622679L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          89L, 31L, 
          7554776L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          63L, 36L, 
          76740139L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          23L, 68L, 
          647498520L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          44L, 66L, 
          70208793L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          81L, 18L, 
          227130467L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          43L, 73L, 
          204618786L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          9L, 42L, 
          797370673L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          41L, 98L, 
          903959704L
      )))
  
  }
  
  main()
source_py: def painting_fence_algorithm(n, k):
      total = k
      mod = 1000000007
      (same, diff) = (0, k)
      for i in range(2, (n + 1)):
          same = diff
          diff = (total * (k - 1))
          diff = (diff % mod)
          total = ((same + diff) % mod)
      return total
source_cpp: long painting_fence_algorithm(int n, int k) {
    long total = k;
    int mod = 1000000007;
    int same = 0, diff = k;
    for ( int i = 2;
    i <= n;
    i ++ ) {
      same = diff;
      diff = total * ( k - 1 );
      diff = diff % mod;
      total = ( same + diff ) % mod;
    }
    return total;
  }