Problem:
Score : 200 points

Problem Statement

Snuke is having a barbeque party.

At the party, he will make N servings of Skewer Meal.

Example of a serving of Skewer Meal

He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.
Also, he has an infinite supply of ingredients.

To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Constraints

1≦N≦100

1≦L_i≦100

For each i, L_i is an integer.

Input

The input is given from Standard Input in the following format:

N
L_1 L_2 ... L_{2N}

Output

Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.

Sample Input 1

2
1 3 1 2

Sample Output 1

3

If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.

Sample Input 2

5
100 1 2 3 14 15 58 58 58 29

Sample Output 2

135

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

use std::io::BufRead;

fn main() -> Result<(), Error> {
    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();
    let mut buffer = ReadBuffer::new();

    let n: usize = buffer.read_line(&mut stdin)?.trim().parse()?;

    for _ in 0..(2 * n) {}
    let mut a: Vec<u32> = buffer
        .read_line(&mut stdin)?
        .split_ascii_whitespace()
        .filter_map(|c| c.parse().ok())
        .collect();

    assert_eq!(a.len(), n * 2);

    a.sort();
    let sum: u32 = a.chunks(2).map(|ab| ab[0].min(ab[1])).sum();

    println!("{}", sum);

    Ok(())
}

struct ReadBuffer {
    buffer: Vec<u8>,
    buffer_string: String,
}

#[allow(dead_code)]
impl ReadBuffer {
    fn new() -> Self {
        Self {
            buffer: Vec::new(),
            buffer_string: String::new(),
        }
    }

    fn read_until(&mut self, mut buf: impl BufRead, b: u8) -> Result<&str, std::io::Error> {
        self.buffer.clear();
        buf.read_until(b, &mut self.buffer)?;

        let buffer = std::mem::replace(&mut self.buffer, Vec::new());
        self.buffer_string = unsafe { String::from_utf8_unchecked(buffer) };
        self.buffer = Vec::new();
        Ok(&self.buffer_string)
    }

    fn read_line(&mut self, buf: impl BufRead) -> Result<&str, std::io::Error> {
        self.read_until(buf, b'\n')
    }
}

#[derive(Debug)]
struct Error {
    message: String,
}

impl<E> From<E> for Error
where
    E: std::error::Error,
{
    fn from(error: E) -> Self {
        Self {
            message: format!("Error: {}", error),
        }
    }
}