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

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 partial_max<T>(v: impl Iterator<Item = T>) -> impl Iterator<Item = T>
where
    T: Default + Ord + Copy,
{
    v.scan(T::default(), |state, x| {
        *state = max(*state, x);
        Some(*state)
    })
}

fn partial_min(v: impl Iterator<Item = u64>) -> impl Iterator<Item = u64> {
    v.scan(std::u64::MAX, |state, x| {
        *state = min(*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;

macro_rules! max_with {
    ($x: expr, $y: expr) => {
        $x = max($x, $y)
    };
}

macro_rules! min_with {
    ($x: expr, $y: expr) => {
        $x = max($x, $y)
    };
}

fn is_prime(n: u64) -> bool {
    factorize(n).len() == 1
}

fn combination(n: u64, k: u64, m: u64) -> u64 {
    if n == 0 {
        return 1;
    }
    if k == 0 || k == n {
        return 1;
    }
    let new_k = if n - k < k { n - k } else { k };
    let mut res = 1;
    for i in ((n - new_k) + 1)..=n {
        res *= i;
        res %= m;
    }
    let mut den = 1;
    for i in 1..=(new_k) {
        den *= i;
        den %= m;
    }
    let (_one, inverse, _c) = egcd(den as i64, m as i64);
    let inverse = if inverse < 0 {
        m as i64 + inverse
    } else {
        inverse
    } as u64;
    //println!("inv: {} {}", den, inverse);
    res *= inverse;
    res %= m;
    res
}

use std::collections::HashSet;
use std::iter::FromIterator;

fn n_to_vec(n: u64, l: usize) -> Vec<u8> {
    let mut res = vec![0; l];
    let mut n = n;
    for i in (0..l).rev() {
        if n % 2 == 1 {
            res[i] = 1;
        }
        n /= 2;
    }
    res
}

fn vec_to_n(v: Vec<u8>) -> u64 {
    let mut res = 0;
    for i in 0..v.len() {
        res *= 2;
        if v[i] == 1 {
            res += 1;
        }
    }
    res
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (mut x1, mut y1, mut x2, mut y2) = read_4::<u32, u32, u32, u32>();
    let (x3, y3, x4, y4) = read_4::<u32, u32, u32, u32>();
    let (x5, y5, x6, y6) = read_4::<u32, u32, u32, u32>();

    // lower edge
    if x3 <= x1 && x2 <= x4 {
        if y3 <= y1 {
            y1 = max(y1, y4);
        }
        if y2 <= y4 {
            y2 = min(y2, y3);
        }
    }
    if x5 <= x1 && x2 <= x6 {
        if y5 <= y1 {
            y1 = max(y1, y6);
        }
        if y2 <= y6 {
            y2 = min(y2, y5);
        }
    }
    // left edge
    if y3 <= y1 && y2 <= y4 {
        if x3 <= x1 {
            x1 = max(x1, x4);
        }
        if x2 <= x4 {
            x2 = min(x2, x3);
        }
    }
    if y5 <= y1 && y2 <= y6 {
        if x5 <= x1 {
            x1 = max(x1, x6);
        }
        if x2 <= x6 {
            x2 = min(x2, x5);
        }
    }
    //println!("{} {} {} {} ", x1, x2, y1, y2);

    if x1 < x2 && y1 < y2 {
        println!("YES")
    } else {
        println!("NO")
    }
    Ok(())
}


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

pub struct Scanner {
  buffer: Vec<String>
}

impl Scanner {
  pub fn new() -> Scanner {
    Scanner { buffer: Vec::new() }
  }

  pub 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();
      std::io::stdin().read_line(&mut input).expect("Failed read");
      self.buffer = input.split_whitespace().rev().map(String::from).collect();
    }
  }
}

struct Square {
 x1: u32,
 y1: u32,
 x2: u32,
 y2: u32,
}

impl Square {
  fn from(scan: &mut Scanner) -> Square {
    Square::new(scan.next(), scan.next(), scan.next(), scan.next())
  }

  fn new(x1: u32, y1: u32, x2: u32, y2: u32) -> Square {
    if x1 <= x2 && y1 <= y2 {
      Square { x1, y1, x2, y2 }
    } else {
      Square { x1: 0, y1: 0, x2: 0, y2: 0 }
    }
  }

  fn intersect(&self, other: &Square) -> Square {
    Square::new(max(self.x1, other.x1), max(self.y1, other.y1),
                min(self.x2, other.x2), min(self.y2, other.y2))
  }

  fn area(&self) -> u64 {
    ((self.x2 - self.x1) as u64) * ((self.y2 - self.y1) as u64)
  }
}

fn main() {
  let stdout = std::io::stdout();
  let mut out = std::io::BufWriter::new(stdout.lock());
  let mut scan = Scanner::new();

  let white = Square::from(&mut scan);
  let black1 = Square::from(&mut scan);
  let black2 = Square::from(&mut scan);
  let intersect1 = white.intersect(&black1);
  let intersect2 = white.intersect(&black2);
  let covered = intersect1.area() + intersect2.area()
                - intersect1.intersect(&intersect2).area();
  if white.area() > covered {
    writeln!(out, "YES").unwrap();
  } else {
    writeln!(out, "NO").unwrap();
  }
}


#[allow(unused_imports)]
use std::io::stdin;

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

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

type Point = (i128, i128);

fn intersect(a: &Point, b: &Point, c: &Point, d: &Point) -> (Point, Point) {
    let l = max(min(a.0, b.0), min(c.0, d.0));
    let r = min(max(a.0, b.0), max(c.0, d.0));
    let u = min(max(a.1, b.1), max(c.1, d.1));
    let d = max(min(a.1, b.1), min(c.1, d.1));
    if l >= r || u <= d {
        ((0,0), (0,0))
    } else {
        ((l, d), (r, u))
    }
}

fn area(x: &Point, y: &Point) -> i128 {
    (x.0 - y.0).abs() * (x.1 - y.1).abs()
}

fn main() {
    let mut scan = Scanner::default();
    let (p1, p2): (Point, Point) = ((scan.next::<i128>(), scan.next::<i128>()),(scan.next::<i128>(), scan.next::<i128>()));
    let (p3, p4): (Point, Point) = ((scan.next::<i128>(), scan.next::<i128>()),(scan.next::<i128>(), scan.next::<i128>()));
    let (p5, p6): (Point, Point) = ((scan.next::<i128>(), scan.next::<i128>()),(scan.next::<i128>(), scan.next::<i128>()));
    let wb1 = intersect(&p1, &p2, &p3, &p4);
    let wb2 = intersect(&p1, &p2, &p5, &p6);
    let sb1b2 = intersect(&wb1.0, &wb1.1, &wb2.0, &wb2.1);
    let a = area(&p1, &p2);
    let b = area(&wb1.0, &wb1.1);
    let c = area(&wb2.0, &wb2.1);
    let d = area(&sb1b2.0, &sb1b2.1);
    println!("{}", if a > b + c -d { "YES" } else { "NO" });
}


#[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;
#[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() {
    input!{
        w0: (i64,i64,i64,i64),
        b0: (i64,i64,i64,i64),
        b1: (i64,i64,i64,i64),
    }

    let mut xs = vec![];
    xs.push(w0.0);
    xs.push(w0.2);
    xs.push(b0.0);
    xs.push(b0.2);
    xs.push(b1.0);
    xs.push(b1.2);
    xs.sort();
    let mut x_compress = HashMap::new();
    let mut x_decompress = HashMap::new();
    let mut cur_x=0;
    for x in xs {
        if !x_compress.contains_key(&x) {
            x_compress.entry(x).or_insert(cur_x);
            x_decompress.entry(cur_x).or_insert(x);
            cur_x+=1;
        }
    }

    let mut ys = vec![];
    ys.push(w0.1);
    ys.push(w0.3);
    ys.push(b0.1);
    ys.push(b0.3);
    ys.push(b1.1);
    ys.push(b1.3);
    ys.sort();
    let mut y_compress = HashMap::new();
    let mut y_decompress = HashMap::new();
    let mut cur_y=0;
    for y in ys {
        if !y_compress.contains_key(&y) {
            y_compress.entry(y).or_insert(cur_y);
            y_decompress.entry(cur_y).or_insert(y);
            cur_y+=1;
        }
    }

    let mut table = vec![vec![false; cur_y-1]; cur_x-1];
    let x_comp = |x: i64| {
        x_compress.get(&x).unwrap().clone() as usize
    };
    let y_comp = |y: i64| {
        y_compress.get(&y).unwrap().clone() as usize
    };
    for x in x_comp(b0.0)..x_comp(b0.2) {
        for y in y_comp(b0.1)..y_comp(b0.3) {
            table[x][y]=true;
        }
    }
    for x in x_comp(b1.0)..x_comp(b1.2) {
        for y in y_comp(b1.1)..y_comp(b1.3) {
            table[x][y]=true;
        }
    }
    let mut ok = false;
    for x in x_comp(w0.0)..x_comp(w0.2) {
        for y in y_comp(w0.1)..y_comp(w0.3) {
            if !table[x][y] {
                ok=true;
                break;
            }
        }
    }

    if ok {
        println!("YES");
    } else {
        println!("NO");
    }
}


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

// ここまで

fn run() {
    input! {
        p: [(u32, u32, u32, u32); 3],
    }
    let mut z = vec![];
    for &(a, b, c, d) in &p {
        z.push(a);
        z.push(b);
        z.push(c);
        z.push(d);
        z.push(c - 1);
        z.push(d - 1);
    }
    z.sort();
    z.dedup();
    let n = z.len();
    let mut ok = vec![vec![true; n]; n];
    for &(a, b, c, d) in &p[1..] {
        let a = z.binary_search(&a).unwrap();
        let b = z.binary_search(&b).unwrap();
        let c = z.binary_search(&c).unwrap();
        let d = z.binary_search(&d).unwrap();
        for i in a..c {
            for j in b..d {
                ok[i][j] = false;
            }
        }
    }
    let (a, b, c, d) = p[0];
    let a = z.binary_search(&a).unwrap();
    let b = z.binary_search(&b).unwrap();
    let c = z.binary_search(&c).unwrap();
    let d = z.binary_search(&d).unwrap();
    for i in a..c {
        for j in b..d {
            if ok[i][j] {
                println!("YES");
                return;
            }
        }
    }
    println!("NO");
}

fn main() {
    run();
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, m: usize, a: usize, b: usize,
        g0: i64, x: i64, y: i64, z: i64,
    }
    let mut d = vec![vec![0; m]; n];
    let mut state = g0;
    for i in 0..n {
        for j in 0..m {
            d[i][j] = state;
            state = (x * state + y) % z;
        }
    }
    let mut slide = vec![vec![0; m]; n];
    for i in 0..n {
        let mut st = VecDeque::<(i64, usize)>::new();
        for j in 0..m {
            if j >= b {
                while let Some(x) = st.pop_front() {
                    if x.1 > j - b {
                        st.push_front(x);
                        break;
                    }
                }
            }
            while let Some(x) = st.pop_back() {
                if x.0 < d[i][j] {
                    st.push_back(x);
                    break;
                }
            }
            st.push_back((d[i][j], j));
            slide[i][j] = st.front().unwrap().0;
        }
    }
    let mut ans = vec![vec![0; m]; n];
    for j in b - 1..m {
        let mut st = VecDeque::<(i64, usize)>::new();
        for i in 0..n {
            if i >= a {
                while let Some(x) = st.pop_front() {
                    if x.1 > i - a {
                        st.push_front(x);
                        break;
                    }
                }
            }
            while let Some(x) = st.pop_back() {
                if x.0 < slide[i][j] {
                    st.push_back(x);
                    break;
                }
            }
            st.push_back((slide[i][j], i));
            ans[i][j] = st.front().unwrap().0;
        }
    }
    let mut tot: i64 = 0;
    for i in a - 1..n {
        for j in b - 1..m {
            tot += ans[i][j];
        }
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};
use std::collections::VecDeque;

struct SlidingWindowQ<F> {
    q: VecDeque<usize>,
    window: usize,
    f: F
}

impl<F> SlidingWindowQ<F>
where
    F: Fn(usize,usize) -> bool
{
    fn new(window: usize, f: F) -> Self
    {
        SlidingWindowQ {
            q: VecDeque::new(),
            window: window,
            f: f
        }
    }

    fn push(&mut self, i: usize) {
        while self.q.len() > 0 {
            let j = *self.q.back().unwrap();

            if (self.f)(i, j) {
                self.q.pop_back();
            } else {
                break;
            }
        }
        self.q.push_back(i);

        let j = *self.q.front().unwrap();
        if i >= self.window && j == i - self.window {
            self.q.pop_front();
        }
    }

    fn front(&self) -> usize {
        *self.q.front().unwrap()
    }
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      a: usize,
      b: usize,
      g0: u64,
      x: u64,
      y: u64,
      z: u64,
    }

    let mut hs = vec![0; n*m];
    let mut g = g0;
    for i in 0..n*m {
        hs[i] = g;
        g = (g * x  + y) % z;
    }

    const INF: u64 = 1 << 50;
    let mut mins = vec![INF; n*m];

    // スライド最小値
    use std::collections::VecDeque;
    for i in 0..n {
        let f = |a, b| hs[i*m + a] <= hs[i*m + b];
        let mut q = SlidingWindowQ::new(b, f);
        for j in 0..m {
            q.push(j);
            if j >= b-1 {
                let min_j = q.front();
                mins[i*m + j] = hs[i*m + min_j];
            }
        }
    }

    let mut ans = 0;
    assert!(mins.len() == n*m);
    for j in b-1..m {
        let f = |a, b| mins[a*m + j] <= mins[b*m + j];
        let mut q = SlidingWindowQ::new(a, f);
        for i in 0..n {
            q.push(i);
            if i >= a-1 {
                let min_i = q.front();
                let v = mins[min_i * m + j];
                ans += v;
            }
        }
    }
    puts!("{}", ans);
}


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

pub mod ds {
    use std::collections::VecDeque;
    pub struct SlidingWindowQ<F> {
        q: VecDeque<usize>,
        window: usize,
        cur: usize,
        f: F,
    }
    impl<F> SlidingWindowQ<F>
    where
        F: Fn(usize, usize) -> bool,
    {
        pub fn new(window: usize, f: F) -> Self {
            SlidingWindowQ {
                q: VecDeque::new(),
                window: window,
                f: f,
                cur: 0,
            }
        }
        pub fn next(&mut self) -> usize {
            let i = self.cur;
            self.cur += 1;
            while self.q.len() > 0 {
                let j = *self.q.back().unwrap();
                if (self.f)(i, j) {
                    self.q.pop_back();
                } else {
                    break;
                }
            }
            self.q.push_back(i);
            let j = *self.q.front().unwrap();
            if i >= self.window && j == i - self.window {
                self.q.pop_front();
            }
            self.front()
        }
        pub fn front(&self) -> usize {
            *self.q.front().unwrap()
        }
    }
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      a: usize,
      b: usize,
      g0: u64,
      x: u64,
      y: u64,
      z: u64,
    }

    let mut hs = vec![0; n*m];
    let mut g = g0;
    for i in 0..n*m {
        hs[i] = g;
        g = (g * x  + y) % z;
    }

    const INF: u64 = 1 << 50;
    let mut mins = vec![INF; n*m];

    use ds::SlidingWindowQ;

    // スライド最小値
    for i in 0..n {
        let f = |a, b| hs[i*m + a] <= hs[i*m + b];
        let mut q = SlidingWindowQ::new(b, f);
        for j in 0..m {
            let min_idx = q.next();
            if j >= b-1 {
                mins[i*m + j] = hs[i*m + min_idx];
            }
        }
    }

    let mut ans = 0;
    assert!(mins.len() == n*m);
    for j in b-1..m {
        let f = |a, b| mins[a*m + j] <= mins[b*m + j];
        let mut q = SlidingWindowQ::new(a, f);
        for i in 0..n {
            let min_idx = q.next();
            if i >= a-1 {
                let v = mins[min_idx * m + j];
                ans += v;
            }
        }
    }
    puts!("{}", ans);
}


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};
use std::collections::VecDeque;

struct SlidingWindowQ<F> {
    q: VecDeque<usize>,
    window: usize,
    f: F
}

impl<F> SlidingWindowQ<F>
where
    F: Fn(usize,usize) -> bool
{
    fn new(window: usize, f: F) -> Self
    {
        SlidingWindowQ {
            q: VecDeque::new(),
            window: window,
            f: f
        }
    }

    fn push(&mut self, i: usize) {
        while self.q.len() > 0 {
            let j = *self.q.back().unwrap();

            if (self.f)(i, j) {
                self.q.pop_back();
            } else {
                break;
            }
        }
        self.q.push_back(i);

        let j = *self.q.front().unwrap();
        if i >= self.window && j == i - self.window {
            self.q.pop_front();
        }
    }

    fn front(&self) -> usize {
        *self.q.front().unwrap()
    }
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      a: usize,
      b: usize,
      g0: u64,
      x: u64,
      y: u64,
      z: u64,
    }

    let mut hs = vec![0; n*m];
    let mut g = g0;
    for i in 0..n*m {
        hs[i] = g;
        g = (g * x  + y) % z;
    }

    const INF: u64 = 1 << 50;
    let mut mins = vec![INF; n*(m-b+1)];

    // スライド最小値
    use std::collections::VecDeque;
    for i in 0..n {
        let f = |a, b| hs[i*m + a] <= hs[i*m + b];
        let mut q = SlidingWindowQ::new(b, f);
        for j in 0..m {
            q.push(j);
            if j >= b-1 {
                let min_j = q.front();
                let idx = i*(m-b+1) + j+1-b;
                mins[idx] = hs[i*m + min_j];
            }
        }
    }

    let mut ans = 0;
    let m = m-b+1;
    assert!(mins.len() == n*m);
    for j in 0..m {
        let f = |a, b| mins[a*m + j] <= mins[b*m + j];
        let mut q = SlidingWindowQ::new(a, f);
        for i in 0..n {
            q.push(i);
            if i >= a-1 {
                let min_i = q.front();
                let v = mins[min_i * m + j];
                ans += v;
            }
        }
    }
    puts!("{}", ans);
}


// ---------- begin Foldable Deque ----------
struct FoldableDeque<T, F> {
    front: Vec<(T, T)>,
    back: Vec<(T, T)>,
    op: F,
}

#[allow(dead_code)]
impl<T, F> FoldableDeque<T, F>
where T: Clone,
      F: Fn(&T, &T) -> T,
{
    fn new(op: F) -> Self {
        FoldableDeque {
            front: Vec::new(),
            back: Vec::new(),
            op: op,
        }
    }
    fn find(&self) -> Option<T> {
        match (self.front.last(), self.back.last()) {
            (Some(a), Some(b)) => Some((self.op)(&a.1, &b.1)),
            (Some(a), None) => Some(a.1.clone()),
            (None, Some(b)) => Some(b.1.clone()),
            (None, None) => None,
        }
    }
    fn clear(&mut self) {
        self.front.clear();
        self.back.clear();
    }
    fn len(&self) -> usize {
        self.front.len() + self.back.len()
    }
    fn push_back(&mut self, val: T) {
        let sum = if let Some(p) = self.back.last() {
            (self.op)(&p.1, &val)
        } else {
            val.clone()
        };
        self.back.push((val, sum));
    }
    fn push_front(&mut self, val: T) {
        let sum = if let Some(p) = self.front.last() {
            (self.op)(&val, &p.1)
        } else {
            val.clone()
        };
        self.front.push((val, sum));
    }
    fn pop_front(&mut self) -> Option<T> {
        if self.len() == 0 {
            return None;
        }
        if self.front.is_empty() {
            let a = self.back.clone();
            let m = (self.back.len() + 1) / 2;
            self.back.clear();
            let (f, b) = a.split_at(m);
            for v in f.iter().rev() {
                self.push_front(v.0.clone());
            }
            for v in b.iter() {
                self.push_back(v.0.clone());
            }
        }
        self.front.pop().map(|p| p.0)
    }
    fn pop_back(&mut self) -> Option<T> {
        if self.len() == 0 {
            return None;
        }
        if self.back.is_empty() {
            let a = self.front.clone();
            let m = self.front.len() / 2;
            self.front.clear();
            let (f, b) = a.split_at(m);
            for v in f.iter().rev() {
                self.push_front(v.0.clone());
            }
            for v in b.iter() {
                self.push_back(v.0.clone());
            }
        }
        self.back.pop().map(|p| p.0)
    }
}
// ---------- end Foldable Deque ----------

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let h: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();
    let r: usize = it.next().unwrap().parse().unwrap();
    let c: usize = it.next().unwrap().parse().unwrap();
    let mut g: u64 = it.next().unwrap().parse().unwrap();
    let x: u64 = it.next().unwrap().parse().unwrap();
    let y: u64 = it.next().unwrap().parse().unwrap();
    let z: u64 = it.next().unwrap().parse().unwrap();
    let mut a = vec![0u32; h * w];
    for a in a.iter_mut() {
        *a = g as u32;
        g = (g * x + y) % z;
    }
    let mut b = vec![0u32; h * (w - c + 1)];
    let op = |a: &u32, b: &u32| std::cmp::min(*a, *b);
    let mut q = FoldableDeque::new(op);
    for (i, a) in a.chunks(w).enumerate() {
        q.clear();
        for a in a.iter().take(c - 1) {
            q.push_back(*a);
        }
        for (b, a) in b[i..].iter_mut().step_by(h).zip(a.iter().skip(c - 1)) {
            q.push_back(*a);
            *b = q.find().unwrap();
            q.pop_front();
        }
    }
    let mut ans = 0u64;
    for b in b.chunks(h) {
        q.clear();
        for b in b.iter().take(r - 1) {
            q.push_back(*b);
        }
        for b in b.iter().skip(r - 1) {
            q.push_back(*b);
            ans += q.find().unwrap() as u64;
            q.pop_front();
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


// ---------- begin Foldable Deque ----------
struct FoldableDeque<T, F> {
    front: Vec<(T, T)>,
    back: Vec<(T, T)>,
    op: F,
}

#[allow(dead_code)]
impl<T, F> FoldableDeque<T, F>
where T: Clone,
      F: Fn(&T, &T) -> T,
{
    fn new(op: F) -> Self {
        FoldableDeque {
            front: Vec::new(),
            back: Vec::new(),
            op: op,
        }
    }
    fn find(&self) -> Option<T> {
        match (self.front.last(), self.back.last()) {
            (Some(a), Some(b)) => Some((self.op)(&a.1, &b.1)),
            (Some(a), None) => Some(a.1.clone()),
            (None, Some(b)) => Some(b.1.clone()),
            (None, None) => None,
        }
    }
    fn clear(&mut self) {
        self.front.clear();
        self.back.clear();
    }
    fn len(&self) -> usize {
        self.front.len() + self.back.len()
    }
    fn push_back(&mut self, val: T) {
        let sum = if let Some(p) = self.back.last() {
            (self.op)(&p.1, &val)
        } else {
            val.clone()
        };
        self.back.push((val, sum));
    }
    fn push_front(&mut self, val: T) {
        let sum = if let Some(p) = self.front.last() {
            (self.op)(&val, &p.1)
        } else {
            val.clone()
        };
        self.front.push((val, sum));
    }
    fn pop_front(&mut self) -> Option<T> {
        if self.len() == 0 {
            return None;
        }
        if self.front.is_empty() {
            let a = self.back.clone();
            let m = (self.back.len() + 1) / 2;
            self.back.clear();
            let (f, b) = a.split_at(m);
            for v in f.iter().rev() {
                self.push_front(v.0.clone());
            }
            for v in b.iter() {
                self.push_back(v.0.clone());
            }
        }
        self.front.pop().map(|p| p.0)
    }
    fn pop_back(&mut self) -> Option<T> {
        if self.len() == 0 {
            return None;
        }
        if self.back.is_empty() {
            let a = self.front.clone();
            let m = self.front.len() / 2;
            self.front.clear();
            let (f, b) = a.split_at(m);
            for v in f.iter().rev() {
                self.push_front(v.0.clone());
            }
            for v in b.iter() {
                self.push_back(v.0.clone());
            }
        }
        self.back.pop().map(|p| p.0)
    }
}
// ---------- end Foldable Deque ----------

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let h: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();
    let r: usize = it.next().unwrap().parse().unwrap();
    let c: usize = it.next().unwrap().parse().unwrap();
    let mut g: u64 = it.next().unwrap().parse().unwrap();
    let x: u64 = it.next().unwrap().parse().unwrap();
    let y: u64 = it.next().unwrap().parse().unwrap();
    let z: u64 = it.next().unwrap().parse().unwrap();
    let mut a = vec![vec![0u32; w]; h];
    for a in a.iter_mut() {
        for a in a.iter_mut() {
            *a = g as u32;
            g = (g * x + y) % z;
        }
    }
    let op = |a: &u32, b: &u32| std::cmp::min(*a, *b);
    let mut q = FoldableDeque::new(op);
    for a in a.iter_mut() {
        q.clear();
        for a in a.iter().take(c - 1) {
            q.push_back(*a);
        }
        for j in (c - 1)..w {
            q.push_back(a[j]);
            a[j - c + 1] = q.find().unwrap();
            q.pop_front();
        }
    }
    let mut ans = 0u64;
    for j in 0..(w - c + 1) {
        q.clear();
        for i in 1..r {
            q.push_back(a[i - 1][j]);
        }
        for i in (r - 1)..h {
            q.push_back(a[i][j]);
            ans += q.find().unwrap() as u64;
            q.pop_front();
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


use std::io;

fn main() {
    let mut guess = String::new();
    let mut i_2:i32 = 0;
    for i in 0_i32..5 {
        io::stdin()
        .read_line(&mut guess)
        .expect("Failed to read line");

        for elem in guess.chars() {
            if elem == '1'{
                let aux_i = if (i_2 % 5) == 0 {i_2 + 1} else {i_2};
                let line = (aux_i as f32/5.0).ceil() as i32;
                let col = i_2%5;
                let mut mv = col-2;
                mv = mv.abs() + (line - 3).abs();
                print!("{}",mv);
                std::process::exit(0);
            }
            else if elem == '0'{
                i_2 +=1;
            }
        }
        guess = String::new();
    }
}


use std::io;

#[derive(Debug)]
struct Matrix {
    origin: (usize, usize),
    target: (usize, usize),
}

impl Matrix {
    fn new(row: usize, col: usize) -> Matrix {
        Matrix {
            origin: (row, col),
            target: (3, 3),
        }
    }

    fn compute(&mut self) -> i64 {
        let row_diff = self.origin.0 as i64 - self.target.0 as i64;
        let col_diff = self.origin.1 as i64 - self.target.1 as i64;
        row_diff.abs() + col_diff.abs()
    }
}

fn main() {
    let mut lines = vec![String::new(); 5];

    for i in 0..5 {
        let _ = io::stdin().read_line(&mut lines[i]);
    }

    let mut rows: Vec<Vec<i32>> = vec![vec![0; 5]; 5];
    for (index, line) in lines.iter().enumerate() {
        rows[index] = line
            .split_whitespace()
            .map(|item| item.parse().unwrap())
            .collect();
    }

    let mut m = Matrix::new(0, 0);
    for (idx_r, row) in rows.iter().enumerate() {
        for (idx_c, elem) in row.iter().enumerate() {
            if elem == &1 {
                m = Matrix::new(idx_r + 1, idx_c + 1);
                break;
            }
        }
    }

    println!("{}", m.compute());
}


use std::io::{BufWriter, stdin, stdout, Write};

#[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 scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());

    let mut x1 = -1;
    let mut y1 = -1;

    for y in 1..6 {
      for x in 1..6 {
	    let n = scan.next::<u8>();
        if n == 1 {
            x1 = x;
            y1 = y;
        }
      }
    }

    writeln!(out, "{}", (x1-3i8).abs() + (y1-3i8).abs()).expect("fail");
}


fn main() {
    let mut count: i64 = 1;
    // let mut column: i64 = 0;
    let mut position: i64 = 0;
while count < 6 {
    let mut input = String::new();
        std::io::stdin()
                    .read_line(&mut input)
                    .expect("Value not found");

    let input: Vec<i64> = input
                            .split_whitespace()
                            .map(|s| s.parse()
                                .expect("Parse Error"))
                            .collect();
    // println!("{}",input.len());
        // let mut j = 0;
        // column += 1;
    for i in 0..input.len() {
            if input[i] == 1 {
                let j = i as i64;
                let first: i64 = 3 - count;
                // println!("first = {}", first);
                let f: i64 = first.abs();
                // println!("first.abs = {}", f);
                let second: i64 = 3 - j - 1;
                // println!("second = {}", second);
                let s: i64 = second.abs();
                // println!("second.abs = {}", s);
                position = f + s;
          }
 }
        count += 1;
 }
 println!("{}", position);
 }

// fn abs(x: isize) -> isize {
//     if x < 0 { x = x * -1}
//     else {x}
//     x

// }


pub fn main(){
    let input = input();
    let mut x = 0;
    let mut y = 0;
    for i in 0..5 {
        for j in 0..5 {
            if input[i][j] == 1 {
                x = i;
                y = j;
            }
        }
    }
    let mut dist = 0;
    dist += if x > 2 { x - 2 } else { 2 - x};
    dist += if y > 2 { y - 2 } else { 2 - y};
    println!("{}", dist);
}

fn input() -> Vec<Vec<u32>> {
    let mut vec = Vec::new();
    for _ in 0..5 {
        let mut input = String::new();
        std::io::stdin().read_line(&mut input);
        vec.push(input.split_whitespace()
            .map(|s| s.parse::<u32>().unwrap())
            .collect());
    }
    vec
}


fn main() {
    let stdin = std::io::stdin();

    let mut buf;
    let mut i = 0;
    let mut j = 0;

    for r in 0..5 {
        buf = String::new();
        stdin.read_line(&mut buf).ok().expect("Error!");
        let sbuf = buf.trim();

        let mut iter = sbuf.split_whitespace();

        for col in 0..5 {
            match iter.next() {
                Some(v) => {
                    if v == "1" {
                        j = col;
                        i = r;
                    }
                    ()
                }
                None => (),
            }
        }
    }

    let mut res;
    res = (2i32 - i).abs();
    res += (2i32 - j).abs();

    // println!("{} {}\n", i, j);

    println!("{}", res);

}


use std::io::stdin;

fn main() {
    for i in 0..5 {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();
        let arr = input.trim().split_whitespace()
            .map(|x| x.parse::<i32>().unwrap())
            .collect::<Vec<i32>>();
        for (j, &elem) in arr.iter().enumerate() {
            if elem == 1 {
                println!("{}", i32::abs(i as i32 - 2) + i32::abs(j as i32 - 2));
                return;
            }
        }
    }
}


use std::io;

fn main() -> io::Result<()> {
    let mut input = String::new();

    let mut one: (u8, u8) = (0, 0);
    for i in 0..5 {
        io::stdin().read_line(&mut input)?;
        let v = input
            .trim()
            .split_whitespace()
            .map(|x| x.parse::<u8>().unwrap())
            .collect::<Vec<u8>>();
        for (j, x) in v.iter().enumerate() {
            if *x == 1 {
                one = (i, j as u8);
            }
        }
        input.clear();
    }

    println!("{}", ((one.0 - 2) as i8).abs() + ((one.1 - 2) as i8).abs());

    Ok(())
}


use std::io::{self, prelude::*, Write};
use std::str;
use std::string::String;
use std::vec::Vec;

#[allow(unused_must_use)]
fn run<B: BufRead, W: Write>(mut reader: Scanner<B>, mut writer: W) {
    let mut numbers: Vec<i32> = reader.next_line().split('+').map(|n| n.parse().unwrap()).collect();
    numbers.sort_unstable();

    for i in 0..numbers.len() {
        write!(writer, "{}", numbers[i]);
        if i + 1 != numbers.len() {
            write!(writer, "+");
        }
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();

    let reader = Scanner::new(stdin.lock());
    let writer = io::BufWriter::new(stdout.lock());
    run(reader, writer);
    io::stdout().flush().unwrap();
}

pub struct Scanner<B> {
    reader: B,
    buffer_string: Vec<u8>,
    buffer_iterator: str::SplitWhitespace<'static>,
}

impl <B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        return Self {
            reader,
            buffer_string: Vec::new(),
            buffer_iterator: "".split_whitespace()
        };
    }

    pub fn next<T: str::FromStr>(&mut self) -> T {
        loop {
            //if buffer already exists, just use existing buffer
            if let Some(token) = self.buffer_iterator.next() {
                return token.parse().ok().expect("Fail to parse token");
            }

            //get new line
            self.buffer_string.clear();
            self.reader.read_until(b'\n', &mut self.buffer_string).expect("Failed to read");

            //split by white space
            self.buffer_iterator = unsafe {
                let slice = str::from_utf8_unchecked(&self.buffer_string);
                std::mem::transmute(slice.split_whitespace())
            };
        }
    }

    pub fn next_line(&mut self) -> String {
        //reset buffer
        self.buffer_iterator = "".split_whitespace();
        self.buffer_string.clear();

        let mut input: String = String::new();
        self.reader.read_line(&mut input).expect("Failed to read line");
        return input.trim().to_string();
    }
}


//spna-rust
#[allow(unused_imports)]
use std::io::{self,Read};

#[derive(Debug)]
struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T : Read>(mut reader : T) -> WordReader {
        let mut s = String::new();
        reader.read_to_string(&mut s).unwrap();
        WordReader { it : s
            .split_ascii_whitespace()
            .map(String::from).collect::<Vec<_>>()
            .into_iter()
        }
    }
    fn from_stdin() -> WordReader {
        WordReader::new(std::io::stdin())
    }
    fn s(&mut self) -> String {
        self.it.next().unwrap()
    }
    fn ab(&mut self) -> Vec<u8> {
        self.it.next().unwrap().into_bytes()
    }
    fn i(&mut self) -> i32 {
        self.it.next().unwrap().parse().unwrap()
    }
}

fn main() {
    let mut input = WordReader::from_stdin();
    let mut a = input.ab()
        .into_iter().step_by(2)
        .collect::<Vec<u8>>();
    a.sort();
    a.into_iter().enumerate().for_each(|(i,b)| {
        if i > 0 { print!("+"); }
        print!("{}", b as char);
    });
}


use std::io;

fn main() {
    let mut word = String::new();
    io::stdin().read_line(&mut word)
        .expect("Failed to read line");

    let snums = word.trim().split("+");
    // let nums: Vec<i32> = word.split("+");
    //     // .map(|s| s.parse::<i32>().unwrap())
    //     // .collect();

    let mut nums = Vec::<i32>::new();
    for s in snums {
        let n = s.parse::<i32>().unwrap();
        nums.push(n);
    }

    nums.sort();

    match nums.pop() {
        Some(last) => {
            for n in nums {
                print!("{}+", n);
            }
            println!("{}", last);
        },
        None => println!("bad input")
    }

}


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

fn main() {
    let expr: String = next();
    let mut counts = [0u8, 0u8, 0u8];

    for ch in expr.chars() {
        if ch != '+' {
            let digit = ch.to_digit(10).unwrap() as u8;
            counts[digit as usize - 1] += 1;
        }
    }

    let mut expr = String::with_capacity(expr.len());
    for (k, v) in counts.iter().enumerate() {
        let mut v = *v;
        while v > 0 {
            if !expr.is_empty() {
                expr.push('+');
            }
            expr.push((k + 1).to_string().chars().nth(0).unwrap());
            v -= 1;
        }
    }

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

fn next<T: FromStr + Default>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().parse::<T>().unwrap_or_else(|_| panic!("failed to parse"))
}


fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s);
    let mut v :Vec<i32>= s.trim().split("+").map( |s| s.parse::<i32>().unwrap()).collect();
    v.sort();
    let ret = v.iter().map( |i| i.to_string()).collect::<Vec<String>>().join("+");
    println!("{}", ret);
}


use std::io::stdin;

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input).expect("error");

    let mut numbers: Vec<i32> = input
        .trim()
        .split("+")
        .map(|s| s.parse::<i32>().unwrap())
        .collect();
    numbers.sort();

    println!(
        "{}",
        numbers
            .iter()
            .map(|a| a.to_string())
            .collect::<Vec<String>>()
            .join("+")
    );
}


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

fn solve(input: &mut Read, output: &mut Write) {
    let mut sin = String::new();
    input.read_to_string(&mut sin).unwrap();
    let mut s = sin.lines()
        .next().unwrap().trim()
        .split('+').map(|x| x.parse::<u8>().unwrap())
        .collect::<Vec<u8>>();
    s.sort();
    let string: String = s.iter().map(|x| x.to_string() + "+").collect();
    let res = &string[..string.len()-1];

    output.write(res.to_string().trim().as_bytes()).unwrap();
}

fn main() {
    solve(&mut io::stdin(), &mut io::stdout());
}

#[cfg(test)]
mod tests {
    use std::fs::File;
    use std::io::Read;
    use solve;

    #[test]
    fn test() {
        (1..3 + 1).map(|x| {
            println!("test #{}", x);
            let mut fin = File::open("./src/in".to_string() + &x.to_string() + ".txt").unwrap();
            let mut buf: Vec<u8> = Vec::new();
            solve(&mut fin, &mut buf);
            let res = String::from_utf8(buf).unwrap();

            let mut fout = File::open("./src/out".to_string() + &x.to_string() + ".txt").unwrap();
            let mut sout = String::new();
            fout.read_to_string(&mut sout).unwrap();
            assert_eq!(res, sout.trim());

        }).count();

    }
}


pub fn main(){
    let mut inputs = input();
    inputs.sort_unstable();
    print!("{}", inputs[0]);
    for i in 1..inputs.len() {
        print!("+{}", inputs[i]);
    }
    println!("");
}

fn input() -> Vec<u32> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input);
    input.trim().split('+').map(|s| s.parse::<u32>().unwrap())
        .collect()
}


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

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

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    let n: usize = reads()[0];

    let mut aa: Vec<i32> = reads();

    while aa.len() > 0 {
        let mut maxi = 0;
        for i in 0..aa.len() {
            if aa[maxi] < aa[i] {
                maxi = i;
            }
        }

        if maxi > 0 && (aa[maxi - 1] - aa[maxi]).abs() >= 2 {
            println!("NO");
            return;
        }

        if maxi + 1 < aa.len() && (aa[maxi + 1] - aa[maxi]).abs() >= 2 {
            println!("NO");
            return;
        }

        aa.remove(maxi);
    }

    println!("YES");
}


use std::io::Read;

fn input(read_file: bool) -> String {
    if read_file {
        let mut file = std::fs::File::open("sample.txt").unwrap();
        let mut buf = String::new();
        file.read_to_string(&mut buf).unwrap();
        buf
    } else {
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();
        buf.trim_end().to_owned()
    }
}

fn solve(ws: &mut std::str::SplitWhitespace) {
    let r: f64 = ws.next().unwrap().parse().unwrap();
    let x: f64 = ws.next().unwrap().parse().unwrap();
    let y: f64 = ws.next().unwrap().parse().unwrap();
    let xd: f64 = ws.next().unwrap().parse().unwrap();
    let yd: f64 = ws.next().unwrap().parse().unwrap();

    let dist = ((xd - x).powi(2) + (yd - y).powi(2)).sqrt();
    let r2 = 2.0 * r;

    println!("{}", (dist / r2).ceil() as i32);
}

fn main() {
    const READ_FROM_FILE: bool = false;

    let s = input(READ_FROM_FILE);
    let mut ws = s.split_whitespace();

    solve(&mut ws);
}


//spnauti-rust
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::*;
#[allow(unused_imports)] use std::collections::*;

#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}

#[allow(dead_code)]
fn build_counting_hashmap<K: Eq + std::hash::Hash, T>(i: T) -> HashMap<K,usize>
    where T: Iterator<Item = K> {
    let mut m = HashMap::new();
    for k in i {
        let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };
        m.insert(k, n);
    }
    m
}

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let r: f64 = input.p();
    let x: f64 = input.p();
    let y: f64 = input.p();
    let xx: f64 = input.p();
    let yy: f64 = input.p();
    println!("{}", (((x - xx).powi(2) + (y - yy).powi(2)).sqrt() / (2. * r)).ceil());
}


use std::io;

fn main() {
    let n: usize = {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        input.trim().parse().unwrap()
    };

    let a: Vec<u32> = {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        input.split_whitespace().map(|k| k.parse().unwrap()).collect()
    };

    let ans = n % 2 == 1 && a.first().unwrap() % 2 == 1 && a.last().unwrap() % 2 == 1;

    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


#![allow(unused_imports)]
use std::io::{self, BufRead};
use std::cmp::*;
use std::collections::*;

macro_rules! scan_to_vec {
    ($count:expr, $t:ty) => ({
        let mut result = Vec::new();
        let stdin = io::stdin();
        let mut handle = stdin.lock();

        for _ in 0..$count {
            let mut buffer = String::new();
            handle.read_line(&mut buffer)
                .expect("scan_to_vec: failed at `handle.read_line`.");
            result.push(buffer.trim().parse::<$t>()
                .expect("scan_to_vec: failed at `parse::<$t>`."));
        }
        result
    })
}

macro_rules! scan_line_to_vec {
    ($t:ty) => ({
        let mut result = Vec::new();
        let stdin = io::stdin();
        let mut handle = stdin.lock();
        let mut buffer = String::new();
        handle.read_line(&mut buffer)
            .expect("scan_line_to_vec: failed at `handle.read_line`.");

        for s in buffer.split_whitespace() {
            result.push(s.parse::<$t>()
                .expect("scan_line_to_vec: failed at `parse::<$t>`."));
        }
        result
    })
}

macro_rules! scan_line {
    () => ({
        let stdin = io::stdin();
        let mut handle = stdin.lock();
        let mut buffer = String::new();
        handle.read_line(&mut buffer)
            .expect("scan_line: failed at `handle.read_line`.");
        buffer
    });
    ( $($t:ty)+ ) => ({
        let stdin = io::stdin();
        let mut handle = stdin.lock();
        let mut buffer = String::new();
        handle.read_line(&mut buffer)
            .expect("scan_line: failed at `handle.read_line`.");
        let mut chunks = buffer.split_whitespace();

        ($(
            {
                chunks.next()
                    .expect("scan_line: failed at `next`, # of space separated strings not equal to requested #")
                .parse::<$t>()
                    .expect("scan_line: failed at `parse::<$t>`.")
            },
        )+)
    })
}

trait Ext {
    fn is_odd(&self) -> bool;
    fn is_even(&self) -> bool;
}

impl Ext for i32 {
    #[inline]
    fn is_odd(&self) -> bool {
        self % 2 != 0
    }

    #[inline]
    fn is_even(&self) -> bool {
        self % 2 == 0
    }
}

fn main() {
    let (n,) = scan_line!(usize);
    let array = scan_line_to_vec!(i32);

    let mut result = true;
    result &= array[0].is_odd();
    result &= array[n - 1].is_odd();
    result &= (array.len() as i32).is_odd();

    if result {
        println!("YES")
    } else {
        println!("NO")
    }
}


fn main() {
    let mut sc = new(std::io::stdin());
    let n: usize = sc.next();
    let mut res = 1_000_000_000;
    for h in 1..(n + 1) {
        let w = (n + h - 1) / h;

        if (h + w) * 2 < res {
            res = (h + w) * 2;
        }
    }
    println!("{}", res);
}

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

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

pub fn new<R: io::Read>(r: R) -> Scanner<R> {
    Scanner::new(r)
}

impl<R: io::Read> Scanner<R> {
    #[inline]
    fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: ")).unwrap()
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(overflowing_literals)]
#![allow(unused_must_use)]

use std::collections::*;
use std::io::*;
use std::cmp::{min, max};
use std::f64::consts::*;
use std::mem::swap;
use std::fs::File;
use std::rc::*;
use std::ascii::*;
use std::ops::*;

const INF: i32 = std::i32::MAX;
const LINF: i64 = std::i64::MAX;
const MOD: i32 = 1000000007;

#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]
struct Pair<A: Eq + Ord + Clone, B: Eq + Ord + Clone>(A, B);

struct Input<Buf: BufRead>
{
	buffer: Buf
}

impl<Buf: BufRead> Input<Buf>
{
	fn read_line(&mut self) -> String {
		let mut v = Vec::new();
		let mut x = [255u8];
		self.buffer.read(&mut x).expect("EOF");
		while x[0] < b' ' && x[0] != 255u8 {
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		while x[0] >= b' ' && x[0] != 255u8 {
			v.push(x[0]);
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		String::from_utf8(v).unwrap()
	}

	fn read_word(&mut self) -> String {
		let mut v = Vec::new();
		let mut x = [255u8];
		self.buffer.read(&mut x).expect("EOF");
		while x[0] <= b' ' && x[0] != 255u8 {
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		while x[0] > b' ' && x[0] != 255u8 {
			v.push(x[0]);
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		String::from_utf8(v).unwrap()
	}
	#[inline]
	fn read_int(&mut self) -> i32 {
		self.read_word().parse::<i32>().expect("Parsing error")
	}
	#[inline]
	fn read_long(&mut self) -> i64 {
		self.read_word().parse::<i64>().expect("Parsing error")
	}
	#[inline]
	fn read_usize(&mut self) -> usize {
		self.read_word().parse::<usize>().expect("Parsing error")
	}
	#[inline]
	fn read_double(&mut self) -> f64 {
		self.read_word().parse::<f64>().expect("Parsing error")
	}
}
macro_rules! read {
    () => {};
	($inf:ident,$($t:ty),*) => ({($({$inf.read_word().parse::<$t>().expect("Parsing error")}),*)});
}
fn gcd<T: RemAssign + Ord + From<i32> + Copy>(x: T, y: T) -> T {
	let (mut a, mut b) = (x, y);
	while b > T::from(0) {
		a %= b;
		swap(&mut a, &mut b);
	}
	a
}

fn main() {
	match std::env::var("home") {
		Ok(_x) => {
			let mut inf = Input {
				buffer: BufReader::new(File::open("input.txt").expect("File not found"))
			};
			let mut ouf = BufWriter::new(stdout());
			solve(&mut inf, &mut ouf);
		}
		Err(_e) => {
			let mut inf = Input { buffer: BufReader::new(stdin()) };
			let mut ouf = BufWriter::new(stdout());
			solve(&mut inf, &mut ouf);
		}
	}
}

fn solve<Inner: BufRead, Output: Write>(inf: &mut Input<Inner>, ouf: &mut Output)
{
	let n = read!(inf,i32);
	let mut s = (n as f64).sqrt() as i32;
	if s * s < n {
		s += 1;
	}

	writeln!(ouf, "{}", 2 * (s + ((n + s - 1) / s)));
}


use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

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

    let x = sc.next::<usize>();
    let mut a = vec![0; x];
    for i in 0..x {
        a[i] = sc.next::<usize>();
    }
    let mut s = HashSet::new();
    let mut result = vec![];
    for v in a.iter().rev() {
        if s.contains(&v) {
            continue;
        }
        s.insert(v);
        result.push(v);
    }
    result.reverse();
    println!("{}", result.len());
    for i in 0..result.len() {
        print!("{}", result[i]);
        if i < result.len() - 1 {
            print!(" ");
        }
    }
    println!("");
}

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

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

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


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

use std::char::*;
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;

macro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::f64;

fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}

fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

const MAX:usize = 30;
const INF:i64 = std::i64::MAX;
const MOD:i64 = 1e9 as i64 + 7;

struct Graph {
    e: Vec<Vec<usize>>,
    v: Vec<usize>,
    u: Vec<usize>,
    f: Vec<bool>,
    c: i64,
    vc: Vec<i64>,
}

impl Graph {
    fn new(n:usize) -> Self {
        Graph {
            e: vec![vec![];n],
            v: vec![],
            u: vec![n;n],
            f: vec![false;n],
            c: 0,
            vc: vec![0;n],
        }
    }

    fn dfs(&mut self, crt: usize) {
        if self.f[crt] { return; }
        self.c += 1;
        self.f[crt] = true;
        self.v.push(crt);
        self.vc[crt] = self.c;
        self.u[crt] = self.v.len()-1;
        for i in 0..self.e[crt].len() {
            self.dfs(self.e[crt][i]);
        }
        //debug!(crt, self.c, self.vc[crt]);
        self.vc[crt] = self.c - self.vc[crt];
    }
}

fn main() {
    //let t:usize = read();

    //'outer: for _ in 0..t {
        let n:usize = read();
        let mut a:Vec<i64> = (0..n).map(|_| read()).collect();
        a.reverse();
        let mut v = vec![];
        for i in 0..n {
            let mut f = false;
            for j in 0..v.len() {
                if a[i] == v[j] {
                    f = true;
                }
            }
            if !f {
                v.push(a[i]);
            }
        }
        v.reverse();
        println!("{}",v.len());
        for e in v {print!("{} ",e);} println!();
    //}
}

/*

*/


fn vec_to_split_str(v: Vec<u16>) -> String {
    let mut s = String::with_capacity(2 * v.len());
    for elem in v {
        s.push_str(&format!("{} ", elem));
    }
    s.trim().to_string()
}

fn input_split() -> Vec<u16> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|elem| elem.parse().unwrap())
        .collect()
}

fn main() {
    {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
    }

    let mut nums = input_split();
    nums.reverse();

    let mut filtered = Vec::with_capacity(nums.len());
    for num in nums {
        if !filtered.contains(&num) {
            filtered.push(num)
        }
    }

    filtered.reverse();
    println!("{}", filtered.len());
    println!("{}", vec_to_split_str(filtered));
}


pub fn main() {
    let mut input = io::Input::new();

    let mut vis = vec![false; 1001];

    let n = input.next();

    let mut u = Vec::<i32>::new();
    let mut v = Vec::<i32>::new();

    for _i in 0..n {
        u.push(input.next());
    }
    u.reverse();

    for a in u {
        if ! vis[a as usize] {
            vis[a as usize] = true;
            v.push(a);
        }
    }

    v.reverse();

    println!("{}", v.len());
    for u in v {
        print!("{} ", u);
    }
    println!();
}

#[allow(unused)]
pub mod io {

    const BUFFER_SIZE: usize = 8192;

    use std::collections::VecDeque;
    use std::str::FromStr;
    use std::io;
    use std::io::Read;

    type AsciiStr = Vec<u8>;

    pub struct Input {
        token_buffer: VecDeque<String>,
        remaining: String,
    }

    impl Input {

        pub fn new() -> Input {
            Input {
                token_buffer: VecDeque::with_capacity(100),
                remaining: String::new(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T
            where T::Err: ::std::fmt::Debug
        {
            self.fill_buffer();
            self.token_buffer.pop_front().unwrap().parse().unwrap()
        }

        pub fn next_ascii_string(&mut self) -> AsciiStr {
            self.fill_buffer();
            Vec::from(self.token_buffer.pop_front().unwrap().as_bytes())
        }

        fn fill_buffer(&mut self) {
            while self.token_buffer.is_empty() {
                let mut minibuffer = [0u8; BUFFER_SIZE];
                let size = io::stdin().read(&mut minibuffer[..]).unwrap();

                self.remaining += &String::from_utf8_lossy(&minibuffer[..size]);

                if self.remaining.trim().len() > 0 {
                    for token in self.remaining.trim().split_whitespace() {
                        self.token_buffer.push_back(String::from(token))
                    }

                    if size > 0 && ! self.remaining.ends_with(|c: char|char::is_ascii_whitespace(&c)) {
                        self.remaining = self.token_buffer.pop_back().unwrap();
                    } else {
                        self.remaining.clear();
                    }

                } else if size == 0 {
                    panic!("EOF");
                }
            }
        }
    }
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Read, Write, BufWriter};
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    let n = get();
    let a: Vec<i32> = (0..n).map(|_| get()).collect();
    let mut marked = vec![false; n];
    for i in 0 .. n {
        for j in i + 1 .. n {
            if a[i] == a[j] {
                marked[i] = true;
            }
        }
    }
    let mut left = Vec::new();
    for i in 0 .. n {
        if !marked[i] { left.push(a[i]); }
    }
    puts!("{}\n", left.len());
    for i in 0 .. left.len() {
        puts!("{}{}", left[i], if i == left.len() - 1 { "\n" } else { " " });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


// Basics

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

//extern crate rand;

use std::io::prelude::*;
use std::mem;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
use std::string;
use std::cmp::*;
use std::collections::*;
use std::vec::Vec;
use std::collections::LinkedList;
use std::num;
use std::ops;
use std::fmt::Debug;
use std::str::FromStr;
use std::ops::Shr;

struct Cin {
    data: LinkedList<String>,
}

impl Cin {
    fn new() -> Self {
        Cin { data: LinkedList::new() }
    }
    fn read_line(&self) -> String {
        let mut s: String = String::new();
        io::stdin().read_line(&mut s).expect("err");
        s
    }
    fn read_str(&mut self) -> String {
        if self.data.len() == 0 {
            let s = self.read_line();
//            let split = s.split("\\s+");
            let split = s.split_whitespace();
            for el in split {
                self.data.push_back(String::from(el));
            }
        }
        self.data.pop_front().expect("empty")
    }
    fn read_int(&mut self) -> i64 {
        self.read_str().parse().expect("err parse")
    }
    fn read_vec(&mut self, size: &i64) -> Vec<i64> {
        let mut v: Vec<i64> = Vec::new();
        for _i in 0..*size {
            v.push(self.read_int());
        }
        v
    }
}

fn main() {
    let mut cin = Cin::new();
    let n: i64 = cin.read_int();
    let vec = cin.read_vec(&n);
    let mut s: HashSet<i64> = HashSet::new();
    let mut res: LinkedList<i64> = LinkedList::new();
    for i in 0..vec.len() {
        let ref value = vec[vec.len() - 1 - i];
        let option = s.get(value).is_some();
        if !option {
            s.insert(value.clone());
            res.push_front(*value);
        }
    }
    println!("{}", res.len());
    for r in res { print!("{} ", r); }
    println!();
}


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

macro_rules! scanln {
    ($($ty: ty),*) => {{
        let line = readln();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$ty>().unwrap()),*)
    }}
}

fn main() {
    let (m, n) = scanln!(i32, i32);
    let mut total = (m / 2) * (n / 2) * 2;
    if m % 2 == 1 {
        total += n / 2;
    }
    if n % 2 == 1 {
        total += m / 2;
    }
    println!("{}", total);
}


fn main() {
    let (m, n) = read_inp();
    let ans = (m * (n / 2)) + ((n % 2) * (m / 2));
    println!("{}", ans);
}

fn read_inp() -> (i32, i32) {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("x");
    let buffer: Vec<i32> = buffer.split_whitespace().map(|i| i.parse().unwrap()).collect();
    (buffer[0], buffer[1])
}


#[allow(unused_imports)]
use std::io::{BufWriter, stdin, stdout, Write};

#[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 scan = Scanner::default();
    let n: (i32,i32) = (scan.next::<i32>(),scan.next::<i32>());
    let mut result = 0i32;

    result = (n.0 * n.1) - (n.0 * n.1)%2;
    result /=2;

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


use std::io;

fn main() -> io::Result<()> {
    let mut input = String::new();

    io::stdin().read_line(&mut input)?;

    let numbers: Vec<u16> = input
        .trim()
        .split(" ")
        .map(|x| x.parse::<u16>().unwrap())
        .take(2)
        .collect();

    let (m, n) = (numbers[0], numbers[1]);

    let result = m * n / 2;
    println!("{}", result);

    return Ok(());
}


use std::io::*;

fn reads<T: std::str::FromStr>(i: &mut StdinLock) -> Vec<T> {
    let mut s = String::new();
    i.by_ref().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let inputs: Vec<f64> = reads(sin);
    let m = inputs[0];
    let n = inputs[1];

    let case1 = (m / 2.).floor() as u64 * n as u64;
    let case2 = (n / 2.).floor() as u64 * m as u64;
    let mut remain = 0;
    let mut other = 0;

    let ans = if case1 < case2 {
        other = m as u64;
        case2
    } else {
        other = n as u64;
        case1
    };

    if m as u64 % 2 != 0 && n as u64 % 2 != 0 {
        remain = (other as f64 / 2.).floor() as u64;
    }

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


//! http://codeforces.com/problemset/problem/50/A

fn main() {
  use std::io;

  let mut buf = String::new();
  io::stdin().read_line(&mut buf).unwrap();
  let mut ns = buf.split(" ")
    .map(|str| str.trim().parse::<usize>().unwrap());
  let m = ns.next().unwrap();
  let n = ns.next().unwrap();

  println!("{}", (m * n) / 2);
}


use std::io::stdin;

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    let a = input.split_whitespace()
                  .map(|x| x.parse().unwrap())
                  .fold(1, |a, x: u32| a * x);
    println!("{}", a / 2);

}


use std::str::FromStr;

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

fn read_vec<T: FromStr>(split_char: char) -> Vec<T> {
    read_str()
        .split(split_char)
        .map(|value| value.parse::<T>().ok().expect("Error"))
        .collect()
}

fn read_tuple<T: FromStr + Copy>() -> (T, T) {
    let buffer: Vec<T> = read_vec(' ');
    (buffer[0], buffer[1])
}

fn main() {
    let (m, n): (u16, u16) = read_tuple();
    println!("{}", (m * n) / 2);
}


// {{{ by shik

use std::io;

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

#[allow(unused_macros)]
macro_rules! R {
    ( $ty:ty, ... ) => {
        gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap()).collect::<Vec<_>>()
    };
    ( $($ty:ty),* ) => {{
        let line = gets();
        let mut it = line.split_whitespace();
        ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )
    }}
}

#[allow(unused_macros)]
macro_rules! W {
    ( $x:expr ) => {{
        println!("{}", $x);
    }};
    ( $x:expr, $($xs:expr),* ) => {{
        print!("{} ", $x);
        W!($($xs),*);
    }}
}

#[allow(unused_macros)]
macro_rules! join {
    ($x:expr, $($xs:expr),*; $sep:expr) => { concat!($x, $($sep, $xs),*) }
}

#[allow(unused_macros)]
macro_rules! dump {
    ($($x:expr),*) => {
        eprintln!(join!($(concat!(stringify!($x), " = {:?}")),*; ", "), $($x),*);
    }
}

// }}}

fn main() {
    let (on, ) = R!(u64);
    let names = vec!["Sheldon".to_string(), "Leonard".to_string(), "Penny".to_string(), "Rajesh".to_string(), "Howard".to_string()];

    let mut n: u64 = on - 1;
    let mut seg: u64 = 1;
    while n >= seg * 5 {
        n -= seg * 5;
        seg *= 2;
    }
    println!("{}", names[(n / seg) as usize]);
}


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

fn main() {
    let mut n = input();
    let (mut repet, mut queue_len) = (1, 5);

    while n > queue_len {
        n -= queue_len;
        queue_len *= 2;
        repet *= 2;
    }

    let mut index = 0;
    while n > repet {
        n -= repet;
        index += 1;
    }

    let options = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];

    println!("{}", options[index]);
}


fn main() {
    let mut n: i32 = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let mut group = 1;
    while n > group * 5 {
        n -= group * 5;
        group *= 2;
    }
    let index = (n - 1) / group;
    let names = vec!["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
    println!("{}", names[index as usize]);
}


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

fn read_line(stdin : &Stdin, line : &mut String) {
    match stdin.read_line(line) {
        Ok(_) => return,
        Err(msg) => panic!("Could not read line! Message: {}.", msg),
    }
}

fn parse_t<T : FromStr>(s : &str) -> T {
    match s.trim().parse() {
        Ok(y) => y,
        Err(_) => panic!("Could not read from string!"),
    }
}

fn read_t<T : FromStr>(stdin : &Stdin) -> T {
    let mut line = String::new();
    read_line(stdin, &mut line);
    parse_t(&line)
}

const NAMES : [&str; 6] = ["",
                           "Sheldon",
                           "Leonard",
                           "Penny",
                           "Rajesh",
                           "Howard"];

fn next_width(w : u64) -> u64 {
    2 * w
}

fn next_interval(h : u64, w : u64) -> (u64, u64) {
    (h + 1, h + w)
}

fn within_interval(l : u64, h : u64, n : u64) -> bool {
    (n >= l) && (n <= h)
}

fn drinks_nth(n : u64) -> String {
    let mut l = 1;
    let mut h = 5;
    let mut w = h - l + 1;
    loop {
        if within_interval(l, h, n) {
            break;
        } else {
            w = next_width(w);
            let (x, y) = next_interval(h, w);
            l = x;
            h = y;
        }
    }
    let b = w / 5;
    let i = ((n - l) / b) + 1;
    String::from(NAMES[i as usize])
}

fn main() {
    let stdin = io::stdin();
    let n = read_t(&stdin);
    println!("{}", drinks_nth(n));
}


use std::io::*;

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

fn get_cycle_rate(c: u32) -> u64 {
    (2 as u64).pow(c)
}

fn get_cycle_person_width(c: u32) -> u64 {
    5 * get_cycle_rate(c)
}

/// return cycle number and cycle offset
fn get_cycle(n: u64) -> Option<(u32, u64)> {
    let mut total = 0;

    for i in 0..100 {
        if n < (total + get_cycle_person_width(i)) {
            return Some((i, total));
        }

        total = total + get_cycle_person_width(i);
    }

    return None;
}

fn main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let n: u64 = read(sin);

    let idx = n - 1;

    let queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];

    // 1.. 2.. 4.. 8..
    // Sheldon, Leonard, Penny, Rajesh, Howard
    // Sheldon, Sheldon, Leonard, Leonard, Penny, Penny, Rajesh, Rajesh, Howard, Howard
    // Sheldon, Sheldon, Sheldon, Sheldon, Leonard, Leonard, Leonard, Leonard, ...

    // elements
    // 5 + 10 + 20 + 40
    // 0   1    2    3

    // 5 * 2^i
    let (cycle, offset) = get_cycle(idx).unwrap();

    println!(
        "{}",
        queue[((idx - offset) / get_cycle_rate(cycle)) as usize]
    );
}


fn readln() -> Vec<i32> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

const NAMES: &'static [&'static str] = &["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];

fn main() {
    let input = readln();
    let mut n = input[0] - 1;

    let mut cnt = 1;
    let mut total_len = 0;
    while total_len + cnt * 5 <= n {
        total_len += cnt * 5;
        cnt *= 2;
    }

    n -= total_len;
    n /= cnt;

    println!("{}", NAMES[n as usize]);
}


//spnauti-rust
#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T: std::io::Read>(mut reader: T) -> WordReader {
        let mut s = String::new();
        reader.read_to_string(&mut s).unwrap();
        WordReader {
            it : s.split_ascii_whitespace().map(String::from)
            .collect::<Vec<_>>().into_iter()
        }
    }
    fn from_stdin() -> WordReader {
        WordReader::new(std::io::stdin())
    }
    fn s(&mut self) -> String {
        self.it.next().unwrap()
    }
    fn ab(&mut self) -> Vec<u8> {
        self.it.next().unwrap().into_bytes()
    }
    fn i(&mut self) -> i32 {
        self.it.next().unwrap().parse().unwrap()
    }
    fn ai(&mut self, n: usize) -> Vec<i32> {
        let mut a = Vec::with_capacity(n);
        for _ in 0..n { a.push(self.i()); }
        a
    }
}

fn main() {
    let mut input = WordReader::from_stdin();
    let mut n = input.i() - 1;
    while n >= 5 {
        n = (n - 5) / 2;
    }
    let a = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
    println!("{}", a[n as usize]);
}


struct Scan {
    buffer: std::collections::VecDeque<String>
}

impl Scan {
    fn new() -> Scan {
        Scan { buffer: std::collections::VecDeque::new() }
    }

    fn next<T: std::str::FromStr>(&mut self)-> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _main() {
    let mut scan = Scan::new();
    let mut n: u64 = scan.next();
    n -= 1;
    let mut current: u64 = 5;
    while current <= n {
        n -= current;
        current*=2;
    }
    let each = current / 5;
    let index = (n/each) as usize;
    let persons: [&str; 5] = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
    println!("{}", persons[index]);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();
}


fn main() {
    // two input strings
    let mut s1 = String::new();
    let mut s2 = String::new();
    std::io::stdin().read_line(&mut s1).unwrap();
    std::io::stdin().read_line(&mut s2).unwrap();

    let lcs1: Vec<char> = s1.trim().to_lowercase().chars().collect();
    let lcs2: Vec<char> = s2.trim().to_lowercase().chars().collect();

    // Compare strings
    let mut r: i32 = 0;
    let mut i: usize = 0;
    let mut j: usize = 0;
    while i < lcs1.len() && j < lcs2.len() {
        if lcs1[i] == lcs2[j] {
            i += 1;
            j += 1;
            continue;
        }

        if lcs1[i] < lcs2[j] {
            r = -1;
            break;
        }

        r = 1;
        break;
    }

    // Display results
    println!("{}", r);
}


use std::io;
use std::cmp::Ordering;

fn main() -> io::Result<()> {
    let mut a = String::new();
    let mut b = String::new();

    io::stdin().read_line(&mut a)?;
    io::stdin().read_line(&mut b)?;

    match a.to_lowercase().cmp(&b.to_lowercase()) {
        Ordering::Greater => println!("1"),
        Ordering::Equal => println!("0"),
        Ordering::Less => println!("-1")
    }

    return Ok(());
}


use std::io::{self};

fn main() {
    let mut buffer1 = String::new();
    let mut buffer2 = String::new();
    io::stdin().read_line(&mut buffer1).expect("???");
    io::stdin().read_line(&mut buffer2).expect("???");

    println!("{}", {
        if &(buffer1.to_ascii_lowercase()) < &(buffer2.to_ascii_lowercase()) {
            -1
        } else if buffer1.eq_ignore_ascii_case(&buffer2) {
            0
        } else {
            1
        }
    });
}


use std::io::{stdin};

fn main() {
	let mut s1 = String::from("");
	let mut s2 = String::from("");

	stdin().read_line(&mut s1).expect("");
	stdin().read_line(&mut s2).expect("");

	s1 = s1.to_lowercase().to_string();
	s2 = s2.to_lowercase().to_string();

	if s1 > s2 {
		print!("{}", 1);
	} else if s1 < s2 {
		print!("{}", -1);
	} else {
		print!("{}", 0);
	}

}


use std::io::{self, prelude::*};
use std::str;

#[allow(unused_must_use)]
fn run<B: BufRead, W: Write>(mut reader: Scanner<B>, mut writer: W) {
    let s1: String = reader.next_line().to_lowercase();
    let s2: String = reader.next_line().to_lowercase();

    if s1 < s2 {
        writeln!(writer, "-1");
    } else if s1 == s2 {
        writeln!(writer, "0");
    } else {
        writeln!(writer, "1");
    }

}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();

    let reader = Scanner::new(stdin.lock());
    let writer = io::BufWriter::new(stdout.lock());
    run(reader, writer);
}

pub struct Scanner<B> {
    reader: B,
    buffer_string: Vec<u8>,
    buffer_iterator: str::SplitWhitespace<'static>,
}

impl <B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        return Self {
            reader,
            buffer_string: Vec::new(),
            buffer_iterator: "".split_whitespace()
        };
    }

    pub fn next<T: str::FromStr>(&mut self) -> T {
        loop {
            //if buffer already exists, just use existing buffer
            if let Some(token) = self.buffer_iterator.next() {
                return token.parse().ok().expect("Fail to parse token");
            }

            //get new line
            self.buffer_string.clear();
            self.reader.read_until(b'\n', &mut self.buffer_string).expect("Failed to read");

            //split by white space
            self.buffer_iterator = unsafe {
                let slice = str::from_utf8_unchecked(&self.buffer_string);
                std::mem::transmute(slice.split_whitespace())
            };
        }
    }

    pub fn next_line(&mut self) -> String {
        //reset buffer
        self.buffer_iterator = "".split_whitespace();
        self.buffer_string.clear();

        let mut input: String = String::new();
        self.reader.read_line(&mut input).expect("Failed to read line");
        return input.trim().to_string();
    }
}


use std::io::{self, BufRead};
use std::cmp::Ordering;

fn main() {
    let stdin = io::stdin();
    let mut iterator = stdin.lock().lines();
    let line1 = iterator.next().unwrap().unwrap().to_ascii_lowercase();
    let line2 = iterator.next().unwrap().unwrap().to_ascii_lowercase();
    match line1.cmp(&line2)  {
        Ordering::Less => println!("-1"),
        Ordering::Greater => println!("1"),
        Ordering::Equal => println!("0"),
    }
}