Let's analyze a program written on some strange programming language. The variables in this language have names consisting of $$$1$$$ to $$$4$$$ characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit.There are four types of operations in the program, each denoted by one of the characters: $, ^, # or &.Each line of the program has one of the following formats:   <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names;  <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character. The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program.Two programs are called equivalent if no matter which operations do characters $, ^, # and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently).You are given a program consisting of $$$n$$$ lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of lines in the program. Then $$$n$$$ lines follow — the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces.

In the first line print $$$k$$$ — the minimum number of lines in the equivalent program. Then print $$$k$$$ lines without any whitespaces — an equivalent program having exactly $$$k$$$ lines, in the same format it is described in the statement.

use std::io::{self, BufRead, Write};
use std::num::Wrapping;
use std::collections::{HashMap, HashSet};

const H1: Wrapping<u64> = Wrapping(327832409582091329);
const H2: Wrapping<u64> = Wrapping(234957239841289312);

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
struct Variable([u8; 4]);
const RES_VAR: Variable = Variable([b'r', b'e', b's', 0]);

impl Variable {
    fn hash(&self) -> Wrapping<u64> {
        let mut hash = H1;
        for v in self.0.iter() {
            hash = (hash + Wrapping(*v as u64)) * H2;
        }
        hash
    }

	fn get(&self) -> &[u8] {
		let mut i = 0;
		while i < 4 && self.0[i] != 0 { i += 1; }
		&self.0[..i]
	}
}

fn is_char(s: u8) -> bool {
    match s {
        b'a' ... b'z' => true,
        b'A' ... b'Z' => true,
        b'0' ... b'9' => true,
        _ => false,
    }
}

fn read_var(s: &[u8]) -> (Variable, &[u8]) {
    let mut var = Variable([0; 4]);
    let mut i = 0;
    while i < s.len() && is_char(s[i]) {
        var.0[i] = s[i];
        i += 1;
    }
    (var, &s[i..])
}

#[derive(Clone, Copy)]
enum Data {
    Input(Variable),
    Op(Wrapping<u64>, u8, Wrapping<u64>),
}

impl Data {
    fn hash(&self) -> Wrapping<u64> {
        match self {
            Data::Input(v) => v.hash(),
            Data::Op(a, op, b) => {
                let op = Wrapping(*op as u64);
                (a * H2 + H1 + op) * H2 + b
            },
        }
    }
}

enum Command {
    Assign(Variable, Variable),
    Op(Variable, Variable, u8, Variable),
}

impl Command {
    fn parse(s: &[u8]) -> Command {
        let (lvar, s) = read_var(&s);
        let (var1, s) = read_var(&s[1..]);
        if s.len() == 0 || !is_op(s[0]) {
            Command::Assign(lvar, var1)
        } else {
            let op = s[0];
            let (var2, _) = read_var(&s[1..]);
            Command::Op(lvar, var1, op, var2)
        }
    }

    fn print(&self) -> io::Result<()> {
        let stdout = io::stdout();
        let mut stdout = stdout.lock();
        match self {
            Command::Assign(lvar, var1) => {
                stdout.write_all(lvar.get())?;
                stdout.write_all(b"=")?;
                stdout.write_all(var1.get())?;
                stdout.write_all(b"\n")?;
                Ok(())
            },
            Command::Op(lvar, var1, op, var2) => {
                stdout.write_all(lvar.get())?;
                stdout.write_all(b"=")?;
                stdout.write_all(var1.get())?;
                stdout.write_all(&[*op])?;
                stdout.write_all(var2.get())?;
                stdout.write_all(b"\n")?;
                Ok(())
            },
        }
    }
}

fn is_op(s: u8) -> bool {
    match s {
        b'$' | b'^' | b'#' | b'&' => true,
        _ => false,
    }
}

struct VariableContext {
    vars: HashMap<Variable, Wrapping<u64>>,
    data: HashMap<Wrapping<u64>, Data>,
    input_vars: HashSet<Variable>,
}

impl VariableContext {
    fn new() -> Self {
        Self {
            vars: HashMap::new(),
            data: HashMap::new(),
            input_vars: HashSet::new(),
        }
    }

    fn hash_data(&mut self, data: Data) -> Wrapping<u64> {
        let hash = data.hash();
        self.data.entry(hash).or_insert(data);
        hash
    }

    fn get_var(&mut self, var: Variable) -> Wrapping<u64> {
        let val = self.vars.get(&var).map(|x| *x);
        match val {
            None => {
                self.input_vars.insert(var);
                self.hash_data(Data::Input(var))
            },
            Some(data) => data,
        }
    }

    fn set_var(&mut self, var: Variable, data: Wrapping<u64>) {
        self.vars.insert(var, data);
    }
}

struct OutputContext {
    used_vars: HashSet<Variable>,
    data: HashMap<Wrapping<u64>, Data>,
    names: HashMap<Wrapping<u64>, Variable>,
    cur_name: i64,
    out: Vec<Command>,
}

impl OutputContext {
    fn new(ctx: VariableContext) -> Self {
        let VariableContext { vars: _, data, input_vars: used_vars } = ctx;
        Self {
            used_vars: used_vars,
            data: data,
            names: HashMap::new(),
            cur_name: 0,
            out: Vec::new(),
        }
    }

    fn new_name(&mut self) -> Variable {
        loop {
            let mut v = Variable([0; 4]);
            let mut cur = self.cur_name;
            self.cur_name += 1;
            for i in 0..4 {
                v.0[i] = (cur % 26) as u8 + b'a';
                cur /= 26;
            }
            if !self.used_vars.contains(&v) {
                return v;
            }
        }
    }

    fn make_var(&mut self, data: Wrapping<u64>) -> Variable {
        let val = self.names.get(&data).map(|x| *x);
        match val {
            Some(v) => v,
            None => {
                let x = *(self.data.get(&data).unwrap());
                match x {
                    Data::Input(v) => v,
                    Data::Op(a, op, b) => {
                        let var = self.new_name();
                        let var1 = self.make_var(a);
                        let var2 = self.make_var(b);
                        self.out.push(Command::Op(var, var1, op, var2));
                        self.names.insert(data, var);
                        var
                    }
                }
            },
        }
    }

    fn output_result(&mut self, res: Wrapping<u64>) {
        let data = *(self.data.get(&res).unwrap());
        match data {
            Data::Input(v) => {
                if v != RES_VAR {
                    self.out.push(Command::Assign(RES_VAR, v));
                }
            },
            Data::Op(a, op, b) => {
                let var1 = self.make_var(a);
                let var2 = self.make_var(b);
                self.out.push(Command::Op(RES_VAR, var1, op, var2));
            }
        }
    }
}

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let n = lines.next().unwrap().unwrap().trim().parse::<usize>().unwrap();
    let mut context = VariableContext::new();
    for line in lines.take(n) {
        let cmd = Command::parse(line.unwrap().as_bytes());
        match cmd {
            Command::Assign(lvar, rvar) => {
                let data = context.get_var(rvar);
                context.set_var(lvar, data);
            },
            Command::Op(lvar, a, op, b) => {
                let x = context.get_var(a);
                let y = context.get_var(b);
                let h = context.hash_data(Data::Op(x, op, y));
                context.set_var(lvar ,h);
            },
        }
    }
    let res = context.get_var(RES_VAR);
    let mut context = OutputContext::new(context);
    context.output_result(res);
    println!("{}", context.out.len());
    for entry in context.out.into_iter() {
        entry.print().unwrap();
    }
}

use std::io::{self, BufRead, Write};
use std::num::Wrapping;
use std::collections::{HashMap, HashSet};

const H1: Wrapping<u64> = Wrapping(327832409582091329);
const H2: Wrapping<u64> = Wrapping(234957239841289312);

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
struct Variable([u8; 4]);
const RES_VAR: Variable = Variable([b'r', b'e', b's', 0]);

impl Variable {
    fn hash(&self) -> Wrapping<u64> {
        let mut hash = H1;
        for v in self.0.iter() {
            hash = (hash + Wrapping(*v as u64)) * H2;
        }
        hash
    }
}

fn is_char(s: u8) -> bool {
    match s {
        b'a' ... b'z' => true,
        b'A' ... b'Z' => true,
        b'0' ... b'9' => true,
        _ => false,
    }
}

fn read_var(s: &[u8]) -> (Variable, &[u8]) {
    let mut var = Variable([0; 4]);
    let mut i = 0;
    while i < s.len() && is_char(s[i]) {
        var.0[i] = s[i];
        i += 1;
    }
    (var, &s[i..])
}

#[derive(Clone, Copy)]
enum Data {
    Input(Variable),
    Op(Wrapping<u64>, u8, Wrapping<u64>),
}

impl Data {
    fn hash(&self) -> Wrapping<u64> {
        match self {
            Data::Input(v) => v.hash(),
            Data::Op(a, op, b) => {
                let op = Wrapping(*op as u64);
                (a * H2 + H1 + op) * H2 + b
            },
        }
    }
}

enum Command {
    Assign(Variable, Variable),
    Op(Variable, Variable, u8, Variable),
}

impl Command {
    fn parse(s: &[u8]) -> Command {
        let (lvar, s) = read_var(&s);
        let (var1, s) = read_var(&s[1..]);
        if s.len() == 0 || !is_op(s[0]) {
            Command::Assign(lvar, var1)
        } else {
            let op = s[0];
            let (var2, _) = read_var(&s[1..]);
            Command::Op(lvar, var1, op, var2)
        }
    }

    fn print(&self) -> io::Result<()> {
        let stdout = io::stdout();
        let mut stdout = stdout.lock();
        match self {
            Command::Assign(lvar, var1) => {
                stdout.write_all(&lvar.0)?;
                stdout.write_all(b"=")?;
                stdout.write_all(&var1.0)?;
                stdout.write_all(b"\n")?;
                Ok(())
            },
            Command::Op(lvar, var1, op, var2) => {
                stdout.write_all(&lvar.0)?;
                stdout.write_all(b"=")?;
                stdout.write_all(&var1.0)?;
                stdout.write_all(&[*op])?;
                stdout.write_all(&var2.0)?;
                stdout.write_all(b"\n")?;
                Ok(())
            },
        }
    }
}

fn is_op(s: u8) -> bool {
    match s {
        b'$' | b'^' | b'#' | b'&' => true,
        _ => false,
    }
}

struct VariableContext {
    vars: HashMap<Variable, Wrapping<u64>>,
    data: HashMap<Wrapping<u64>, Data>,
    input_vars: HashSet<Variable>,
}

impl VariableContext {
    fn new() -> Self {
        Self {
            vars: HashMap::new(),
            data: HashMap::new(),
            input_vars: HashSet::new(),
        }
    }

    fn hash_data(&mut self, data: Data) -> Wrapping<u64> {
        let hash = data.hash();
        self.data.entry(hash).or_insert(data);
        hash
    }

    fn get_var(&mut self, var: Variable) -> Wrapping<u64> {
        let val = self.vars.get(&var).map(|x| *x);
        match val {
            None => {
                self.input_vars.insert(var);
                self.hash_data(Data::Input(var))
            },
            Some(data) => data,
        }
    }

    fn set_var(&mut self, var: Variable, data: Wrapping<u64>) {
        self.vars.insert(var, data);
    }
}

struct OutputContext {
    used_vars: HashSet<Variable>,
    data: HashMap<Wrapping<u64>, Data>,
    names: HashMap<Wrapping<u64>, Variable>,
    cur_name: i64,
    out: Vec<Command>,
}

impl OutputContext {
    fn new(ctx: VariableContext) -> Self {
        let VariableContext { vars: _, data, input_vars: used_vars } = ctx;
        Self {
            used_vars: used_vars,
            data: data,
            names: HashMap::new(),
            cur_name: 0,
            out: Vec::new(),
        }
    }

    fn new_name(&mut self) -> Variable {
        loop {
            let mut v = Variable([0; 4]);
            let mut cur = self.cur_name;
            self.cur_name += 1;
            for i in 0..4 {
                v.0[i] = (cur % 26) as u8 + b'a';
                cur /= 26;
            }
            if !self.used_vars.contains(&v) {
                return v;
            }
        }
    }

    fn make_var(&mut self, data: Wrapping<u64>) -> Variable {
        let val = self.names.get(&data).map(|x| *x);
        match val {
            Some(v) => v,
            None => {
                let x = *(self.data.get(&data).unwrap());
                match x {
                    Data::Input(v) => v,
                    Data::Op(a, op, b) => {
                        let var = self.new_name();
                        let var1 = self.make_var(a);
                        let var2 = self.make_var(b);
                        self.out.push(Command::Op(var, var1, op, var2));
                        self.names.insert(data, var);
                        var
                    }
                }
            },
        }
    }

    fn output_result(&mut self, res: Wrapping<u64>) {
        let data = *(self.data.get(&res).unwrap());
        match data {
            Data::Input(v) => {
                if v != RES_VAR {
                    self.out.push(Command::Assign(RES_VAR, v));
                }
            },
            Data::Op(a, op, b) => {
                let var1 = self.make_var(a);
                let var2 = self.make_var(b);
                self.out.push(Command::Op(RES_VAR, var1, op, var2));
            }
        }
    }
}

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let n = lines.next().unwrap().unwrap().trim().parse::<usize>().unwrap();
    let mut context = VariableContext::new();
    for line in lines.take(n) {
        let cmd = Command::parse(line.unwrap().as_bytes());
        match cmd {
            Command::Assign(lvar, rvar) => {
                let data = context.get_var(rvar);
                context.set_var(lvar, data);
            },
            Command::Op(lvar, a, op, b) => {
                let x = context.get_var(a);
                let y = context.get_var(b);
                let h = context.hash_data(Data::Op(x, op, y));
                context.set_var(lvar ,h);
            },
        }
    }
    let res = context.get_var(RES_VAR);
    let mut context = OutputContext::new(context);
    context.output_result(res);
    println!("{}", context.out.len());
    for entry in context.out.into_iter() {
        entry.print().unwrap();
    }
}


Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·n people in the group (including Vadim), and they have exactly n - 1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. i-th person's weight is wi, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.Help the party to determine minimum possible total instability!

The first line contains one number n (2 ≤ n ≤ 50). The second line contains 2·n integer numbers w1, w2, ..., w2n, where wi is weight of person i (1 ≤ wi ≤ 1000).

Print minimum possible total instability.

#![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: usize = 1000000007;

#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]
struct Pair<A: Eq + Ord + Copy + Clone, B: Eq + Ord + Copy + 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 + Clone>(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,usize) * 2;
	let mut w = vec![0usize; n];
	for i in 0..n {
		w[i] = read!(inf,usize);
	}
	w.sort();
	let mut ans = MOD;
	for i in 0..n {
		for j in i + 1..n {
			let mut v = Vec::new();
			for k in 0..n {
				if k != i && k != j {
					v.push(w[k]);
				}
			}
			let mut pos = 0;
			let mut p = 0;
			while pos < v.len() {
				p += v[pos + 1] - v[pos];
				pos += 2;
			}
			ans = min(ans, p);
		}
	}
	writeln!(ouf, "{}", ans);
}

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

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

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

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

fn main() {
    let n: usize = get_line().trim().parse().unwrap();

    let mut w: Vec<i32> = get_vec();

    w.sort();

    let mut ans = None;

    for i in 0..2 * n {
        for j in i + 1..2 * n {
            let mut v = w.clone();
            v.remove(j);
            v.remove(i);
            let cur = v.into_iter().fold((0, false), |acc, x| {
                (if acc.1 {
                    acc.0 + x
                } else {
                    acc.0 - x
                },
                !acc.1)
            }).0;

            match ans {
                Some(x) if x <= cur => (),
                _ => ans = Some(cur),
            };
        }
    }

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

#![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: usize = 1000000007;

#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]
struct Pair<A: Eq + Ord + Copy + Clone, B: Eq + Ord + Copy + 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 + Clone>(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,usize);
	let mut w = vec![0usize; 2 * n];
	for i in 0..2 * n {
		w[i] = read!(inf,usize);
	}
	w.sort();
	let mut ans = MOD;
	for i in 0..3 {
		let mut pos = i;
		let mut p = 0;
		while pos < 2 * n - 2 + i {
			p += w[pos + 1] - w[pos];
			pos += 2;
		}
		ans = min(ans, p);
	}
	writeln!(ouf, "{}", ans);
}

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

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

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

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

fn main() {
    let n: usize = get_line().trim().parse().unwrap();

    let mut w: Vec<u32> = get_vec();

    w.sort();

    let ans = min(w[2 * n - 3] - w[0], w[2 * n - 2] - w[1]);
    let ans = min(ans, w[2 * n - 1] - w[2]);

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

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

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

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

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

fn main() {
    let n: usize = get_line().trim().parse().unwrap();

    let mut w: Vec<i32> = get_vec();

    w.sort();

    let ans = (0..3).map(|i| {
        w.iter().cloned().skip(i).take(2 * (n - 1)).fold((0, false), |acc, x| {
            (if acc.1 {
                acc.0 + x
            } else {
                acc.0 - x
            }, !acc.1)
        }).0
    }).min().unwrap();

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


Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform:  U — move from the cell (x, y) to (x, y + 1);  D — move from (x, y) to (x, y - 1);  L — move from (x, y) to (x - 1, y);  R — move from (x, y) to (x + 1, y). Ivan entered a sequence of n commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0, 0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!

The first line contains one number n — the length of sequence of commands entered by Ivan (1 ≤ n ≤ 100). The second line contains the sequence itself — a string consisting of n characters. Each character can be U, D, L or R.

Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

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

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

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

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

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

fn main() {
    let _n = get!(usize);
    let seq: Vec<char> = util::line().chars().collect();

    let l = seq.iter().filter(|&&c| c == 'L').count();
    let r = seq.iter().filter(|&&c| c == 'R').count();
    let u = seq.iter().filter(|&&c| c == 'U').count();
    let d = seq.iter().filter(|&&c| c == 'D').count();

    println!("{}", 2 * min(l, r) + 2 * min(u, d));
}

use std::collections::HashMap;

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

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

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

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

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

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

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

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

fn main() {
    input! {
        _n: usize,
        commands: chars,
    }

    let mut num_command = HashMap::new();

    commands
        .iter()
        .for_each(|x| *num_command.entry(x).or_insert(0) += 1);

    let num_l = *num_command.get(&'L').unwrap_or(&0);
    let num_r = *num_command.get(&'R').unwrap_or(&0);
    let num_u = *num_command.get(&'U').unwrap_or(&0);
    let num_d = *num_command.get(&'D').unwrap_or(&0);

    println!(
        "{}",
        std::cmp::min(num_l * 2, num_r * 2) + std::cmp::min(num_u * 2, num_d * 2)
    );
}

fn main() {
    let mut ri = ReadIn::new();
    let n = ri.int();
    ri.read_line();
    let s = ri.0;
    let mut c1 = 0;
    let mut c2 = 0;
    for c in s.chars() {
        if c == 'L' {
            c1 -= 1;
        }
        if c == 'R' {
            c1 += 1;
        }
        if c == 'U' {
            c2 -= 1;
        }
        if c == 'D' {
            c2 += 1;
        }
    }
    if c1 < 0 {
        c1 = -c1;
    }
    if c2 < 0 {
        c2 = -c2;
    }
    println!("{}", n - c1 - c2);
}

use std::iter::Map;
use std::str::SplitWhitespace;
use std::io::stdin;
use std::mem::forget;

pub struct ReadIn(pub String);

impl ReadIn {
    pub fn new() -> ReadIn {
        ReadIn(String::new())
    }
    fn read_i32(s: &str) -> i32 {
        s.parse().unwrap()
    }
    pub fn read_line(&mut self) {
        self.0.clear();
        forget(stdin().read_line(&mut self.0));
    }
    pub fn ints(&mut self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.read_line();
        self.0.split_whitespace().map(ReadIn::read_i32)
    }
    pub fn int(&mut self) -> i32 {
        self.ints().next().unwrap()
    }
    pub fn int2(&mut self) -> (i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap())
    }
}

use std::cmp::min;
use std::io::stdin;
fn main() {
    let mut _text = String::new();
    stdin().read_line(&mut _text).unwrap();
    let (uc, dc, rc, lc) = command_counter(parse());
    let counter = min(uc, dc) * 2 + min(lc, rc) * 2;
    println!("{}", counter)
}
#[derive(Debug, Copy, Clone)]
enum Command {
    U,
    D,
    L,
    R,
}

fn parse() -> Vec<Command> {
    let mut text = String::new();
    stdin().read_line(&mut text).unwrap();
    let fu = |e: char| -> Command {
        match e {
            'U' => Command::U,
            'D' => Command::D,
            'L' => Command::L,
            _ => Command::R,
        }
    };
    let text: Vec<Command> = text.trim().chars().map(fu).collect();
    text
}
fn command_counter(arr: Vec<Command>) -> (usize, usize, usize, usize) {
    let mut uc = 0;
    let mut dc = 0;
    let mut lc = 0;
    let mut rc = 0;
    for i in arr {
        match i {
            Command::U => uc += 1,
            Command::D => dc += 1,
            Command::L => lc += 1,
            Command::R => rc += 1,
        }
    }
    (uc, dc, rc, lc)
}

use std::cmp::min;
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)
}

fn max_moves(moves : &str) -> usize {
    let lrud = "LRUD".as_bytes();
    let left = lrud[0];
    let right = lrud[1];
    let up = lrud[2];
    let down = lrud[3];
    let mut num_left = 0;
    let mut num_right = 0;
    let mut num_up = 0;
    let mut num_down = 0;
    for &b in moves.as_bytes().iter() {
        if b == left {
            num_left = num_left + 1;
        } else if b == right {
            num_right = num_right + 1;
        } else if b == up {
            num_up = num_up + 1;
        } else if b == down {
            num_down = num_down + 1;
        } else {
            panic!("Unknown move!");
        }
    }
    let x = min(num_left, num_right);
    let y = min(num_up, num_down);
    x + x + y + y
}

fn main() {
    let stdin = io::stdin();
    let _ : usize = read_t(&stdin);
    let mut moves = String::new();
    read_line(&stdin, &mut moves);
    let moves = moves.trim();
    let x = max_moves(moves);
    println!("{}", x);
}

use std::io::stdin;
fn main() {
    let mut _text = String::new();
    stdin().read_line(&mut _text).unwrap();
    let commands = parse();
    let mut robot = Robot::new();
    let mut counter = 0;
    let mut results = vec!(0);
    for i in commands {
        robot.obey(i);
        counter +=1;
        if robot.x ==0 && robot.y ==0 {
           results.push(counter);
        }
    }
    println!("{}",results[results.len()-1])

}
enum Command {
    U,
    D,
    L,
    R,
}
struct Robot {
    x: usize,
    y: usize,
}
impl Robot {
    fn new() -> Robot {
        Robot { x: 0, y: 0 }
    }
    fn obey(&mut self, c: Command) {
        match c {
            Command::U => {
                self.y += 1;
            }
            Command::D => {
                self.y -= 1;
            }
            Command::L => {
                self.x -= 1;
            }
            Command::R => {
                self.x += 1;
            }
        };
    }
}

fn parse() -> Vec<Command> {
    let mut text = String::new();
    stdin().read_line(&mut text).unwrap();
    let fu = |e: char| -> Command {
        match e {
            'U' => Command::U,
            'D' => Command::D,
            'L' => Command::L,
            _ => Command::R,
        }
    };
    let text: Vec<Command> = text.trim().chars().map(fu).collect();
    text
}


Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Write one line — the corresponding answer. Do not omit the leading 0s.

#[allow(unused)] use std::io::*;
#[allow(unused)] use std::collections::*;
#[allow(unused)] use std::mem::*;
#[allow(unused)] use std::num::*;
#[allow(unused)] use std::cmp::*;
#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{
    let mut inp = String::new(); stdin().read_line(&mut inp).ok();
    let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();
    let mut cnt : usize = 0;
    fn next<T>(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr
    { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }
    ($(next::<$x>(&mut cnt, &s)), +)
    }}; }
#[allow(unused)] macro_rules! arr { ($($n:expr, $T:ty), +) => {{
    let mut inp = String::new(); stdin().read_line(&mut inp).ok();
    let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);
    ($({let mut v = Vec::new(); v.reserve(($n) as usize);
        for _ in 0..$n { let t = s.next(); if t == None { break; }
        v.push(t.unwrap().parse::<$T>().unwrap()); } v }),+)
    }}; }

///////////////////////////////////////////////////////////////////////////////
fn main()
{
    scan!(String).chars().zip(scan!(String).chars()).map(|(x, y)| if x == y { 0 } else { 1 }).for_each(|x| print!("{}", x));
}

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

fn main() {
    let a = input();
    let b = input();
    let res = a
        .chars()
        .zip(b.chars())
        .map(|(a, b)| if a == b { '0' } else { '1' })
        .collect::<String>();
    println!("{}", res)
}

//spnauti-rust
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();
    input.ab().into_iter().zip(input.ab().into_iter()).for_each(|(a,b)| {
        print!("{}", if a != b {1} else {0})
    });
}

fn main() {
    let a = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().to_string()
    };
    let b = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().to_string()
    };

    let ret: String = a.chars()
        .zip(b.chars())
        .map(|(x, y)| if x == y { '0' } else { '1' })
        .collect();
    println!("{}", ret);
}

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

fn main() {
    let stdin = io::stdin();
    let mut iterator = stdin.lock().lines();
    let first = iterator.next().unwrap().unwrap();
    let second = iterator.next().unwrap().unwrap();

    let first_vec: Vec<char> = first.chars().collect();
    let second_vec: Vec<char> = second.chars().collect();

    let mut result = Vec::new();

    for i in 0..first_vec.len() {
        if first_vec[i] != second_vec[i] {
            result.push("1");
        } else {
            result.push("0");
        }
    }

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

use std::io::stdin;

fn main() {
    let mut a = String::new();
    let mut b = String::new();
    stdin().read_line(&mut a).unwrap();
    stdin().read_line(&mut b).unwrap();
    let a: Vec<char> = a.trim().chars().collect();
    let b: Vec<char> = b.trim().chars().collect();

    let mut answer = String::new();

    for i in 0..a.len() {
        if a[i] != b[i] {
            answer.push_str("1");
        } else {
            answer.push_str("0");
        }
    }

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

use std::io::stdin;

fn main() {
    let mut a = String::new();
    let mut b = String::new();
    stdin().read_line(&mut a).unwrap();
    stdin().read_line(&mut b).unwrap();
    let a: Vec<char> = a.trim().chars().collect();
    let b: Vec<char> = b.trim().chars().collect();

    let mut answer = String::new();

    for i in 0..a.len() {
        if a[i] != b[i] {
            answer.push_str("1");
        } else {
            answer.push_str("0");
        }
    }

    println!("{}", answer); //Hola
}

use std::io;

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

fn main() {
    let l1 = read_line();
    let l2 = read_line();
    let ans = l1.chars().zip(l2.chars()).map(|(c1, c2)| if c1 == c2 { '0' } else { '1' }).collect::<String>();
    println!("{}", ans);
}

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 bits(i: impl Iterator<Item = char>) -> impl Iterator<Item = bool> {
    i.map(|x| x == '0')
}

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

    let input1: String = read(sin);
    let input2: String = read(sin);

    let ans: String = bits(input1.as_str().chars())
        .zip(bits(input2.as_str().chars()))
        .map(|x| x.0 ^ x.1)
        .map(|x| if x { '1' } else { '0' })
        .collect();

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

// https://codeforces.com/problemset/problem/61/A
use std::io;

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

    io::stdin()
        .read_line(&mut a)
        .unwrap();

    let a = a.trim();

    let a: Vec<char> = a.chars().collect();

    let mut b = String::new();

    io::stdin()
        .read_line(&mut b)
        .unwrap();

    let b = b.trim();

    let b: Vec<char> = b.chars().collect();

    let mut answer = String::from("");

    for i in 0..a.len() {
        if a[i] == b[i] {
            answer.push_str("0");
        } else {
            answer.push_str("1");
        }
    }
    println!("{}", answer);
}

// https://codeforces.com/problemset/problem/61/A
// implementation, simulation
use std::io;

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

    io::stdin()
        .read_line(&mut a)
        .unwrap();

    let a = a.trim();

    let mut b = String::new();

    io::stdin()
        .read_line(&mut b)
        .unwrap();

    let b = b.trim();

    let mut iter = b.chars();

    let mut answer = String::from("");

    for ch in a.chars() {
        if ch == iter.next().unwrap() {
            answer.push_str("0");
        } else {
            answer.push_str("1");
        }
    }

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

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

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

fn main() -> io::Result<()> {
    let input1 = get_input().trim().to_string();
    let input2 = get_input().trim().to_string();

    for i in 0..input1.len() {
        let c1 = input1.chars().nth(i);
        let c2 = input2.chars().nth(i);
        if c1 == c2 {
            print!("{}", 0);
        } else {
            print!("{}", 1);
        }
    }
    print!("\n");

    Ok(())
}

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

#[allow(unused_must_use)]
fn solve<B: BufRead, W: Write>(mut scan: Scanner<B>, mut w: W) {
    let a: Vec<char> = scan.token::<String>().chars().collect();
    let b: Vec<char> = scan.token::<String>().chars().collect();

    let mut c: Vec<char> = Vec::new();

    for (i, _) in a.iter().enumerate() {
        if a[i] == b[i] {
            c.push('0');
        } else {
            c.push('1');
        }
    }

    let ans: String = c.into_iter().collect();

    writeln!(w, "{}", ans);
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let reader = Scanner::new(stdin.lock());
    let writer = io::BufWriter::new(stdout.lock());
    solve(reader, writer);
}

#[allow(dead_code)]
fn matrix_to_str<T: ToString>(matrix: &Vec<Vec<T>>, separator: &str) -> String {
    use std::fmt::Write;
    let mut ans = String::new();
    for line in matrix.iter() {
        for elem in line.iter() {
            write!(&mut ans, "{}{}", elem.to_string(), separator).unwrap();
        }
        write!(&mut ans, "\n").unwrap();
    }
    ans
}
pub struct Scanner<B> {
    reader: B,
    buf_str: Vec<u8>,
    buf_iter: std::str::SplitWhitespace<'static>,
}
impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_whitespace()
        }
    }
    pub fn token<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = std::str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace()) }
        }
    }
    pub fn get_matrix<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>> {
        // m rows and n columns
        let mut ans: Vec<Vec<T>> = Vec::with_capacity(m);
        for i in 0..m {
            ans.push(Vec::with_capacity(n));
            for _ in 0..n {
                ans[i].push(self.token::<T>());
            }
        }
        ans
    }
}

use std::io;

fn main() {
    let mut s = vec![String::new(), String::new()];
    for i in 0..2 {
        io::stdin().read_line(&mut s[i as usize]).unwrap();
        s[i as usize] = s[i as usize].trim().to_string();
    }
    for i in 0..s[0].len() {
        if s[0].chars().nth(i) != s[1].chars().nth(i) {
            print!("1");
        } else {
            print!("0");
        }
    }
}

#![allow(unused_imports)]
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::str::FromStr;

fn main() {
    let mut first = String::new();
    let mut second = String::new();
    io::stdin().read_line(&mut first).unwrap();
    io::stdin().read_line(&mut second).unwrap();
    let fir: Vec<char> = first.chars().filter(|c| c.is_digit(2)).collect();
    let sec: Vec<char> = second.chars().filter(|c| c.is_digit(2)).collect();
    let mut out = vec!['_'; fir.len()];

    for i in 0..fir.len() {
        if fir[i] == sec[i] {
            out[i] = '0';
        } else {
            out[i] = '1';
        }
    }

    println!("{}", out.iter().collect::<String>());
}

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

fn main() {
    let num_1 = read_line().to_vec_chars();
    let num_2 = read_line().to_vec_chars();
    let mut s = String::with_capacity(num_1.len());

    for i in 0..num_1.len() {
        if num_1[i] == num_2[i] {
            s.push('0')
        } else {
            s.push('1')
        }
    }
    println!("{}", s);
}

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Ошибка чтения");

    buffer.trim().to_string()
}

trait ParseStr {
    fn to_vec<T>(&self, separator: &str) -> Vec<T>
    where
        T: FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug;

    fn to_vec_chars(&self) -> Vec<char>;

    fn to<T>(&self) -> T
    where
        T: FromStr + Copy,
        <T as std::str::FromStr>::Err: Debug;
}

impl ParseStr for String {

    fn to_vec<T>(&self, separator: &str) -> Vec<T>
    where
        T: FromStr,
        <T as std::str::FromStr>::Err: Debug,
    {
        self.split(separator).map(|c| c.parse::<T>().expect("Ошибка преобразования")).collect()
    }

    fn to_vec_chars(&self) -> Vec<char> {
        self.chars().collect()
    }

    fn to<T>(&self) -> T
    where
        T: FromStr + Copy,
        <T as std::str::FromStr>::Err: Debug,
    {
        ParseStr::to_vec::<T>(self, " ")[0]
    }
}

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

fn main() {
    let (length, a): (usize, u128) = {
        let s: String = read_str();
        (s.len(), u128::from_str_radix(&s[..], 2).expect("Error"))
    };
    let b: u128 = {
        let s: String = read_str();
        u128::from_str_radix(&s[..], 2).expect("Error")
    };

    print!("{:01$b}", a ^ b, length);
}

use std::io;
use std::io::Stdin;

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 print_result(s_1 : &String, s_2 : &String) {
    let pair_iter = s_1.trim().chars().zip(s_2.trim().chars());
    for (a, b) in pair_iter {
        if a == b {
            print!("0");
        } else {
            print!("1");
        }
    }
    println!();
}

fn main() {
    let stdin = io::stdin();
    let mut s_1 = String::new();
    let mut s_2 = String::new();
    read_line(&stdin, &mut s_1);
    read_line(&stdin, &mut s_2);
    print_result(&s_1, &s_2);
}

fn main() {
    let s: Vec<char> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().chars().collect()
    };
    let t: Vec<char> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().chars().collect()
    };

    let n = s.len();
    let mut ans = String::new();

    for i in 0..n {
        ans.push(if s.get(i) != t.get(i) { '1' } else { '0' });
    }

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

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

    for i in 0..a.trim().len() {
        if a.as_bytes()[i] != b.as_bytes()[i] {
            print!("1");
        }
        else {
            print!("0");
        }
    }
}

use std::io;

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

	let mut string2 = String::new();
	io::stdin().read_line(&mut string2).unwrap();
	let string2 = string2.trim();

	for i in 0..string1.len() {
		if string1.chars().nth(i) != string2.chars().nth(i) {
			print!("1");
		} else {
			print!("0");
		}
	}
	println!();
}

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

fn main() {
    let stdin = io::stdin();
    let mut input1 = String::new();
    let mut input2 = String::new();

    stdin.lock().read_line(&mut input1).unwrap();
    stdin.lock().read_line(&mut input2).unwrap();

    for (i, j) in input1.trim().chars().zip(input2.trim().chars()) {
        if i == j {
            print!("0");
        } else {
            print!("1");
        }
    }
    println!();
}

use std::io;

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

fn main() {
    let s = read_line();
    let t = read_line();

    for (ps, pt) in s.chars().zip(t.chars()) {
        if ps == pt {
            print!("0");
        } else {
            print!("1");
        }

    }

}

#[allow(unused_imports)]
use std::cmp::{min,max};
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 a = scan.next::<String>();
	let b = scan.next::<String>();
    let ab = a.as_bytes();
    let bb = b.as_bytes();

    for i in 0..ab.len() {
        write!(out, "{}", ab[i] ^ bb[i]).expect("fail");
    }

    writeln!(out, "").expect("fail");
}

fn main() {
    let a = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().to_string()
    };
    let b = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().to_string()
    };
    let x = i32::from_str_radix(&a, 2).unwrap();
    let y = i32::from_str_radix(&b, 2).unwrap();
    let z = x ^ y;

    println!("{}", format!("{:b}", z));
}

use std::io::stdin;

fn main() {
    let mut a = String::new();
    let mut b = String::new();
    stdin().read_line(&mut a).unwrap();
    stdin().read_line(&mut b).unwrap();
    let a: Vec<char> = a.chars().collect();
    let b: Vec<char> = b.chars().collect();

    let mut answer = String::new();

    for i in 0..a.len() {
        if a[i] != b[i] {
            answer.push_str("1");
        } else {
            answer.push_str("0");
        }
    }

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

use std::io;

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

	let mut string2 = String::new();
	io::stdin().read_line(&mut string2).unwrap();

	for i in 0..(string1.len()-1) {
		if string1.chars().nth(i) == string2.chars().nth(i) {
			print!("0");
		} else {
			print!("1");
		}
	}

}

use std::io;

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

	let mut string2 = String::new();
	io::stdin().read_line(&mut string2).unwrap();

	for i in 0..(string1.len()-1) {
		if string1.chars().nth(i) == string2.chars().nth(i) {
			print!("0");
		} else {
			print!("1");
		}
	}
	println!();
}

use std::io;

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

	let mut string2 = String::new();
	io::stdin().read_line(&mut string2).unwrap();

	for i in 0..string1.len()-1 {
		if string1.chars().nth(i) == string2.chars().nth(i) {
			print!("0");
		} else {
			print!("1");
		}
	}
	println!();
}

use std::io;

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

	let mut string2 = String::new();
	io::stdin().read_line(&mut string2).unwrap();

	for i in 0..string1.len()-1 {
		if string1.chars().nth(i) != string2.chars().nth(i) {
			print!("1");
		} else {
			print!("0");
		}
	}
	println!();
}


There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:   this list contains all Jinotega's flights in this year (in arbitrary order),  Jinotega has only flown from his hometown to a snooker contest and back,  after each competition Jinotega flies back home (though they may attend a competition in one place several times),  and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location!

In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.

If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".

4
SVO
SVO->CDG
LHR->SVO
SVO->LHR
CDG->SVO

NoteIn the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.

use std::collections::HashMap;
use std::io::{self};
use std::str::FromStr;
use std::process;

fn main() {
    let mut buffer = String::new();
    let mut nbuff = String::new();
    let mut flights: HashMap<&str, i8> = HashMap::new();
    let stdin = io::stdin();

    stdin.read_line(&mut buffer).expect("Cannot_read_data1!!!");
    stdin.read_line(&mut buffer).expect("Cannot_read_dat2!!!");
    let lines: Vec<&str> = buffer.trim().split("\n").collect();

    let n: i8 = FromStr::from_str(lines[0].trim()).unwrap();

    let home = lines[1];
    let mut home_vec: Vec<&str> = vec![];

    for _ in 0..n {
        stdin.read_line(&mut nbuff).expect("Cannot_read_dat3!!!");
    }

    let nlines: Vec<&str> = nbuff.trim().split("\n").collect();

    for x in &nlines {
        let points: Vec<&str> = x.trim().split("->").collect();

        if *points[0] == *home {
            home_vec.push(points[1]);
        } else {
            if flights.contains_key(points[0]) {
                if let Some(y) = flights.get_mut(points[0]) {
                    *y += 1;
                }
            } else {
                flights.insert(points[0], 1);
            }
        }
    }

    let mut result = "home";

    for x in &home_vec {
        if !flights.contains_key(x) {
            result = "contest";
            break;
        } else {
            if let Some(y) = flights.get_mut(x) {
                if *y == 0 {
                    result = "contest";
                    break;
                }
                *y -= 1;
            }
        }
    }

    println!("{}", result);
    process::exit(0);

}

use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;

fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    for _ in 0..n + 1 {
        let _: String = sc.ne();
    }
    println!("{}",
             match n & 1 {
                 1 => "contest",
                 _ => "home",
             });
}

fn main() {
    const DEFAULT_STACK: usize = 16 * 1024 * 1024;
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.

The first line of the input contains a positive integer n (1 ≤ n ≤ 2·109) — the length of Pasha's stick.

The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.

NoteThere is only one way to divide the stick in the first sample {1, 1, 2, 2}.Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.

//spnauti-rusT
use std::io::*;
use std::str::{self,*};
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_macros)]
macro_rules! m {
    ($c:tt, $x:expr, $y:expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
#[allow(unused_macros)]
macro_rules! l {
    ($($v:ident),* = $i:ident.$f:ident $a:tt) => {
        $( let $v = $i.$f$a; )*
    };
    ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {
        $( let $v:$t = $i.$f$a; )*
    };
}
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 f(&mut self) ->    f64 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn sk(&mut self, n: usize) { self.it.nth(n - 1); }
    fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> {
        self.ip(n).into_iter()
    }
    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 ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
        self.vp(n).into_iter()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}
//------------------- End rusT

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

    let n = input.i();
    let sol = if n % 2 == 1 {
        0
    } else {
        (n - 2) / 4
    };
    println!("{}", sol);
}

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

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

macro_rules! debug {($($a:expr),*) => {println!(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" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

const MAX:usize = 100006;
const MOD:i64 = 1e9 as i64 + 7;

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

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

use std::f64;

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

use std::hash::Hash;
fn inc<T: Hash+Ord>(map:&mut BTreeMap<T,i64>, key:T) {
    let count = map.entry(key).or_insert(0);
    *count += 1;
}

fn mod_pow(x:i64, n:i64, m:i64) -> i64 {
    let mut x = x;
    let mut n = n;
    let mut res = 1i64;
    while n > 0 {
        if n & 1 > 0 {
            res = res * x % m;
        }
        x = x * x % m;
        n >>= 1;
    }
    res
}

fn main() {
    input!{n:i64};
    if n%2 != 0 {
        println!("0");
        return();
    }
    println!("{}", (n/2-1)/2);
}

use std::io;

macro_rules! parse_line {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        io::stdin().read_line(&mut a_str).unwrap();
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    })
}

fn main() {
    let (mut n,) = parse_line!(u32);
    if n % 2 != 0 {
        println!("{}", 0);
        return;
    }
    n /= 2;
    println!("{}", n / 2 - ((n % 2) ^ 1));
}


Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.

Input will consist of a single integer N (1 ≤ N ≤ 106), the number of city blocks that must be enclosed by the route.

Print the minimum perimeter that can be achieved.

NoteHere are some possible shapes for the examples:

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

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

fn scan_helper(lock : &mut StdinLock) -> String {
    let mut buffer = String::new();
    lock.read_line(&mut buffer).ok();
    buffer
}

macro_rules! scan {
    ($lock:ident, $t:ty) => ({
        scan_helper(&mut $lock).split_whitespace()
            .next().unwrap()
            .parse::<$t>().unwrap()
    });
    ($lock:ident, $($t:ty),+) => ({
        let buffer = scan_helper(&mut $lock);
        let mut iter = buffer.split_whitespace();
        ($(
            {
                iter.next().unwrap()
                    .parse::<$t>().unwrap()
            },
        )+)
    })
}

macro_rules! scan_iter {
    ($lock:ident, $t:ty) => ({
        scan_helper(&mut $lock).split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect()
    })
}

trait Ext {
    fn idx(&self) -> usize;
    fn num(&self) -> i64;
}

macro_rules! ext {
    ($t:ty) => (
        impl Ext for $t {
            #[inline]
            fn idx(&self) -> usize {
                *self as usize
            }

            #[inline]
            fn num(&self) -> i64 {
                *self as i64
            }
        }
    )
}
ext!(i64);
ext!(usize);

macro_rules! derive_regular {
    ($t:ty) => (
        impl Ord for $t {
            fn cmp(&self, other : &$t) -> Ordering {
                self.partial_cmp(other).unwrap()
            }
        }
        impl PartialEq for $t {
            fn eq(&self, other : &$t) -> bool {
                self.cmp(other) == Ordering::Equal
            }
        }
        impl Eq for $t {}
    )
}

fn main() {
    let stdin = stdin();
    let mut s = stdin.lock();
    let n = scan!(s, usize);
    let max_n = 1000000;
    let mut squares = vec![2*max_n; 2001];
    squares[0] = 0;

    let mut i = 1;
    while i*i <= max_n {
        squares[i] = i*i;
        i += 1;
    }

    while squares[i] > n {
        i -= 1;
    }

    let mut result = 4*i;
    let diff = n - squares[i];
    if diff > 0 {
        if diff > i {
            result += 4;
        } else {
            result += 2;
        }
    }

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