Problem:
Score : 200 points

Problem Statement

There are N balls placed in a row.
AtCoDeer the deer is painting each of these in one of the K colors of his paint cans.
For aesthetic reasons, any two adjacent balls must be painted in different colors.

Find the number of the possible ways to paint the balls.

Constraints

1≦N≦1000

2≦K≦1000

The correct answer is at most 2^{31}-1.

Input

The input is given from Standard Input in the following format:

N K

Output

Print the number of the possible ways to paint the balls.

Sample Input 1

2 2

Sample Output 1

2

We will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.

Sample Input 2

1 10

Sample Output 2

10

Since there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.

Solution in Rust (1.15.1) (judge verdict: Accepted)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    println!("{}", k * (k - 1).pow(n as u32 - 1))
}

// fn main() {
//     input! {
//         h: usize,
//         w: usize,
//         s: [chars; h]
//     }
//     let xy = [
//         // [-1i32, 1i32],
//         [0i32, 1i32],
//         // [1i32, 1i32],
//         [-1i32, 0i32],
//         [1i32, 0i32],
//         // [-1i32, -1i32],
//         [0i32, -1i32],
//         // [1i32, -1i32],
//     ];
//     let mut s = s;
//     for y in 0..h {
//         for x in 0..w {
//             if s[y][x] == '.' {
//                 continue;
//             }
//             let mut b = false;
//             for i in 0..4 {
//                 let xx = x as i32 + xy[i][0] as i32;
//                 let yy = y as i32 + xy[i][1] as i32;
//                 if xx < 0 || w as i32 <= xx {
//                     continue;
//                 }
//                 if yy < 0 || h as i32 <= yy {
//                     continue;
//                 }
//                 if s[yy as usize][xx as usize] == '#' {
//                     b = true;
//                 }
//             }
//             if !b {
//                 println!("No");
//                 return;
//             }
//         }
//     }
//     println!("Yes")
// }