It's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood.  The neighborhood consists of n houses in a straight line, labelled 1 to n from left to right, all an equal distance apart.Everyone in this neighborhood loves peace and quiet. Because of this, whenever a new person moves into the neighborhood, he or she always chooses the house whose minimum distance to any occupied house is maximized. If there are multiple houses with the maximum possible minimum distance, he or she chooses the leftmost one.Note that the first person to arrive always moves into house 1.Karen is the k-th person to enter this neighborhood. If everyone, including herself, follows this rule, which house will she move into?

The first and only line of input contains two integers, n and k (1 ≤ k ≤ n ≤ 1018), describing the number of houses in the neighborhood, and that Karen was the k-th person to move in, respectively.

Output a single integer on a line by itself, the label of the house Karen will move into.

NoteIn the first test case, there are 6 houses in the neighborhood, and Karen is the fourth person to move in:  The first person moves into house 1.  The second person moves into house 6.  The third person moves into house 3.  The fourth person moves into house 2. In the second test case, there are 39 houses in the neighborhood, and Karen is the third person to move in:  The first person moves into house 1.  The second person moves into house 39.  The third person moves into house 20.

//! http://codeforces.com/contest/815/problem/E

#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(isize);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

#[inline]
fn house_dist(segment: i64) -> i64 {
  (segment + 1) / 2
}

/// Check whether the k'th placed house has a position <= limit.
fn is_before(n: i64, k: i64, limit: i64) -> bool {
  use std::collections::BTreeMap;
  let mut l_segs = BTreeMap::new();
  let mut r_segs = BTreeMap::new();
  let mut cross = Some((2, n - 1));
  let mut rem = k;

  l_segs.insert(0i64, 0i64);
  r_segs.insert(0i64, 0i64);

  while rem > 0 {
    let (&l_max, &l_cnt) = l_segs.iter().rev()
      .next()
      .unwrap();
    let (&r_max, &r_cnt) = r_segs.iter().rev()
      .next()
      .unwrap();

    let mut max_seg = match cross {
      Some((lo, hi)) => hi - lo + 1,
      None => i64::min_value()
    };
    max_seg = std::cmp::max(max_seg, l_max);
    max_seg = std::cmp::max(max_seg, r_max);

    if house_dist(max_seg) == house_dist(l_max) {
      if l_cnt >= rem { return true; }
      rem -= l_cnt;
      l_segs.remove(&l_max);
      *l_segs.entry((l_max - 1) / 2).or_insert(0) += l_cnt;
      *l_segs.entry(l_max / 2).or_insert(0) += l_cnt;
    } else if match cross {
        None => false,
        Some((lo, hi)) => house_dist(max_seg) == house_dist(hi - lo + 1)
      }
    {
      let (lo, hi) = cross.unwrap();
      let mid = (lo + hi) / 2;
      if rem == 1 { return mid <= limit; }
      rem -= 1;

      let (lr, rl) = (mid - 1, mid + 1);

      if limit < lr {
        cross = Some((lo, lr));
        *r_segs.entry(hi - rl + 1).or_insert(0) += 1;
      } else if limit >= rl {
        cross = Some((rl, hi));
        *l_segs.entry(lr - lo + 1).or_insert(0) += 1;
      } else {
        cross = None;
        *r_segs.entry(hi - rl + 1).or_insert(0) += 1;
        *l_segs.entry(lr - lo + 1).or_insert(0) += 1;
      }
    } else if house_dist(max_seg) == house_dist(r_max) {
      if r_cnt >= rem { return false; }
      rem -= r_cnt;
      r_segs.remove(&r_max);
      *r_segs.entry((r_max - 1) / 2).or_insert(0) += r_cnt;
      *r_segs.entry(r_max / 2).or_insert(0) += r_cnt;
    }
  }

  unreachable!()
}

fn main() {
  use std::io::{self, Write, BufWriter};
  let __stdout = io::stdout();
  let mut __out = BufWriter::with_capacity(4096, __stdout.lock());

  macro_rules! put {
    ($fmt:expr) => { write!(__out, $fmt).unwrap(); };
    ($fmt:expr, $($arg:expr),+) => { write!(__out, $fmt, $($arg),+).unwrap(); }
  }
  macro_rules! putln {
    () => { writeln!(__out, "").unwrap(); };
    ($fmt:expr) => { writeln!(__out, $fmt).unwrap(); };
    ($fmt:expr, $($arg:expr),+) => { writeln!(__out, $fmt, $($arg),+).unwrap(); }
  }
  macro_rules! fflush {
    () => { __out.flush().unwrap(); }
  }

  scanln!(n: i64, k: i64);

  if k == 1 { putln!("1"); }
  else if k == 2 { putln!("{}", n); }
  else {
    let (mut lo, mut hi) = (2, n - 1);
    let mut ans = hi;
    while lo <= hi {
      let mid = (lo + hi) / 2;
      if is_before(n, k - 2, mid) {
        ans = mid;
        hi = mid - 1;
      } else {
        lo = mid + 1;
      }
    }
    putln!("{}", ans);
  }
}


Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.He came up with the following game. The player has a positive integer $$$n$$$. Initially the value of $$$n$$$ equals to $$$v$$$ and the player is able to do the following operation as many times as the player want (possibly zero): choose a positive integer $$$x$$$ that $$$x<n$$$ and $$$x$$$ is not a divisor of $$$n$$$, then subtract $$$x$$$ from $$$n$$$. The goal of the player is to minimize the value of $$$n$$$ in the end.Soon, Chouti found the game trivial. Can you also beat the game?

The input contains only one integer in the first line: $$$v$$$ ($$$1 \le v \le 10^9$$$), the initial value of $$$n$$$.

Output a single integer, the minimum value of $$$n$$$ the player can get.

NoteIn the first example, the player can choose $$$x=3$$$ in the first turn, then $$$n$$$ becomes $$$5$$$. He can then choose $$$x=4$$$ in the second turn to get $$$n=1$$$ as the result. There are other ways to get this minimum. However, for example, he cannot choose $$$x=2$$$ in the first turn because $$$2$$$ is a divisor of $$$8$$$.In the second example, since $$$n=1$$$ initially, the player can do nothing.

use std::cell::RefCell;
use std::io::{self, Read};
use std::iter::FromIterator;

#[allow(dead_code)]
struct Source {
    chars: Box<Iterator<Item = char>>,
}

#[allow(dead_code)]
impl Source {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }

    fn from_stdin() -> Self {
        let mut data = String::new();
        io::stdin().read_to_string(&mut data).expect("Input error");
        Self::from_str(&data)
    }

    fn from_str(s: &str) -> Self {
        let data = String::from(s);
        let chars = data.chars().collect::<Vec<char>>().into_iter();
        Source {
            chars: Box::new(chars),
        }
    }
}

thread_local!(static SRC: RefCell<Source> = RefCell::new(Source::from_stdin()));

#[allow(unused_macros)]
macro_rules! input {
    ($($elem:tt)*) => {
        input_inner!(SRC, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = $src.with(|src| {
            let mut src = src.borrow_mut();
            parse!(src, $ty)
        });
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = $src.with(|src| {
            let mut src = src.borrow_mut();
            parse!(src, $ty)
        });
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

fn main() {
    input! { n: mut u32 }

    if n > 2 {
        println!("1")
    } else {
        println!("{}", n)
    }
}

use std::io;

fn main() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).expect("failed to read input");
    let s: u32 = buffer.trim().parse().expect("invalid input");

    println!("{}", if s == 2 { 2 } else { 1 });
}

use std::io::{self, BufRead};
use std::fs;

fn main() {
    let stdin = io::stdin();
    let line = stdin.lock()
        .lines()
        .next()
        .expect("there was no next line")
        .expect("the line could not be read");

    let numbers: Vec<_> = line.split(" ").collect();
    let v: i32 = numbers[0].parse().unwrap();
//    let b: i32 = numbers[1].parse().unwrap();

    println!("{}", if v == 2 {2} else {1});
}

//fn main() {
//    let mut line = String::new();
//    let stdin = io::stdin();
//    stdin.lock().read_line(&mut line).expect("Could not read line");
//    println!("{}", line)
//}

/*
fn main() {
    let stdin = io::stdin();
    let lines: Vec<String> = stdin.lock().lines().map(|x| x.unwrap()).collect();

    let line = &lines[0];

//    let data = fs::read_to_string("test").expect("Unable to read file");
//    println!("{}", data);

    let numbers: Vec<_> = line.split(" ").collect();
    let a: i32 = numbers[0].parse().unwrap();
    let b: i32 = numbers[1].parse().unwrap();

    println!("{}", a + b);
}

*/

use std::io::{self, BufRead};
use std::fs;

fn main() {
    let stdin = io::stdin();
    let line = stdin.lock()
        .lines()
        .next()
        .expect("there was no next line")
        .expect("the line could not be read");

    let numbers: Vec<_> = line.split(" ").collect();
    let v: i32 = numbers[0].parse().unwrap();
//    let b: i32 = numbers[1].parse().unwrap();

    println!("{}", 1);
}

//fn main() {
//    let mut line = String::new();
//    let stdin = io::stdin();
//    stdin.lock().read_line(&mut line).expect("Could not read line");
//    println!("{}", line)
//}

/*
fn main() {
    let stdin = io::stdin();
    let lines: Vec<String> = stdin.lock().lines().map(|x| x.unwrap()).collect();

    let line = &lines[0];

//    let data = fs::read_to_string("test").expect("Unable to read file");
//    println!("{}", data);

    let numbers: Vec<_> = line.split(" ").collect();
    let a: i32 = numbers[0].parse().unwrap();
    let b: i32 = numbers[1].parse().unwrap();

    println!("{}", a + b);
}

*/


A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....   The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.

The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).  The second line contains two integers c and d (1 ≤ c, d ≤ 100).

Print the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.

NoteIn the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.

use std::io::{self, Read};
use std::cmp::min;

fn read_line() -> Vec<i32> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    return buf.trim().split(" ")
        .map(|x| {x.parse::<i32>().unwrap() })
        .collect();
}

fn get_ans (a : i32, b : i32, c : i32, d : i32) -> i32{
    let ans = -1;

    for i in 0..101{
        for j in 0..101{
            if (a*i + b == c*j + d){
                return a*i + b;
            }
        }
    }

    return 0x3f3f3f3f;
}

fn main(){
    let mut line = read_line();
    let (a, b) = (line[0], line[1]);
    line = read_line();
    let (c, d) = (line[0], line[1]);

    let mut ans = 0x3f3f3f3f;

    ans = min (get_ans(c, d, a, b), get_ans(a, b, c, d));
    if (ans == 0x3f3f3f3f){
        println! ("-1");
    }
    else{
        println! ("{}", ans);
    }

}

fn gcd(mut x: usize, mut y: usize) -> usize {
    while y != 0 {
        let z = x%y;
        x = y;
        y = z;
    }
    x
}

fn lcm(x: usize, y: usize) -> usize {
    x * y / gcd(x, y)
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let mut line = line.split_whitespace();
    let a = line.next().unwrap().parse::<usize>().unwrap();
    let b = line.next().unwrap().parse::<usize>().unwrap();
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let mut line = line.split_whitespace();
    let c = line.next().unwrap().parse::<usize>().unwrap();
    let d = line.next().unwrap().parse::<usize>().unwrap();

    let mut counter_one = 0;
    let mut counter_two = 0;
    let limit = lcm(a, c);
    loop {
        let (x, y) = (counter_one + b, counter_two + d);
        if x == y {
            println!("{}", x);
            return;
        } else if x < y {
            counter_one += a;
        } else {
            counter_two += c;
        }
        if counter_one > limit && counter_two > limit {
            println!("-1");
            return;
        }
    }
}

use std::io;
use std::str::FromStr;

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>(s: String) -> Vec<T>
    where T: FromStr,
          <T as FromStr>::Err: std::fmt::Debug,
{
    s.split_whitespace().map(|k| k.parse().unwrap()).collect()
}

fn extended_euclid(a: i32, b: i32) -> (i32, i32, i32) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d, x, y) = extended_euclid(b, modulo(a, b));
        (d, y, x - a / b * y)
    }
}

fn modulo(a: i32, b: i32) -> i32 {
    let ret_val = a % b;
    if ret_val < 0 {
        ret_val + b
    } else {
        ret_val
    }
}

fn main() {
    let (a, b): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let (c, d): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let e = d - b;

    let (g, x, y) = extended_euclid(a, c);

    let ans = if e % g != 0 {
        -1
    } else {
        let x1 = x * e / g;
        let x2 = modulo(x1, c / g);

        let y1 = y * e / g;
        let y2 = modulo(-y1, a / g);

        max(b + x2 * a, d + y2 * c)
    };

    println!("{}", ans);
}

use std::io::{self, Read};

fn read_line() -> Vec<i64> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    return buf.trim().split(" ")
        .map(|x| {x.parse::<i64>().unwrap() })
        .collect();
}

fn main(){

    let mut line = read_line();
    let (a, b) = (line[0], line[1]);
    line = read_line();
    let (c, d) = (line[0], line[1]);

    let mut ans = -1;

    'outer: for i in 1..101 {

        for j in 1..101 {
            if ((a*i + b) == (c*j + d)){
                ans = a*i + b;
                break 'outer;
            }
        }
    }

    println! ("{}", ans);
}

use std::io;
use std::str::FromStr;

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>(s: String) -> Vec<T>
    where T: FromStr,
          <T as FromStr>::Err: std::fmt::Debug,
{
    s.split_whitespace().map(|k| k.parse().unwrap()).collect()
}

fn extended_euclid(a: i32, b: i32) -> (i32, i32, i32) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d, x, y) = extended_euclid(b, modulo(a, b));
        (d, y, x - a / b * y)
    }
}

fn modulo(a: i32, b: i32) -> i32 {
    let ret_val = a % b;
    if ret_val < 0 {
        ret_val + b
    } else {
        ret_val
    }
}

fn main() {
    let (a, b): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let (c, d): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let e = d - b;

    let (g, x, y) = extended_euclid(a, c);

    let ans = if e % g != 0 {
        -1
    } else {
        let x1 = x * e / g;
        let x2 = modulo(x1, c / g);
        b + x2 * a
    };

    println!("{}", ans);
}

use std::io;
use std::str::FromStr;

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>(s: String) -> Vec<T>
    where T: FromStr,
          <T as FromStr>::Err: std::fmt::Debug,
{
    s.split_whitespace().map(|k| k.parse().unwrap()).collect()
}

fn extended_euclid(a: i32, b: i32) -> (i32, i32, i32) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d, x, y) = extended_euclid(b, modulo(a, b));
        (d, y, x - a / b * y)
    }
}

fn modulo(a: i32, b: i32) -> i32 {
    if a < 0 {
        a % b + b
    } else {
        a % b
    }
}

fn main() {
    let (a, b): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let (c, d): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let e = d - b;

    let (g, x, y) = extended_euclid(a, c);

    let ans = if e % g != 0 {
        -1
    } else {
        let f = e / g;
        let x0 = x * f;
        let x1 = modulo(x0, c / g);
        a * x1 + b
    };

    println!("{}", ans);
}

use std::io;
use std::str::FromStr;

use std::cmp::{max, min};

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>(s: String) -> Vec<T>
    where T: FromStr,
          <T as FromStr>::Err: std::fmt::Debug,
{
    s.split_whitespace().map(|k| k.parse().unwrap()).collect()
}

fn extended_gcd(a: i32, b: i32) -> (i32, i32, i32) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d1, x1, y1) = extended_gcd(b, modulo(a, b));
        let (d, x, y) = (d1, y1, x1 - (a / b) * y1);
        (d, x, y)
    }
}

fn modulo(a: i32, b: i32) -> i32 {
    if a < 0 {
        a % b + b
    } else {
        a % b
    }
}

fn main() {
    let (a, b): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let (c, d): (i32, i32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let (g, x, y) = extended_gcd(a, c);

    let ans = if (b - d) % g == 0 {
        a * modulo(x * (d - b) / g, c) + b
    } else {
        -1
    };

    println!("{}", ans);
}


It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.

Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26). In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.

Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower).

NoteIn the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.

#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(isize);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

fn main() {
  scanln!(n: u32, guards: u32);
  scanln!(guests: String);
  let mut starts = vec![-1i32; 26];
  let mut ends = vec![-1i32; 26];
  for (i, &byte) in guests.as_bytes().iter().enumerate() {
    let idx = (byte - b'A') as usize;
    ends[idx] = i as i32;
    if starts[idx] == -1 { starts[idx] = i as i32; }
  }

  enum Event { Start(i32), End(i32) };
  let mut events: Vec<Event> = starts.into_iter().filter_map(|x| if x != -1 { Some(Event::Start(x)) } else { None })
    .chain(ends.into_iter().filter_map(|x| if x != -1 { Some(Event::End(x)) } else { None }))
    .collect();
  events.sort_by_key(|x| match *x {
    Event::Start(x) => x,
    Event::End(x) => x
  });
  let mut concurrent = 0;
  let mut max_concurrent = 0;
  for event in events {
    match event {
      Event::Start(_) => concurrent += 1,
      Event::End(_) => concurrent -= 1
    };
    max_concurrent = std::cmp::max(max_concurrent, concurrent);
  }
  println!("{}", if max_concurrent > guards { "YES" } else { "NO" });
}

fn main() {
    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let mut it = input.split_whitespace().map(|x| x.parse::<usize>().unwrap());

    let (n, k) = (it.next().unwrap(), it.next().unwrap());

    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let input = input.trim();

    let mut last_poss = [0; 26];

    for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {
        last_poss[c as usize] = i;
    }

    let mut statuses = [0; 26];
    for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {
        statuses[c as usize] = 1;
        let cur_gc:usize = statuses.iter().fold(0, |acc, &x| acc + x);
        if cur_gc > k {
            println!("YES");
            std::process::exit(0);
        }
        if i >= last_poss[c as usize] {
            statuses[c as usize] = 0;
        }
    }

    println!("NO");
}

fn read_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect(
        "Could not read line",
    );
    String::from(&line[..line.len() - 1])
}

macro_rules! read_line {
    (Vec<$t: ty>) => {{
        read_line().split_whitespace().map(|token| {
            <$t as std::str::FromStr>::from_str(token).expect(
                &format!(concat!("Could not parse {} into ", stringify!($t)), token))
        }).collect::<Vec<$t>>()
    }};
    ($($t: ty),*) => {{
        let line = read_line();
        let mut iter = line.split_whitespace();
        let result = ($({
            let token = iter.next().expect("Not enough tokens");
            <$t as std::str::FromStr>::from_str(token).expect(
                &format!(concat!("Could not parse {} into ", stringify!($t)), token))
        }),*);
        if let Some(token) = iter.next() {
            panic!("Unexpected token {}", token);
        }
        result
    }};
}

fn main() {
    let (n, k) = read_line!(usize, usize);
    let s: Vec<char> = read_line().chars().collect();
    let mut v = vec![0; s.len() + 1];
    for c in 'A' as u8..'Z' as u8 + 1 {
        let c = c as char;
        if let Some(i1) = s.iter().position(|x| *x == c) {
            let i2 = s.iter().rposition(|x| *x == c).unwrap() + 1;
            v[i1] += 1;
            v[i2] -= 1;
        }
    }
    let mut cur = 0;
    let mut ans = false;
    for &x in &v {
        cur += x;
        // println!("{}", cur);
        if cur > k {
            ans = true;
            break;
        }
    }
    println!("{}", if ans { "YES" } else { "NO" });
}

fn read_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("EOF");
    line.pop();
    return line;
}

macro_rules! read_line {
    (Vec<$t: ty>) => {{
        read_line().split_whitespace().map(|token| {
            <$t as std::str::FromStr>::from_str(token).expect("Invalid token")
        }).collect<Vec<$t>>()
    }};
    ($($t: ty),*) => {{
        let line = read_line();
        let mut iter = line.split_whitespace();
        ($({
            let token = iter.next().expect("Too few tokens");
            <$t as std::str::FromStr>::from_str(token).expect("Invalid token")
        }), *)
    }};
}

use std::collections::HashMap;
use std::collections::HashSet;

fn main() {
    let (n, k) = read_line!(i32, usize);
    let s = read_line();
    let mut last_of: HashMap<char, usize> = HashMap::new();
    for (i, c) in s.chars().enumerate() {
        last_of.insert(c, i);
    }

    let mut ans = false;
    let mut open_doors = HashSet::new();
    for (i, c) in s.chars().enumerate() {
        open_doors.insert(c);
        if open_doors.len() > k {
            ans = true;
        }
        if last_of[&c] == i {
            open_doors.remove(&c);
        }
    }

    match ans {
        true => println!("YES"),
        false => println!("NO"),
    }
}

#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(isize);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

fn main() {
  scanln!(n: u32, guards: u32);
  scanln!(guests: String);
  let mut starts = vec![-1i32; 26];
  let mut ends = vec![-1i32; 26];
  for (i, &byte) in guests.as_bytes().iter().enumerate() {
    let idx = (byte - b'A') as usize;
    ends[idx] = i as i32;
    if starts[idx] == -1 { starts[idx] = i as i32; }
  }

  enum Event { Start(i32), End(i32) };
  let mut events: Vec<Event> = ends.into_iter().filter_map(|x| if x != -1 { Some(Event::End(x)) } else { None })
    .chain(starts.into_iter().filter_map(|x| if x != -1 { Some(Event::Start(x)) } else { None }))
    .collect();
  events.sort_by_key(|x| match *x {
    Event::Start(x) => x,
    Event::End(x) => x
  });
  let mut concurrent = 0;
  let mut max_concurrent = 0;
  for event in events {
    match event {
      Event::Start(_) => concurrent += 1,
      Event::End(_) => concurrent -= 1
    };
    max_concurrent = std::cmp::max(max_concurrent, concurrent);
  }
  println!("{}", if max_concurrent > guards { "YES" } else { "NO" });
}

#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(isize);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

fn main() {
  scanln!(n: u32, guards: u32);
  scanln!(guests: String);
  let mut starts = vec![-1i32; 26];
  let mut ends = vec![-1i32; 26];
  for (i, &byte) in guests.as_bytes().iter().enumerate() {
    let idx = (byte - b'A') as usize;
    ends[idx] = i as i32;
    if starts[idx] == -1 { starts[idx] = i as i32; }
  }
  let mut max_overlaps = 0;
  for i in 0..26 {
    let here = starts[i];
    if here != -1 {
      let mut overlaps = 1;
      for j in 0..26 {
        if i != j && starts[j] != -1 {
          use std::mem;
          let (mut os, mut oe) = (starts[i], ends[i]);
          let (mut ts, mut te) = (starts[j], ends[j]);
          if os > ts {
            mem::swap(&mut os, &mut ts);
            mem::swap(&mut oe, &mut te);
          }
          if ts <= oe { overlaps += 1; }
        }
      }
      max_overlaps = std::cmp::max(max_overlaps, overlaps);
    }
  }
  println!("{}", if max_overlaps > guards { "YES" } else { "NO" });
}

use std::collections::HashSet;

fn main() {
    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let mut it = input.split_whitespace().map(|x| x.parse::<usize>().unwrap());

    let (n, k) = (it.next().unwrap(), it.next().unwrap());

    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let input = input.trim();

    let has_left: Vec<_> = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {
        state.insert(x.clone());
        Some(state.clone())
    }).collect();

    let has_right: Vec<_> = input.chars().rev().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {
        state.insert(x.clone());
        Some(state.clone())
    }).collect();

    let it = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap());
    let it = it.skip(1).take(n - 2).zip(has_left.iter().zip(&has_right));

    for (c, (left_set, right_set)) in it {
        let cur_gc = left_set.intersection(&right_set).filter(|&&x| x != c).count();
        if cur_gc >= k {
            println!("YES");
            std::process::exit(0);
        }
    }
    println!("NO");
}

fn main() {
    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let mut it = input.split_whitespace().map(|x| x.parse::<usize>().unwrap());

    let (n, k) = (it.next().unwrap(), it.next().unwrap());

    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let input = input.trim();

    let mut last_poss = [0; 26];

    for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {
        last_poss[c as usize] = i;
    }

    let mut statuses = [0; 26];
    for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {
        if i >= last_poss[c as usize] {
            statuses[c as usize] = 0;
        } else {
            statuses[c as usize] = 1;
        }
        let cur_gc:usize = statuses.iter().fold(0, |acc, &x| acc + x);
        if cur_gc > k {
            println!("YES");
            std::process::exit(0);
        }
    }

    println!("NO");
}

use std::collections::HashSet;

fn main() {
    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let mut it = input.split_whitespace().map(|x| x.parse::<usize>().unwrap());

    let (n, k) = (it.next().unwrap(), it.next().unwrap());

    let mut input = String::new();

    std::io::stdin().read_line(&mut input).unwrap();

    let input = input.trim();

    let has_left: Vec<_> = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {
        state.insert(x.clone());
        Some(state.clone())
    }).collect();

    let has_right: Vec<_> = input.chars().rev().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {
        state.insert(x.clone());
        Some(state.clone())
    }).collect();

    let it = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap());
    let it = it.skip(1).take(n - 2).zip(has_left.iter().zip(&has_right));

    println!("{:?}\n{:?}", has_left, has_right);

    for (c, (left_set, right_set)) in it {
        let cur_gc = left_set.intersection(&right_set).filter(|&&x| x != c).count();
        if cur_gc >= k {
            println!("YES");
            std::process::exit(0);
        }
    }
    println!("NO");
}


Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:  the Euclidean distance between A and B is one unit and neither A nor B is blocked;  or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B. Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick?

The first line contains an integer n (0 ≤ n ≤ 4·107).

Print a single integer — the minimum number of points that should be blocked.

#![allow(unused_imports)]
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};
use std::cmp::Ordering::{*};

// I have no idea what I'm doing

use std::f64::consts::{PI};

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let n: i64 = scan.token();

    if n == 0 {
        return writeln!(out, "1");
    }

    let is_in = |i, j| i*i + j*j <= n*n;
    // Uncomment for a cool circle in your screen
    // for i in -n..=n {
    //     for j in -n..=n {
    //         write!(out, "{}", if is_in(i.abs(), j.abs()) { '+' }
    //                           else { '-' })?;
    //         write!(out, " ")?;
    //     }
    //     writeln!(out)?;
    // }

    let mut ans = 0;
    let mut y = n;
    for x in 0..=n {
        if is_in(x, y) {
            ans += 1;
        }
        while !is_in(x, y) {
            y -= 1;
            ans += 1;
        }
    }

    writeln!(out, "{}", (ans - 1) * 4)?;

    Ok(())
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}

#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn bi(x: i64, n: i64, l0: i64, r0: i64) -> i64 {
    let mut left = l0;
    let mut right = r0;

    while right - left > 1 {
        let y = (left + right) / 2;
        if x * x + y * y <= n * n {
            left = y;
        } else {
            right = y;
        }
    }
    return left;
}

fn main() {
    let mut sc = Scanner::new();

    let n: i64 = sc.cin();

    if n == 0 {
        println!("1");
        return;
    }

    let mut a = 0;
    let mut b = 0;

    let mut l0 = 0;
    let mut r0 = n + 1;
    for x in 0..n {
        let y = bi(x, n, l0, r0);
        l0 = max(0, y - 10);
        r0 = min(y + 10, n + 1);
        // trace!((x, y));
        if x < y {
            a += 1;
        } else if x == y {
            b += 1;
            break;
        } else {
            break;
        }
    }
    let ans = 4 * (a * 2 - 1 + b);
    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}

#![allow(unused_imports)]
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};
use std::cmp::Ordering::{*};

// I have no idea what I'm doing

use std::f64::consts::{PI};

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let n: i64 = scan.token();

    let is_in = |i, j| i*i + j*j <= n*n;
    // Uncomment for a cool circle in your screen
    // for i in -n..=n {
    //     for j in -n..=n {
    //         write!(out, "{}", if is_in(i.abs(), j.abs()) { '+' }
    //                           else { '-' })?;
    //         write!(out, " ")?;
    //     }
    //     writeln!(out)?;
    // }

    let mut ans = 0;
    let mut y = n;
    for x in 0..=n {
        if is_in(x, y) {
            ans += 1;
        }
        while !is_in(x, y) {
            y -= 1;
            ans += 1;
        }
    }

    writeln!(out, "{}", (ans - 1) * 4)?;

    Ok(())
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}

#![allow(unused_imports)]
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};
use std::cmp::Ordering::{*};

// I have no idea what I'm doing

use std::f64::consts::{PI};

fn brute(n: i32) -> i32 {
    let mut ans = 0;
    let is_in = |i, j| i*i + j*j <= n*n;
    for i in -n..=n {
        for j in -n..=n {
            let (i, j) = (i.abs(), j.abs());
            if is_in(i, j) && (!is_in(i+1, j) || !is_in(i, j+1) || !is_in(i-1, j) || !is_in(i, j-1)) {
                ans += 1;
            }
        }
    }
    ans
}

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let n: i32 = scan.token();

    // I wonder if this works
    writeln!(out, "{}", if n <= 2500 { brute(n) as i64 }
                        else { (2.0 * PI * f64::from(n)).round() as i64 })?;

    Ok(())
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}

#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn bi(x: i32, n: i32) -> i32 {
    let mut left = 0;  // in
    let mut right = n + 1;  // out
    for _ in 0..100 {
        let y = (left + right) / 2;
        if x * x + y * y <= n * n {
            left = y;
        } else {
            right = y;
        }
    }
    return left;
}

fn main() {
    let mut sc = Scanner::new();

    let n: i32 = sc.cin();

    let mut a = 0;
    let mut b = 0;
    for x in 0..n {
        let y = bi(x, n);
        // trace!((x, y));
        if x < y {
            a += 1;
        } else if x == y {
            b += 1;
            break;
        } else {
            break;
        }
    }
    let ans = 4 * (a * 2 - 1 + b);
    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}

#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn bi(x: i64, n: i64, l0: i64, r0: i64) -> i64 {
    let mut left = l0;
    let mut right = r0;

    while right - left > 1 {
        let y = (left + right) / 2;
        if x * x + y * y <= n * n {
            left = y;
        } else {
            right = y;
        }
    }
    return left;
}

fn main() {
    let mut sc = Scanner::new();

    let n: i64 = sc.cin();

    if n == 0 {
        println!("1");
        return;
    }

    let mut a = 0;
    let mut b = 0;

    let mut l0 = 0;
    let mut r0 = n + 1;
    for x in 0..n {
        let y = bi(x, n, l0, r0);
        l0 = y - 10;
        r0 = y + 10;
        // trace!((x, y));
        if x < y {
            a += 1;
        } else if x == y {
            b += 1;
            break;
        } else {
            break;
        }
    }
    let ans = 4 * (a * 2 - 1 + b);
    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}

#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn bi(x: i32, n: i32) -> i32 {
    let mut left = 0;  // in
    let mut right = n + 1;  // out
    for _ in 0..100 {
        let y = (left + right) / 2;
        if x * x + y * y <= n * n {
            left = y;
        } else {
            right = y;
        }
    }
    return left;
}

fn main() {
    let mut sc = Scanner::new();

    let n: i32 = sc.cin();

    if n == 0 {
        println!("1");
        return;
    }

    let mut a = 0;
    let mut b = 0;
    for x in 0..n {
        let y = bi(x, n);
        // trace!((x, y));
        if x < y {
            a += 1;
        } else if x == y {
            b += 1;
            break;
        } else {
            break;
        }
    }
    let ans = 4 * (a * 2 - 1 + b);
    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.

The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.

Print a single number — the sum of all edges of the parallelepiped.

NoteIn the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.

#[allow(unused_imports)]
use std::cmp::{min,max};
use std::collections::{*};
use std::io::{BufWriter, stdin, stdout, Write};
const BITS: usize = 19;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scanner = Scanner::default();
    let (a, b, c): (f64, f64, f64) = (scanner.next(), scanner.next(), scanner.next());
    let tot = (a*b*c).sqrt();
    println!["{}", 4.0*(tot/a + tot/b + tot/c)];
}

fn main() {
    let areas: Vec<f64> = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();

    let a = (areas[0] * areas[1] / areas[2]).sqrt();
    let b = (areas[0] * areas[2] / areas[1]).sqrt();
    let c = (areas[2] * areas[1] / areas[0]).sqrt();
    let res = 4 * (a+b+c) as u32;

    println!("{}", res);

}

fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer.trim().to_owned()
}

fn get_input_usize() -> usize {
    get_input().parse().unwrap()
}

fn main() {
    let areas: Vec<u32> = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();
    let sum: u32 = areas.iter().sum();
    let result = 4 * sum;

    println!("{}", result);

}

fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer.trim().to_owned()
}

fn get_input_usize() -> usize {
    get_input().parse().unwrap()
}


Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture:  The picture shows only the central part of the clock. This coloring naturally extends to infinity.The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball.All the points located on the border of one of the areas have to be considered painted black.

The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000.

Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black.

#![allow(unused_imports)]
use std::cmp::Ordering::*;
use std::collections::{BTreeMap, BTreeSet};
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};

// I have no idea what I'm doing

macro_rules! answer {
    ($out:ident, $ans:expr) => {
        writeln!($out, "{}", $ans)
    };
}

fn sqrt(x: i32) -> i32 {
    (0..=2000).find(|y| y * y >= x).unwrap()
}

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let mut rev = false;

    let (mut x, mut y) = scan.pair::<i32>();
    if x < 0 {
        rev = !rev;
        x = -x;
    }
    if y < 0 {
        rev = !rev;
        y = -y;
    }

    let dsq = x*x + y*y;

    let d = sqrt(dsq);

    if d * d == dsq {
        return answer!(out, "black");
    }

    answer!(out, match (d & 1 == 1) != rev {
        true => "black",
        false => "white",
    })?;

    Ok(())
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}


The only difference between easy and hard versions is on constraints. In this version constraints are lower. You can make hacks only if all versions of the problem are solved.Koa the Koala is at the beach!The beach consists (from left to right) of a shore, $$$n+1$$$ meters of sea and an island at $$$n+1$$$ meters from the shore.She measured the depth of the sea at $$$1, 2, \dots, n$$$ meters from the shore and saved them in array $$$d$$$. $$$d_i$$$ denotes the depth of the sea at $$$i$$$ meters from the shore for $$$1 \le i \le n$$$.Like any beach this one has tide, the intensity of the tide is measured by parameter $$$k$$$ and affects all depths from the beginning at time $$$t=0$$$ in the following way:  For a total of $$$k$$$ seconds, each second, tide increases all depths by $$$1$$$.  Then, for a total of $$$k$$$ seconds, each second, tide decreases all depths by $$$1$$$.  This process repeats again and again (ie. depths increase for $$$k$$$ seconds then decrease for $$$k$$$ seconds and so on ...).Formally, let's define $$$0$$$-indexed array $$$p = [0, 1, 2, \ldots, k - 2, k - 1, k, k - 1, k - 2, \ldots, 2, 1]$$$ of length $$$2k$$$. At time $$$t$$$ ($$$0 \le t$$$) depth at $$$i$$$ meters from the shore equals $$$d_i + p[t \bmod 2k]$$$ ($$$t \bmod 2k$$$ denotes the remainder of the division of $$$t$$$ by $$$2k$$$). Note that the changes occur instantaneously after each second, see the notes for better understanding. At time $$$t=0$$$ Koa is standing at the shore and wants to get to the island. Suppose that at some time $$$t$$$ ($$$0 \le t$$$) she is at $$$x$$$ ($$$0 \le x \le n$$$) meters from the shore:  In one second Koa can swim $$$1$$$ meter further from the shore ($$$x$$$ changes to $$$x+1$$$) or not swim at all ($$$x$$$ stays the same), in both cases $$$t$$$ changes to $$$t+1$$$.  As Koa is a bad swimmer, the depth of the sea at the point where she is can't exceed $$$l$$$ at integer points of time (or she will drown). More formally, if Koa is at $$$x$$$ ($$$1 \le x \le n$$$) meters from the shore at the moment $$$t$$$ (for some integer $$$t\ge 0$$$), the depth of the sea at this point  — $$$d_x + p[t \bmod 2k]$$$  — can't exceed $$$l$$$. In other words, $$$d_x + p[t \bmod 2k] \le l$$$ must hold always.  Once Koa reaches the island at $$$n+1$$$ meters from the shore, she stops and can rest.Note that while Koa swims tide doesn't have effect on her (ie. she can't drown while swimming). Note that Koa can choose to stay on the shore for as long as she needs and neither the shore or the island are affected by the tide (they are solid ground and she won't drown there). Koa wants to know whether she can go from the shore to the island. Help her!

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)  — the number of test cases. Description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k$$$ and $$$l$$$ ($$$1 \le n \le 100; 1 \le k \le 100; 1 \le l \le 100$$$) — the number of meters of sea Koa measured and parameters $$$k$$$ and $$$l$$$. The second line of each test case contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$ ($$$0 \le d_i \le 100$$$)  — the depths of each meter of sea Koa measured. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$.

For each test case: Print Yes if Koa can get from the shore to the island, and No otherwise. You may print each letter in any case (upper or lower).

NoteIn the following $$$s$$$ denotes the shore, $$$i$$$ denotes the island, $$$x$$$ denotes distance from Koa to the shore, the underline denotes the position of Koa, and values in the array below denote current depths, affected by tide, at $$$1, 2, \dots, n$$$ meters from the shore.In test case $$$1$$$ we have $$$n = 2, k = 1, l = 1, p = [ 0, 1 ]$$$.Koa wants to go from shore (at $$$x = 0$$$) to the island (at $$$x = 3$$$). Let's describe a possible solution:  Initially at $$$t = 0$$$ the beach looks like this: $$$[\underline{s}, 1, 0, i]$$$.  At $$$t = 0$$$ if Koa would decide to swim to $$$x = 1$$$, beach would look like: $$$[s, \underline{2}, 1, i]$$$ at $$$t = 1$$$, since $$$2 > 1$$$ she would drown. So Koa waits $$$1$$$ second instead and beach looks like $$$[\underline{s}, 2, 1, i]$$$ at $$$t = 1$$$.  At $$$t = 1$$$ Koa swims to $$$x = 1$$$, beach looks like $$$[s, \underline{1}, 0, i]$$$ at $$$t = 2$$$. Koa doesn't drown because $$$1 \le 1$$$.  At $$$t = 2$$$ Koa swims to $$$x = 2$$$, beach looks like $$$[s, 2, \underline{1}, i]$$$ at $$$t = 3$$$. Koa doesn't drown because $$$1 \le 1$$$.  At $$$t = 3$$$ Koa swims to $$$x = 3$$$, beach looks like $$$[s, 1, 0, \underline{i}]$$$ at $$$t = 4$$$.  At $$$t = 4$$$ Koa is at $$$x = 3$$$ and she made it! We can show that in test case $$$2$$$ Koa can't get to the island.

use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

fn tide(k: usize, time: usize) -> usize {
    let time = time % (2 * k);
    if time <= k {
        time
    } else {
        2 * k - time
    }
}

fn depth(k: usize, depths: &Vec<usize>, time: usize, index: usize) -> usize {
    depths[index] + tide(k, time)
}

fn prev_time(k: usize, time: usize) -> usize {
    if time == 0 {
        2 * k - 1
    } else {
        time - 1
    }
}

fn possible(k: usize, l: usize, depths: &Vec<usize>) -> bool {
    let mut dp = vec![vec![false; 2 * k]; depths.len()];
    for i in 0..2 * k {
        if depth(k, depths, i, 0) <= l {
            dp[0][i] = true;
        }
    }

    for i in 1..depths.len() {
        for t in 0..2 * k {
            let p = prev_time(k, t);
            let d = depth(k, depths, t, i);

            if d > l {
                continue;
            } else if dp[i - 1][p] {
                dp[i][t] = true;
            } else if dp[i][p] {
                dp[i][t] = true;
            }
        }
    }
    dp[depths.len() - 1].iter().any(|&b| b)
}

fn main() {
    let mut reader = TokenReader::new();
    let tests = reader.next();

    for _ in 0..tests {
        let _ = reader.next::<usize>();
        let k = reader.next();
        let l = reader.next();
        let depths = reader.vector();

        let res = possible(k, l, &depths);
        println!("{}", if res { "Yes" } else { "No" });
    }
}

#![allow(dead_code)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;
use std::io;
use std::ops::{self, Range};
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
struct ProblemState {
}

impl Problem {
    fn solve(&mut self) {
        let n: usize = self.scan();
        let k: usize = self.scan();
        let l: usize = self.scan();
        let d: Vec<usize> = self.scan_vec(n);

        let mut x = vec![vec![0; 2 * k]; n];
        let mut p = vec![0; 2 * k];

        for i in 0..k {
            p[i] = i;
            p[2 * k - i - 1] = i + 1;
        }

        for i in 0..n {
            for j in 0..2 * k {
                if d[i] + p[j] <= l {
                    if i == 0 {
                        x[i][j] = 1;
                    } else {
                        x[i][j] |= x[i - 1][(j - 1 + 2 * k) % (2 * k)];
                        x[i][j] |= x[i][(j - 1 + 2 * k) % (2 * k)];
                    }
                }
            }
        }

        if x[n - 1].iter().any(|x_i| *x_i == 1) {
            println!("Yes");
        } else {
            println!("No");
        }

//        eprintln!("{:?}", x[n - 1]);
    }
}

fn main() {
    Problem::new().solve_cases();
}

struct Problem {
    input_state: InputState,
    problem_state: ProblemState,
}

struct InputState {
    stdin: io::Stdin,
    buffer: String,
    tokens: VecDeque<String>,
}

impl Problem {
    fn new() -> Self {
        Self {
            input_state: InputState {
                stdin: io::stdin(),
                buffer: String::new(),
                tokens: VecDeque::new(),
            },
            problem_state: Default::default(),
        }
    }

    fn solve_cases(&mut self) {
        for _ in 0usize..self.scan() {
            self.solve()
        }
    }

    fn scan<T: FromStr>(&mut self) -> T {
        while self.input_state.tokens.is_empty() {
            self.input_state.stdin.read_line(&mut self.input_state.buffer).unwrap();

            for token in self.input_state.buffer.split_ascii_whitespace() {
                self.input_state.tokens.push_back(token.to_string());
            }

            self.input_state.buffer.clear();
        }

        self.input_state.tokens.pop_front().unwrap().parse().ok().unwrap()
    }

    fn scan_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).into_iter().map(|_| self.scan()).collect()
    }

    fn scan_line(&mut self) -> String {
        let mut line = String::new();
        self.input_state.stdin.read_line(&mut line).unwrap();
        while line.ends_with('\n') || line.ends_with('\r') { line.pop(); }
        line
    }

    fn scan_line_vec(&mut self, n: usize) -> Vec<String> {
        (0..n).into_iter().map(|_| self.scan_line()).collect()
    }
}

impl ops::Deref for Problem {
    type Target = ProblemState;

    fn deref(&self) -> &ProblemState {
        &self.problem_state
    }
}

impl ops::DerefMut for Problem {
    fn deref_mut(&mut self) -> &mut ProblemState {
        &mut self.problem_state
    }
}

use std::collections::HashSet;

struct DFS {
    n: usize, k: usize, l: usize,
    d: Vec<usize>,
    p: Vec<usize>,
    set: HashSet<(usize, usize)>,
}

impl DFS {
    fn new() -> DFS {
        let (n, k, l): (usize, usize, usize) = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            )
        };
        let d: Vec<usize> = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let iter = buf.split_whitespace();
            iter.map(|x| x.parse().unwrap()).collect()
        };
        let p: Vec<usize> = (0..k).chain((1..=k).rev()).collect();
        DFS { n, k, l, d, p, set: HashSet::new() }
    }

    fn search(&mut self, x: usize, t: usize) -> bool {
        if x == self.n + 1 {
            true
        } else if x > 0 && self.d[x - 1] + self.p[t] > self.l {
            false
        } else if self.set.contains(&(x, t)) {
            false
        } else {
            self.set.insert((x, t));
            let nt = (t + 1) % (self.k * 2);
            self.search(x, nt) || self.search(x + 1, nt)
        }
    }
}

fn main() {
    let t: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    for _ in 0..t {
        let mut dfs = DFS::new();
        println!("{}", if dfs.search(0, 0) { "Yes" } else { "No" });
    }
}

#![allow(dead_code, unused_imports)]

use std::fmt::Debug;
use std::str::FromStr;

fn read_stdin() -> String {
    let mut s = String::new();
    std::io::stdin()
        .read_line(&mut s)
        .expect("cannot read stdin");
    s.trim().to_string()
}

fn read<T>() -> T
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    read_stdin().parse::<T>().unwrap()
}

fn read_usize() -> usize {
    read::<usize>()
}

fn read_2<A, B>() -> (A, B)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    (a, b)
}

fn read_3<A, B, C>() -> (A, B, C)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    (a, b, c)
}

fn read_4<A, B, C, D>() -> (A, B, C, D)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
    D: FromStr,
    <D as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    let d = s.next().unwrap().parse::<D>().unwrap();
    (a, b, c, d)
}

fn read_multiple<T: FromStr>() -> Vec<T>
where
    <T as FromStr>::Err: Debug,
{
    read_stdin()
        .split_whitespace()
        .map(|x| x.parse::<T>().expect("cannot parse stdin"))
        .collect()
}

/// NOTE: sort iter beforehand if required
fn count<T>(iter: &mut impl Iterator<Item = T>) -> Vec<(T, usize)>
where
    T: std::cmp::Ord,
{
    let iter = iter.collect::<Vec<_>>();
    //iter.sort();
    let (mut v, o, c) =
        iter.into_iter()
            .fold((Vec::new(), None, 0), |(mut v, last, count), item| {
                if let Some(o) = last {
                    if item == o {
                        (v, Some(o), count + 1)
                    } else {
                        v.push((o, count));
                        (v, Some(item), 1)
                    }
                } else {
                    (v, Some(item), 1)
                }
            });
    if let Some(i) = o {
        v.push((i, c));
    }
    v
}

fn max_subarray(v: impl Iterator<Item = i64>) -> (i64, (usize, usize)) {
    //assert!(v.len() > 0);
    let mut best_sum = 0;
    let (mut best_start, mut best_end) = (0, 0);
    let mut current_sum = 0;
    let mut current_start = 0;
    for (end, val) in v.enumerate() {
        if current_sum <= 0 {
            current_start = end;
            current_sum = val;
        } else {
            current_sum += val;
        }
        if current_sum > best_sum {
            best_sum = current_sum;
            best_start = current_start;
            best_end = end + 1;
        }
    }
    (best_sum, (best_start, best_end))
}

fn gcd(a: u64, b: u64) -> u64 {
    let mut a = a;
    let mut b = b;
    while a != b {
        if a > b {
            a = a - b
        } else {
            b = b - a
        }
    }
    a
}

fn factorize(mut n: u64) -> Vec<u64> {
    if n <= 3 {
        return vec![n];
    }
    let mut v = Vec::new();
    while n % 2 == 0 {
        n /= 2;
        v.push(2);
    }
    while n % 3 == 0 {
        n /= 3;
        v.push(3);
    }
    let mut f = 6;
    while (f - 1) * (f - 1) <= n {
        while n % (f - 1) == 0 {
            n /= f - 1;
            v.push(f - 1);
        }
        while n % (f + 1) == 0 {
            n /= f + 1;
            v.push(f + 1);
        }
        f += 6;
    }
    if n > 1 {
        v.push(n);
    }
    v
}

fn compact_factors(n: u64) -> Vec<(u64, usize)> {
    count(&mut factorize(n).into_iter())
}

fn all_factors(n: u64) -> Vec<u64> {
    let factors = compact_factors(n);
    let mut v = vec![1];
    for (fac, num) in factors {
        let ori = v.clone();
        for i in 1..num + 1 {
            v.append(
                &mut ori
                    .clone()
                    .into_iter()
                    .map(|f| f * fac.pow(i as u32))
                    .collect::<Vec<_>>(),
            )
        }
    }
    v.sort();
    v
}

use std::cmp::{max, min};
use std::collections::VecDeque;

fn first_factor(n: u32) -> u32 {
    if n % 2 == 0 {
        return 2;
    }
    if n % 3 == 0 {
        return 3;
    }
    let mut f = 6;
    while (f - 1) * (f - 1) <= n {
        if n % (f - 1) == 0 {
            return f - 1;
        }
        if n % (f + 1) == 0 {
            return f + 1;
        }
        f += 6;
    }
    return n;
}

fn found(d: Vec<u16>, k: u16, limit: u16) -> bool {
    if d.is_empty() {
        return true;
    }
    let p = (0..k).chain((1..k + 1).rev()).collect::<Vec<_>>();
    for start in 0..p.len() {
        if d.iter()
            .enumerate()
            .map(|(i, di)| di + p[(i + start) % p.len()])
            .all(|di| di <= limit)
        {
            return true;
        }
    }
    false
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    for _ in 0..read_usize() {
        let (_n, k, l) = read_3::<u16, u16, u16>();
        let d = read_multiple();
        let mut dead = false;
        let mut gap = Vec::new();
        for di in d {
            if k + di <= l {
                if !found(gap, k, l) {
                    dead = true
                }
                gap = Vec::new();
            } else {
                gap.push(di)
            }
        }
        if !found(gap, k, l) {
            dead = true
        }
        if dead {
            println!("No")
        } else {
            println!("Yes")
        }
    }
    Ok(())
}

#![allow(dead_code)]
#![allow(unused)]
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::collections::{HashSet, HashMap};
use std::cmp::{min,max,Reverse};
use std::io::{self, prelude::*};
use std::{str, iter};

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self { reader, buf_str: vec![], buf_iter: "".split_whitespace() }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}

const MAX : usize = 444;

fn solve<R: BufRead, W: Write>(scan: &mut Scanner<R>, w: &mut W) {
    let N : usize = scan.token();
    let K : usize = scan.token();
    let L : i64 = scan.token();
    let d : Vec<i64> = iter::repeat_with(|| scan.token()).take(N).collect();
    let p : Vec<i64> = (0..K).chain((1..K+1).rev()).cycle().take(4*K).map(|x| x as i64).collect();

    let mut dp = [[false; MAX]; MAX];
    dp[N] = [true; MAX];

    for i in (0..N).rev() {
        for j in (0..4*K).rev() {
            dp[i][j] = (d[i] + p[j] <= L) && (dp[i][j+1] || dp[i+1][(j+1)%(2*K)]);
        }
    }
    // for i in (0..N).rev() {
    //     println!("{}, {:?}",i,&dp[i][0..2*K]);
    // }

    writeln!(w, "{}", if dp[0].iter().any(|&x|x) {"Yes"} else {"No"});
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    for _ in 0..scan.token::<i32>() {
        solve(&mut scan, &mut out);
    }
}

#![allow(unused_imports)]
#![allow(dead_code)]

use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::io::{stdin, stdout, BufWriter, Write};
use std::mem::swap;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().unwrap();
            }
            let mut input = String::new();
            stdin().read_line(&mut input).unwrap();
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

const T: usize = 20;

fn solve_case<T: Write>(scan: &mut Scanner, out: &mut BufWriter<T>) {
    let n: usize = scan.next();
    let k: usize = scan.next();
    let l: usize = scan.next();
    let d: Vec<usize> = (0..n).map(|_| scan.next()).collect();
    let mut g: Vec<Vec<bool>> = vec![vec![false; 2 * k]; n + 2];
    let mut dt: Vec<usize> = vec![0; 2 * k];
    for i in 0..k {
        dt[i + 1] = dt[i] + 1;
    }
    for i in k + 1..2*k {
        dt[i] = dt[i - 1] - 1;
    }
    g[0][0] = true;
    let mut q: VecDeque<usize> = VecDeque::new();
    q.push_back(0);
    q.push_back(0);
    while !q.is_empty() {
        let pos = q.pop_front().unwrap();
        let time = q.pop_front().unwrap();
        let nxt_time = (time + 1) % dt.len();
        if pos == n+1 {
            writeln!(out, "Yes").unwrap();
            return;
        }
        if (pos == 0 || d[pos-1] + dt[nxt_time] <= l) && !g[pos][nxt_time] {
            g[pos][nxt_time] = true;
            q.push_back(pos);
            q.push_back(nxt_time);
        }
        if (pos == n || d[pos] + dt[nxt_time] <= l) && !g[pos+1][nxt_time] {
            g[pos+1][nxt_time] = true;
            q.push_back(pos+1);
            q.push_back(nxt_time);
        }
    }
    writeln!(out, "No").unwrap();
}

fn solve<T: Write>(scan: &mut Scanner, out: &mut BufWriter<T>) {
    let t: usize = scan.next();
    for _ in 0..t {
        solve_case(scan, out);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("solver_thread".into())
        .stack_size(1024 * 1024 * 1024)
        .spawn(|| {
            let mut scan = Scanner::default();
            let out = stdout();
            let mut out = BufWriter::new(out.lock());
            solve(&mut scan, &mut out);
        })
        .unwrap()
        .join()
        .unwrap();
}

#![allow(dead_code, unused_macros, unused_imports)]
use std::collections::*;
use std::io;
use std::io::Write;
macro_rules! fprintln {
    ($dst:expr) => (
        $dst.write("\n".as_bytes()).unwrap();
    );
    ($dst:expr, $($arg:tt)*) => ( {
        $dst.write_fmt(format_args!($($arg)*)).unwrap();
        $dst.write("\n".as_bytes()).unwrap();
    }
    );
}

macro_rules! fprintvec {
    ($dst:expr, $arg:expr) => {{
        fprintln!(
            $dst,
            "{}",
            $arg.iter()
                .map(|x| format!("{}", x))
                .collect::<Vec<String>>()
                .join(" ")
        );
    }};
}

macro_rules! parse_input {
    ($t:ident) => {{
        let mut input_line = String::new();
        io::stdin().read_line(&mut input_line).unwrap();
        input_line
            .trim_end_matches("\n")
            .trim_end_matches("\r")
            .parse::<$t>()
            .unwrap()
    }};
}

macro_rules! split_input {
    ($t:ident) => {{
        parse_input!(String)
            .split(" ")
            .map(|z| z.parse::<$t>().unwrap())
            .collect::<Vec<$t>>()
    }};
}

fn depth(t: i64, k: i64, start: i64) -> i64 {
    let v;
    let t = t % (2 * k);
    if t <= k {
        v = t;
    } else {
        v = k - (t - k);
    }
    v + start
}

fn slow(depths: &Vec<i64>, k: i64, l: i64) -> bool {
    let mut valid = (0..=2 * k).collect::<HashSet<i64>>();
    for p in depths.iter() {
        let mut next = HashSet::new();
        for z in valid.iter() {
            for x in 1..=(2 * k) {
                if depth(z + x, k, *p) <= l {
                    next.insert((z + x) % (2 * k));
                } else {
                    break;
                }
            }
        }
        valid = next;
    }
    valid.len() > 0
}

fn main() {
    let stdout = io::stdout();
    let lock = stdout.lock();
    let mut w = io::BufWriter::new(lock);
    let num_tests = parse_input!(usize);
    // let num_tests = 1;
    for _ in 0..num_tests {
        let limits = split_input!(i64);
        let n = limits[0];
        let k = limits[1];
        let l = limits[2];
        let vals = split_input!(i64);
        let mut start = -k;
        let mut valid = true;
        // for (p, &d) in vals.iter().enumerate() {
        //     if d > l {
        //         valid = false;
        //         break;
        //     }
        //     if d + k <= l {
        //         start = -k;
        //     } else {
        //         let nt = start + 1;
        //         let bad = (l - d) + 1;
        //         let good = -bad;
        //         if nt >= bad {
        //             valid = false;
        //             break;
        //         }
        //         start = std::cmp::max(nt, good);
        //     }
        //     dbg!(start);
        // }
        valid = slow(&vals, k, l);
        if valid {
            fprintln!(w, "YES");
        } else {
            fprintln!(w, "NO");
        }
    }
}

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn calc_depth(d: &Vec<i64>, p: &Vec<i64>, ki: usize, ni: usize) -> i64 {
    d[ni - 1] + p[ki]
}

fn solve() -> bool {
    let v = read_vec::<usize>();
    let (n, k, l) = (v[0], v[1], v[2] as i64);
    let d = read_vec::<i64>();
    let p = (0..2 * k)
        .map(|x| if x <= k { x as i64 } else { (2 * k - x) as i64 })
        .collect::<Vec<_>>();

    let mut dp = vec![vec![false; 2 * k]; n + 1];
    for ki in 0..2 * k {
        dp[0][ki] = true;
    }

    for ni in 1..n + 1 {
        for ki in 0..2 * k {
            let next_k = (ki + 1) % (2 * k);
            if dp[ni - 1][ki] && calc_depth(&d, &p, next_k, ni) <= l {
                dp[ni][next_k] = true;
            }
        }
        for ki in 0..2 * k {
            let next_k = (ki + 1) % (2 * k);
            if dp[ni][ki] && calc_depth(&d, &p, next_k, ni) <= l {
                dp[ni][next_k] = true;
            }
        }
    }

    dp[n].iter().any(|&x| x)
}

fn main() {
    let n = read::<usize>();
    for i in 0..n {
        if solve() {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance.

The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined.  The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.

Print the year of Igor's university entrance.

NoteIn the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.

#[allow(unused_imports)]
use std::io;
use std::cmp::{min, max};
use std::mem;
use std::str::FromStr;
use std::cmp::Ordering;
use std::collections::BinaryHeap;

pub struct Scanner<B> {
    reader: B,
    buffer: Vec<String>,
}

impl<B: io::BufRead> Scanner<B> {
    pub fn new(reader: B) -> Scanner<B> {
        Scanner {
            reader: reader,
            buffer: Vec::new(),
        }
    }

    /// Use "turbofish" syntax next::<T>() to select data type of next token.
    pub fn next<T: ::std::str::FromStr>(&mut self) -> T
        where
            T::Err: ::std::fmt::Debug,
    {
        if let Some(front) = self.buffer.pop() {
            front.parse::<T>().expect(&front)
        } else {
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Line not read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
            self.next()
        }
    }

    pub fn next_vec<T: ::std::str::FromStr>(&mut self, len: usize) -> Vec<T>
        where
            T::Err: ::std::fmt::Debug,
    {
        (0..len).map(|_| self.next::<T>()).collect::<Vec<T>>()
    }
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
struct ReverseInt(i64);

impl Ord for ReverseInt {
    fn cmp(&self, other: &ReverseInt) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl PartialOrd for ReverseInt {
    fn partial_cmp(&self, other: &ReverseInt) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

fn main1() {
    let stdin = io::stdin();
    let mut input = Scanner::new(stdin.lock());
    let n: usize = input.next();
    let mut v: Vec<i64> = input.next_vec(n);
    v.sort();
    println!("{}", v[n / 2]);
}

fn main() {
    std::thread::Builder::new().stack_size(50 << 20)
        .spawn(main1).unwrap().join().unwrap();
}


A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.A substring $$$s[l \ldots r]$$$ ($$$1 \leq l \leq r \leq |s|$$$) of a string $$$s = s_{1}s_{2} \ldots s_{|s|}$$$ is the string $$$s_{l}s_{l + 1} \ldots s_{r}$$$.Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $$$s$$$ is changed into its longest substring that is not a palindrome. If all the substrings of $$$s$$$ are palindromes, she skips the word at all.Some time ago Ann read the word $$$s$$$. What is the word she changed it into?

The first line contains a non-empty string $$$s$$$ with length at most $$$50$$$ characters, containing lowercase English letters only.

If there is such a substring in $$$s$$$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $$$0$$$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.

Note"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $$$3$$$.The string "uffuw" is one of the longest non-palindrome substrings (of length $$$5$$$) of the string "wuffuw", so the answer for the second example is $$$5$$$.All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $$$0$$$.

use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    let input_string = lines.next().unwrap().expect("input reading failed");
    let len = input_string.len();
    let iter = input_string.chars().take(len / 2 + 1);
    let mut reverse = input_string.chars().rev().take(len / 2 + 1);
    let mut palindrome = true;
    let mut same_char = true;

    // input string is non-empty
    let my_char = input_string.chars().nth(0).unwrap();

    for char_a in iter {
        if char_a != my_char {
            same_char = false;
        }

        let char_b = match reverse.next() {
            Some(c) => c,
            None => {
                break;
            }
        };

        if char_a != char_b {
            palindrome = false;
            break;
        }
    }

    let mut count = len;
    if palindrome {
        if same_char {
            count = 0;
        } else {
            count = len - 1;
        }
    }

    println!("{}", count);
}