Problem:
Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters.
We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.

Constraints

1 \leq w \leq |S| \leq 1000

S consists of lowercase English letters.

w is an integer.

Input

Input is given from Standard Input in the following format:

S
w

Output

Print the desired string in one line.

Sample Input 1

abcdefgh
3

Sample Output 1

adg

When we write down abcdefgh, starting a new line after every three letters, we get the following:

abc

def

gh

Concatenating the letters at the beginnings of these lines, we obtain adg.

Sample Input 2

lllll
1

Sample Output 2

lllll

Sample Input 3

souuundhound
2

Sample Output 3

suudon

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

use std::io;

// Avoids to use unstable feature iter_unfold
fn unfold<In, Out, F>(seed: &In, f: F) -> Vec<Out>
where F: FnMut(&In) -> Option<(Out, In)> {
    fn go<In, Out, F>(seed: &In, mut f: F, acc: &mut Vec<Out>)
    where F: FnMut(&In) -> Option<(Out, In)> {
        match f(seed) {
            Some((out, next)) => {
                acc.push(out);
                go(&next, f, acc);
            }
            None => ()
        }
    }

    let mut result = Vec::new();
    go(seed, f, &mut result);
    result
}

// Avoids to use experimental trait std::slice::SliceConcatExt
// A more general signature of this function seems to be:
//   fn concat<'a, Seq>(ss: Seq) -> String where Seq: Iterator<Item = &'a str>
// but I don't know how to pass the compilation.
fn concat<Seq>(ss: Seq) -> String where Seq: Iterator<Item = String> {
    let mut result = String::new();
    for s in ss {
        result = result + &s;
    }
    result
}

fn split_at_safe(s: &str, at: usize) -> (&str, &str) {
    if s.len() <= at { (s, "") } else { s.split_at(at) }
}

fn main() {
    let mut line1 = String::new();
    io::stdin()
        .read_line(&mut line1)
        .unwrap();
    let s = line1.trim();

    let mut line2 = String::new();
    io::stdin()
        .read_line(&mut line2)
        .unwrap();
    let w = line2.trim().parse::<usize>().unwrap();

    let fragments = unfold(&s, |s| {
        if s.is_empty() { None } else { Some(split_at_safe(s, w)) }
    });
    println!("{}", concat(
        fragments.iter()
            .map(|&s| { s.chars().nth(0).unwrap().to_string() })
    ));
}