title: Painting Fence Algorithm
signature: paintingFenceAlgorithm :: Integer -> Integer -> Integer
  paintingFenceAlgorithm n k = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Integer -> Integer -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: Integer -> Integer -> Integer -> String
  driver n k expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME n k) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver (6) (30) (725841870) )
  
      printf "TEST-1...%s\n" (driver (23) (87) (370622679) )
  
      printf "TEST-2...%s\n" (driver (89) (31) (7554776) )
  
      printf "TEST-3...%s\n" (driver (63) (36) (76740139) )
  
      printf "TEST-4...%s\n" (driver (23) (68) (647498520) )
  
      printf "TEST-5...%s\n" (driver (44) (66) (70208793) )
  
      printf "TEST-6...%s\n" (driver (81) (18) (227130467) )
  
      printf "TEST-7...%s\n" (driver (43) (73) (204618786) )
  
      printf "TEST-8...%s\n" (driver (9) (42) (797370673) )
  
      printf "TEST-9...%s\n" (driver (41) (98) (903959704) )
  
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;
  }