static long countWays ( int n , int k ) {
  long dp [ ] = new long [ n + 1 ] ;
  Arrays . fill ( dp , 0 ) ;
  int mod = 1000000007 ;
  dp [ 1 ] = k ;
  int same = 0 , diff = k ;
  for ( int i = 2 ;
  i <= n ;
  i ++ ) {
    same = diff ;
    diff = ( int ) ( dp [ i - 1 ] * ( k - 1 ) ) ;
    diff = diff % mod ;
    dp [ i ] = ( same + diff ) % mod ;
  }
  return dp [ n ] ;
}

static long countWays ( int n , int k ) { long dp [ ] = new long [ n + 1 ] ; Arrays . fill ( dp , 0 ) ; int mod = 1000000007 ; dp [ 1 ] = k ; int same = 0 , diff = k ; for ( int i = 2 ; i <= n ; i ++ ) { same = diff ; diff = ( int ) ( dp [ i - 1 ] * ( k - 1 ) ) ; diff = diff % mod ; dp [ i ] = ( same + diff ) % mod ; } return dp [ n ] ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (identifier))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))))) (return_statement (array_access array: (identifier) index: (identifier)))))