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};
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::{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);
}


#[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 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"),
    }
}

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");
}

#[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");
}


#![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();

    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, 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
    }
}


#[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()
}


#![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()
}

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");
        }
    }
}


fn read_line() -> String {
    let stdin = std::io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).unwrap();
    String::from(line.trim())
}

macro_rules! scan_line {
    ($($ty: ty),*) => {{
        let line = read_line();
        let mut tok = line.split_whitespace();
        ($(tok.next().unwrap().parse::<$ty>().unwrap()),*)
    }}
}

fn main() {
    let (a, b) = scan_line!(u64, u64);
    let mut acc = 1;
    for i in (a + 1)..(b + 1) {
        acc = (acc * i % 10) % 10;
        if acc == 0 {
            break;
        }
    }
    println!("{}", acc);
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

fn main() {
    let (a, b): (u64, u64) = util::get2();

    let mut f = 1;

    for x in a + 1..b + 1 {
        f = (f * (x % 10)) % 10;
        if f == 0 {
            break;
        }
    }

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

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>() -> Vec<T>
where T: FromStr,
      <T as FromStr>::Err: std::fmt::Debug,
{
    get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()
}

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

    let ans = if b - a < 10 {
        (a..b).fold(1, |acc, k| ((k + 1) * acc) % 10)
    } else {
        0
    };

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

#![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 partial_sum<T>(v: impl Iterator<Item = T>) -> impl Iterator<Item = T>
where
    T: Default + std::ops::Add<Output = T> + Copy,
{
    v.scan(T::default(), |state, x| {
        *state = *state + x;
        Some(*state)
    })
}

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(mut a: u64, mut b: u64) -> u64 {
    while a != 0 {
        let old_m = a;
        a = b % a;
        b = old_m;
    }
    b
}

/// returns gcd, and pair (x, y), such that x * a + b * y == gcd
fn egcd(a: i64, b: i64) -> (i64, i64, i64) {
    if a == 0 {
        (b, 0, 1)
    } else {
        let (g, x, y) = egcd(b % a, a);
        (g, y - (b / a) * x, x)
    }
}

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> {
    if n == 0 {
        return vec![0];
    } else if n == 1 {
        return vec![1];
    }
    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
}

fn abs_diff<T>(a: T, b: T) -> T
where
    T: PartialOrd + std::ops::Sub<Output = T>,
{
    if a > b {
        a - b
    } else {
        b - a
    }
}

struct Permutations<T> {
    inner: Vec<T>,
    state: Vec<usize>,
    i: usize,
    start: bool,
}

impl<T> Permutations<T> {
    fn new(inner: Vec<T>) -> Self {
        Self {
            state: vec![0; inner.len()],
            i: 0,
            start: true,
            inner,
        }
    }
}

/*impl<T, X> From<X> for Permutations<T>
where
    X: IntoIterator<Item = T>,
{
    fn from(f: X) -> Self {
        Self::new(f.into_iter().collect::<Vec<T>>())
    }
}*/

impl<T> Iterator for Permutations<T>
where
    T: Clone,
{
    type Item = Vec<T>;
    fn next(&mut self) -> Option<Self::Item> {
        if self.start {
            self.start = false;
            return Some(self.inner.clone());
        }
        while self.i < self.inner.len() {
            if self.state[self.i] < self.i {
                if self.i % 2 == 0 {
                    self.inner.swap(0, self.i)
                } else {
                    self.inner.swap(self.state[self.i], self.i)
                }
                self.state[self.i] += 1;
                self.i = 0;
                return Some(self.inner.clone());
            } else {
                self.state[self.i] = 0;
                self.i += 1;
            }
        }
        None
    }
}

use std::cmp::{max, min, Ord, Ordering};
use std::collections::{BinaryHeap, VecDeque};
use std::mem::swap;

#[derive(Clone)]
struct Graph {
    nodes: usize,
    edges: Vec<Vec<(usize, u64)>>,
}

impl Graph {
    fn new(n: usize) -> Self {
        Self {
            nodes: n,
            edges: vec![Vec::new(); n + 1],
        }
    }

    fn add_edge(&mut self, x: usize, y: usize, cost: u64) {
        self.edges[x].push((y, cost));
        self.edges[y].push((x, cost));
    }

    fn dijkstra(&mut self, start: usize, end: usize) -> u64 {
        let mut dist = vec![None; self.nodes + 1];
        let mut prev = vec![None; self.nodes + 1];
        dist[start] = Some(0);
        let mut queue = (1..=self.nodes).collect::<Vec<_>>();
        queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));
        queue.reverse();
        while let Some(next_node) = queue.pop() {
            if next_node == end {
                return dist[next_node].unwrap();
            }
            for (neighbour, cost) in self.edges[next_node].iter() {
                let alt = dist[next_node].unwrap() + cost;
                if dist[*neighbour].is_none() {
                    dist[*neighbour] = Some(alt);
                    prev[*neighbour] = Some(next_node);
                } else {
                    if alt < dist[*neighbour].unwrap() {
                        dist[*neighbour] = Some(alt);
                        prev[*neighbour] = Some(next_node);
                    }
                }
            }
            //println!("{:?} {:?}", dist, prev);
            queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));
            queue.reverse();
        }
        0
    }

    fn set_cost(&mut self, x: usize, y: usize, cost: u64) {
        for i in 0..self.edges[x].len() {
            if self.edges[x][i].0 == y {
                self.edges[x][i].1 = cost
            }
        }
        for i in 0..self.edges[y].len() {
            if self.edges[y][i].0 == x {
                self.edges[y][i].1 = cost
            }
        }
    }
}

const MODULO: u64 = 1_000_000_007;

#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
struct BigPrimeRing {
    inner: u64,
}

impl<T> From<T> for BigPrimeRing
where
    T: Into<u64>,
{
    fn from(n: T) -> Self {
        Self {
            inner: n.into() % MODULO,
        }
    }
}

impl<T> std::ops::Add<T> for BigPrimeRing
where
    T: Into<Self>,
{
    type Output = BigPrimeRing;
    fn add(self, rhs: T) -> Self::Output {
        Self {
            inner: (self.inner + rhs.into().inner) % MODULO,
        }
    }
}

impl<T> std::ops::AddAssign<T> for BigPrimeRing
where
    T: Into<Self>,
{
    fn add_assign(&mut self, rhs: T) {
        self.inner += rhs.into().inner;
        self.inner %= MODULO;
    }
}

impl<T> std::ops::Sub<T> for BigPrimeRing
where
    T: Into<Self>,
{
    type Output = BigPrimeRing;
    fn sub(self, rhs: T) -> Self::Output {
        Self {
            inner: (self.inner + MODULO - rhs.into().inner) % MODULO,
        }
    }
}

impl<T> std::ops::SubAssign<T> for BigPrimeRing
where
    T: Into<Self>,
{
    fn sub_assign(&mut self, rhs: T) {
        self.inner += MODULO;
        self.inner -= rhs.into().inner;
        self.inner %= MODULO;
    }
}

impl<T> std::ops::Mul<T> for BigPrimeRing
where
    T: Into<Self>,
{
    type Output = BigPrimeRing;
    fn mul(self, rhs: T) -> Self::Output {
        Self {
            inner: (self.inner * rhs.into().inner) % MODULO,
        }
    }
}

impl<T> std::ops::MulAssign<T> for BigPrimeRing
where
    T: Into<Self>,
{
    fn mul_assign(&mut self, rhs: T) {
        self.inner *= rhs.into().inner;
        self.inner %= MODULO;
    }
}

impl BigPrimeRing {
    fn inverse(self) -> Self {
        if self.inner == 0 {
            return self;
        }
        let (_g, mut x, _y) = egcd(self.inner as i64, MODULO as i64);
        if x < 0 {
            x += MODULO as i64;
        }
        Self { inner: x as u64 }
    }
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (a, b) = read_2::<u64, u64>();
    let mut res = 1;
    'lop: for i in (a + 1)..=b {
        res *= i;
        res %= 10;
        if res == 0 {
            break 'lop;
        }
    }
    println!("{}", res);
    Ok(())
}

// Basics

#![allow(unused_imports)]

use std::mem;
use std::io;
use std::string;
use std::cmp::*;
use std::collections::*;

fn load() -> Vec<i64> {
    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("Failed to read line");
    let vec: Vec<&str> = line.split(" ").collect();
    let mut data: Vec<i64> = Vec::new();
    for i in vec {
        let el: i64 = i.trim().parse().unwrap();
        data.push(el);
    }
    data
}

fn main() {
    let w = load();
    let (a, b) = (w[0], w[1]);
    if b - a >= 10 {
        println!("0");
    } else {
        let mut end = 1;
        for i in (a + 1)..(b + 1) {
            end *= i % 10;
        }
        println!("{}", (end % 10));
    }
}

//
//mod strings;
//
//fn main() {
//    strings_sample();
//}

// Basics

#![allow(unused_imports)]

use std::mem;
use std::io;
use std::string;
use std::cmp::*;
use std::collections::*;

fn load() -> Vec<i32> {
    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("Failed to read line");
    let vec: Vec<&str> = line.split(" ").collect();
    let mut data: Vec<i32> = Vec::new();
    for i in vec {
        let el: i32 = i.trim().parse().unwrap();
        data.push(el);
    }
    data
}

fn main() {
    let w = load();
    let (a, b) = (w[0], w[1]);
    if b - a >= 10 {
        println!("0");
    } else {
        let mut end = 1;
        for i in (a + 1)..(b + 1) {
            end *= i;
        }
        println!("{}", (end % 10));
    }
}

//
//mod strings;
//
//fn main() {
//    strings_sample();
//}


// https://codeforces.com/contest/1271/problem/A
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: i64, b: i64, c: i64, d: i64,
        t1: i64, t2: i64
    };

    let mut best = 0;
    for i in 0..d+1 {
        best = max(best, t1*min(a, i)+t2*(min(min(b,c),d-i)));
    }

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

use std::io::stdin;
use std::cmp::max;
use std::cmp::min;

fn main() {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut a: i64 = str.trim().parse().unwrap();
    str.clear();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut b: i64 = str.trim().parse().unwrap();
    str.clear();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut c: i64 = str.trim().parse().unwrap();
    str.clear();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut d: i64 = str.trim().parse().unwrap();
    str.clear();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut e: i64 = str.trim().parse().unwrap();
    str.clear();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut f: i64 = str.trim().parse().unwrap();
    str.clear();
    b = min (b, c);
    if e > f {
        println!("{}", min(d, a) * e + min(d - min(d,a) ,b) * f);
    }
    else {
        println!("{}", min(d, b) * f + min(d - min(d,b) ,a) * e);
    }

}

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::cmp::*;

fn run() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        d: i32,
        e: i32,
        f: i32,
    }
    let mut ans = 0;
    for x in 0..=min(a, d) {
        let mut val = 0;
        val += e * x;
        val += f * min(b, min(c, d - x));
        ans = max(ans, val);
    }
    println!("{}", ans);
}

fn main() {
    run();
}

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[macro_export]
macro_rules ! chmax { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: max ( $ x ,$ v ) ; ) + } ; }
#[macro_export]
macro_rules ! chmin { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: min ( $ x ,$ v ) ; ) + } ; }
#[macro_export]
macro_rules ! max { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: max ( $ x , max ! ( $ ( $ xs ) ,+ ) ) } ; }
#[macro_export]
macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: min ( $ x , min ! ( $ ( $ xs ) ,+ ) ) } ; }
#[macro_export]
macro_rules ! dvec { ( $ t : expr ; $ len : expr ) => { vec ! [ $ t ; $ len ] } ; ( $ t : expr ; $ len : expr , $ ( $ rest : expr ) ,* ) => { vec ! [ dvec ! ( $ t ; $ ( $ rest ) ,* ) ; $ len ] } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[macro_export]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut parser = Parser :: from_str ( $ s ) ; input_inner ! { parser , $ ( $ r ) * } } ; ( parser = $ parser : ident , $ ( $ r : tt ) * ) => { input_inner ! { $ parser , $ ( $ r ) * } } ; ( new_stdin_parser = $ parser : ident , $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let reader = std :: io :: BufReader :: new ( stdin . lock ( ) ) ; let mut $ parser = Parser :: new ( reader ) ; input_inner ! { $ parser , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { input ! { new_stdin_parser = parser , $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! input_inner { ( $ parser : ident ) => { } ; ( $ parser : ident , ) => { } ; ( $ parser : ident , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ parser , $ t ) ; input_inner ! { $ parser $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! read_value { ( $ parser : ident , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ parser , $ t ) ) ,* ) } ; ( $ parser : ident , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ parser , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ parser : ident , chars ) => { read_value ! ( $ parser , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ parser : ident , usize1 ) => { read_value ! ( $ parser , usize ) - 1 } ; ( $ parser : ident , $ t : ty ) => { $ parser . next ::<$ t > ( ) . expect ( "Parse error" ) } ; }
use std::io;
use std::io::BufRead;
use std::str;
pub struct Parser<R> {
    reader: R,
    buf: Vec<u8>,
    pos: usize,
}
impl Parser<io::Empty> {
    pub fn from_str(s: &str) -> Parser<io::Empty> {
        Parser {
            reader: io::empty(),
            buf: s.as_bytes().to_vec(),
            pos: 0,
        }
    }
}
impl<R: BufRead> Parser<R> {
    pub fn new(reader: R) -> Parser<R> {
        Parser {
            reader: reader,
            buf: vec![],
            pos: 0,
        }
    }
    pub fn update_buf(&mut self) {
        self.buf.clear();
        self.pos = 0;
        loop {
            let (len, complete) = {
                let buf2 = self.reader.fill_buf().unwrap();
                self.buf.extend_from_slice(buf2);
                let len = buf2.len();
                if len == 0 {
                    break;
                }
                (len, buf2[len - 1] <= 0x20)
            };
            self.reader.consume(len);
            if complete {
                break;
            }
        }
    }
    pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> {
        loop {
            let mut begin = self.pos;
            while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                begin += 1;
            }
            let mut end = begin;
            while end < self.buf.len() && (self.buf[end] > 0x20) {
                end += 1;
            }
            if begin != self.buf.len() {
                self.pos = end;
                return str::from_utf8(&self.buf[begin..end]).unwrap().parse::<T>();
            } else {
                self.update_buf();
            }
        }
    }
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    input!{
        a:usize,
        b:usize,
        c:usize,
        d:usize,
        e:usize,
        f:usize,
    }

    let mut maxcost = 0;
    for i in 0..d+1 {
        let mut cost = 0;
        if a < i {
            continue;
        }
        cost += e*i;

        let rest = d-i;
        let mut j = min(min(b,c),rest);

        cost += f*j;

        chmax!(maxcost, cost);
    }
    println!("{}", maxcost);
}

fn read_u32() -> u32 {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().parse().unwrap()
}

fn convert_a(a: &mut u32, d: &mut u32, cost: u32) -> u32 {

    let a_amount = *a.min(d);
    *a -= a_amount;
    *d -= a_amount;

    a_amount * cost
}

fn convert_b(b: &mut u32, c: &mut u32, d: &mut u32, cost: u32) -> u32 {

    let b_amount = *b.min(c).min(d);
    *b -= b_amount;
    *c -= b_amount;
    *d -= b_amount;

    b_amount * cost
}

fn main() {
    let mut a = read_u32();
    let mut b = read_u32();
    let mut c = read_u32();
    let mut d = read_u32();

    let cost_a = read_u32();
    let cost_b = read_u32();

    let mut rev = 0;

    if cost_a > cost_b {

        rev += convert_a(&mut a, &mut d, cost_a);
        rev += convert_b(&mut b, &mut c, &mut d, cost_b);

    } else {

        rev += convert_b(&mut b, &mut c, &mut d, cost_b);
        rev += convert_a(&mut a, &mut d, cost_a);

    }

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

#![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 main() {
    let a = read::<i64>();
    let b = read::<i64>();
    let c = read::<i64>();
    let b = min(b, c);
    let mut d = read::<i64>();
    let e = read::<i64>();
    let f = read::<i64>();
    if e > f {
        let eset = min(a, d);
        d -= eset;
        let fset = min(b, d);
        println!("{}", e * eset + f * fset);
    } else {
        let fset = min(b, d);
        d -= fset;
        let eset = min(a, d);
        println!("{}", e * eset + f * fset);
    }
}

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()
}