use std::io::{stdin, Read};
use libc::{clock_gettime, timespec, CLOCK_PROCESS_CPUTIME_ID};

fn main() {
    let mut data = String::new();
    stdin().read_to_string(&mut data).unwrap();

    let mut begin = timespec {
        tv_sec: 0,
        tv_nsec: 0,
    };
    unsafe {
        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mut begin);
    };

    let mut num1 = vec![];
    let mut num2 = vec![];

    for line in data.lines() {
        let numbers: Vec<&str> = line.split("   ").collect();
        let num11: i32 = numbers[0].parse().unwrap();
        let num22: i32 = numbers[1].parse().unwrap();
        num1.push(num11);
        num2.push(num22);
    }

    let mut sum = 0;

    for i in num1 {
        let mut count = 0;
        for num in &num2 {
            if i == *num {
                count += 1;
            }
        }
        sum += i * count;
    }
    println!("{sum:?}");
    let mut end = timespec {
        tv_sec: 0,
        tv_nsec: 0,
    };
    unsafe {
        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mut end);
    };
    println!(
        "time: {:.6}ms",
        (end.tv_nsec - begin.tv_nsec) as f32 / 1000.0 / 1000.0
    );
}
