QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#194488#7523. Partially Free Mealucup-team296#AC ✓1387ms23720kbRust19.9kb2023-09-30 20:55:032023-09-30 20:55:03

Judging History

你现在查看的是最新测评结果

  • [2023-09-30 20:55:03]
  • 评测
  • 测评结果:AC
  • 用时:1387ms
  • 内存:23720kb
  • [2023-09-30 20:55:03]
  • 提交

answer

pub mod solution {
//{"name":"l","group":"Manual","url":"","interactive":false,"timeLimit":2000,"tests":[{"input":"","output":""}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"l"}}}

use std::collections::BTreeSet;

use crate::algo_lib::io::output::output;
use crate::algo_lib::io::task_io_settings::TaskIoType;
use crate::algo_lib::io::task_runner::run_task;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::task_io_settings::TaskIoSettings;
use crate::algo_lib::misc::gen_vector::gen_vec;
use crate::algo_lib::misc::min_max::UpdateMinMax;
#[allow(unused)]
use crate::dbg;
use crate::out;
use crate::out_line;

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Elem {
    a: i64,
    b: i64,
    id: usize,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Res {
    cost: i64,
    pos: usize,
}

#[derive(Clone, Copy, Debug)]
struct Query {
    min_pos: usize,
    max_pos: usize,
    need_cnt: usize,
}

fn solve(input: &mut Input, _test_case: usize) {
    let n = input.usize();
    let mut a = gen_vec(n, |id| Elem {
        a: input.read(),
        b: input.read(),
        id,
    });
    a.sort_by_key(|e| e.b);
    let mut res = vec![
        Res {
            cost: i64::MAX,
            pos: 0
        };
        n + 1
    ];
    {
        let mut sum_a = 0;
        for i in 0..n {
            sum_a += a[i].a;
            res[1].update_min(Res {
                cost: a[i].a + a[i].b,
                pos: i,
            });
        }
        res[n].update_min(Res {
            cost: sum_a + a[n - 1].b,
            pos: n - 1,
        });
    }

    loop {
        let mut queries = vec![];
        {
            let mut i = 0;
            while i + 1 < n {
                if res[i].cost != i64::MAX && res[i + 1].cost == i64::MAX {
                    let mut j = i + 1;
                    while res[j].cost == i64::MAX {
                        j += 1;
                    }
                    let mid = (i + j) / 2;
                    queries.push(Query {
                        min_pos: res[i].pos,
                        max_pos: res[j].pos,
                        need_cnt: mid,
                    });
                    i = j;
                } else {
                    i += 1;
                }
            }
        }
        if queries.is_empty() {
            break;
        }
        let mut set_smaller = BTreeSet::new();
        let mut sum_smaller = 0;
        let mut set_bigger = BTreeSet::new();
        let mut q_it = 0;
        for i in 0..n {
            let elem = a[i];
            sum_smaller += elem.a;
            set_smaller.insert(elem);
            while q_it != queries.len() {
                let need_k = queries[q_it].need_cnt;
                if set_smaller.len() > need_k {
                    let elem = *set_smaller.iter().next_back().unwrap();
                    set_smaller.remove(&elem);
                    sum_smaller -= elem.a;
                    set_bigger.insert(elem);
                }
                while set_smaller.len() < need_k && !set_bigger.is_empty() {
                    let elem = *set_bigger.iter().next().unwrap();
                    set_bigger.remove(&elem);
                    sum_smaller += elem.a;
                    set_smaller.insert(elem);
                }
                if set_smaller.len() == need_k {
                    res[queries[q_it].need_cnt].update_min(Res {
                        cost: sum_smaller + elem.b,
                        pos: i,
                    });
                }
                if queries[q_it].max_pos == i {
                    q_it += 1;
                    assert!(q_it == queries.len() || queries[q_it].min_pos >= i)
                } else {
                    break;
                }
            }
        }
        assert_eq!(q_it, queries.len());
    }
    for i in 1..(n - 1) {
        assert!(res[i].pos <= res[i + 1].pos);
    }
    for i in 1..=n {
        out_line!(res[i].cost);
    }
}

pub(crate) fn run(mut input: Input) -> bool {
    solve(&mut input, 1);
    output().flush();
    true
}

#[allow(unused)]
pub fn submit() -> bool {
    let io = TaskIoSettings {
        is_interactive: false,
        input: TaskIoType::Std,
        output: TaskIoType::Std,
    };

    run_task(io, run)
}

}
pub mod algo_lib {
pub mod io {
pub mod input {
use std::fmt::Debug;
use std::io::Read;
use std::marker::PhantomData;
use std::path::Path;
use std::str::FromStr;

pub struct Input {
    input: Box<dyn Read>,
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
}

macro_rules! read_integer_fun {
    ($t:ident) => {
        #[allow(unused)]
        pub fn $t(&mut self) -> $t {
            self.read_integer()
        }
    };
}

impl Input {
    const DEFAULT_BUF_SIZE: usize = 4096;

    ///
    /// Using with stdin:
    /// ```no_run
    /// use algo_lib::io::input::Input;
    /// let stdin = std::io::stdin();
    /// let input = Input::new(Box::new(stdin));
    /// ```
    ///
    /// For read files use ``new_file`` instead.
    ///
    ///
    pub fn new(input: Box<dyn Read>) -> Self {
        Self {
            input,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_file<P: AsRef<Path>>(path: P) -> Self {
        let file = std::fs::File::open(&path)
            .unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
        Self::new(Box::new(file))
    }

    pub fn new_with_size(input: Box<dyn Read>, buf_size: usize) -> Self {
        Self {
            input,
            buf: vec![0; buf_size],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_file_with_size<P: AsRef<Path>>(path: P, buf_size: usize) -> Self {
        let file = std::fs::File::open(&path)
            .unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
        Self::new_with_size(Box::new(file), buf_size)
    }

    pub fn get(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            self.at += 1;
            Some(res)
        } else {
            None
        }
    }

    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            Some(self.buf[self.at])
        } else {
            None
        }
    }

    pub fn skip_whitespace(&mut self) {
        while let Some(b) = self.peek() {
            if !char::from(b).is_whitespace() {
                return;
            }
            self.get();
        }
    }

    pub fn next_token(&mut self) -> Option<Vec<u8>> {
        self.skip_whitespace();
        let mut res = Vec::new();
        while let Some(c) = self.get() {
            if char::from(c).is_whitespace() {
                break;
            }
            res.push(c);
        }
        if res.is_empty() {
            None
        } else {
            Some(res)
        }
    }

    //noinspection RsSelfConvention
    pub fn is_exhausted(&mut self) -> bool {
        self.peek().is_none()
    }

    pub fn has_more_elements(&mut self) -> bool {
        !self.is_exhausted()
    }

    pub fn read<T: Readable>(&mut self) -> T {
        T::read(self)
    }

    pub fn vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
        let mut res = Vec::with_capacity(size);
        for _ in 0usize..size {
            res.push(self.read());
        }
        res
    }

    pub fn string_vec(&mut self, size: usize) -> Vec<Vec<u8>> {
        let mut res = Vec::with_capacity(size);
        for _ in 0usize..size {
            res.push(self.string());
        }
        res
    }

    pub fn read_line(&mut self) -> String {
        let mut res = String::new();
        while let Some(c) = self.get() {
            if c == b'\n' {
                break;
            }
            if c == b'\r' {
                if self.peek() == Some(b'\n') {
                    self.get();
                }
                break;
            }
            res.push(c.into());
        }
        res
    }

    #[allow(clippy::should_implement_trait)]
    pub fn into_iter<T: Readable>(self) -> InputIterator<T> {
        InputIterator {
            input: self,
            phantom: Default::default(),
        }
    }

    fn read_integer<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let res = self.read_string();
        res.parse::<T>().unwrap()
    }

    fn read_string(&mut self) -> String {
        match self.next_token() {
            None => {
                panic!("Input exhausted");
            }
            Some(res) => unsafe { String::from_utf8_unchecked(res) },
        }
    }

    pub fn string_as_string(&mut self) -> String {
        self.read_string()
    }

    pub fn string(&mut self) -> Vec<u8> {
        self.read_string().into_bytes()
    }

    fn read_char(&mut self) -> char {
        self.skip_whitespace();
        self.get().unwrap().into()
    }

    fn read_float(&mut self) -> f64 {
        self.read_string().parse().unwrap()
    }

    pub fn f64(&mut self) -> f64 {
        self.read_float()
    }

    fn refill_buffer(&mut self) -> bool {
        if self.at == self.buf_read {
            self.at = 0;
            self.buf_read = self.input.read(&mut self.buf).unwrap();
            self.buf_read != 0
        } else {
            true
        }
    }

    read_integer_fun!(i32);
    read_integer_fun!(i64);
    read_integer_fun!(i128);
    read_integer_fun!(u32);
    read_integer_fun!(u64);
    read_integer_fun!(usize);
}

pub trait Readable {
    fn read(input: &mut Input) -> Self;
}

impl Readable for String {
    fn read(input: &mut Input) -> Self {
        input.read_string()
    }
}

impl Readable for char {
    fn read(input: &mut Input) -> Self {
        input.read_char()
    }
}

impl Readable for f64 {
    fn read(input: &mut Input) -> Self {
        input.read_string().parse().unwrap()
    }
}

impl Readable for f32 {
    fn read(input: &mut Input) -> Self {
        input.read_string().parse().unwrap()
    }
}

impl<T: Readable> Readable for Vec<T> {
    fn read(input: &mut Input) -> Self {
        let size = input.read();
        input.vec(size)
    }
}

pub struct InputIterator<T: Readable> {
    input: Input,
    phantom: PhantomData<T>,
}

impl<T: Readable> Iterator for InputIterator<T> {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.input.skip_whitespace();
        self.input.peek().map(|_| self.input.read())
    }
}

macro_rules! read_integer {
    ($t:ident) => {
        impl Readable for $t {
            fn read(input: &mut Input) -> Self {
                input.read_integer()
            }
        }
    };
}

read_integer!(i8);
read_integer!(i16);
read_integer!(i32);
read_integer!(i64);
read_integer!(i128);
read_integer!(isize);
read_integer!(u8);
read_integer!(u16);
read_integer!(u32);
read_integer!(u64);
read_integer!(u128);
read_integer!(usize);
}
pub mod output {
use std::io::Write;

pub struct Output {
    output: Box<dyn Write>,
    buf: Vec<u8>,
    at: usize,
    auto_flush: bool,
}

impl Output {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: false,
        }
    }

    pub fn new_with_auto_flush(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: true,
        }
    }

    pub fn flush(&mut self) {
        if self.at != 0 {
            self.output.write_all(&self.buf[..self.at]).unwrap();
            self.at = 0;
            self.output.flush().expect("Couldn't flush output");
        }
    }

    pub fn print<T: Writable>(&mut self, s: &T) {
        s.write(self);
    }

    pub fn put(&mut self, b: u8) {
        self.buf[self.at] = b;
        self.at += 1;
        if self.at == self.buf.len() {
            self.flush();
        }
    }

    pub fn maybe_flush(&mut self) {
        if self.auto_flush {
            self.flush();
        }
    }

    pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
        for i in arg {
            i.write(self);
            self.put(b'\n');
        }
    }

    pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }

    pub fn print_iter_ref<'a, T: 'a + Writable, I: Iterator<Item = &'a T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }
}

impl Write for Output {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        let mut start = 0usize;
        let mut rem = buf.len();
        while rem > 0 {
            let len = (self.buf.len() - self.at).min(rem);
            self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
            self.at += len;
            if self.at == self.buf.len() {
                self.flush();
            }
            start += len;
            rem -= len;
        }
        if self.auto_flush {
            self.flush();
        }
        Ok(buf.len())
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.flush();
        Ok(())
    }
}

pub trait Writable {
    fn write(&self, output: &mut Output);
}

impl Writable for &str {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for String {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for char {
    fn write(&self, output: &mut Output) {
        output.put(*self as u8);
    }
}

impl<T: Writable> Writable for [T] {
    fn write(&self, output: &mut Output) {
        output.print_iter_ref(self.iter());
    }
}

impl<T: Writable> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self[..].write(output);
    }
}

macro_rules! write_to_string {
    ($t:ident) => {
        impl Writable for $t {
            fn write(&self, output: &mut Output) {
                self.to_string().write(output);
            }
        }
    };
}

write_to_string!(u8);
write_to_string!(u16);
write_to_string!(u32);
write_to_string!(u64);
write_to_string!(u128);
write_to_string!(usize);
write_to_string!(i8);
write_to_string!(i16);
write_to_string!(i32);
write_to_string!(i64);
write_to_string!(i128);
write_to_string!(isize);
write_to_string!(f32);
write_to_string!(f64);

impl<T: Writable, U: Writable> Writable for (T, U) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
    }
}

impl<T: Writable, U: Writable, V: Writable> Writable for (T, U, V) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
        output.put(b' ');
        self.2.write(output);
    }
}

pub static mut OUTPUT: Option<Output> = None;

pub fn set_global_output_to_stdout() {
    unsafe {
        OUTPUT = Some(Output::new(Box::new(std::io::stdout())));
    }
}

pub fn set_global_output_to_file(path: &str) {
    unsafe {
        let out_file =
            std::fs::File::create(path).unwrap_or_else(|_| panic!("Can't create file {}", path));
        OUTPUT = Some(Output::new(Box::new(out_file)));
    }
}

pub fn set_global_output_to_none() {
    unsafe {
        match &mut OUTPUT {
            None => {}
            Some(output) => output.flush(),
        }
        OUTPUT = None;
    }
}

pub fn output() -> &'static mut Output {
    unsafe {
        match &mut OUTPUT {
            None => {
                panic!("Global output wasn't initialized");
            }
            Some(output) => output,
        }
    }
}

#[macro_export]
macro_rules! out {
    ($first: expr $(,$args:expr )*) => {
        output().print(&$first);
        $(output().put(b' ');
        output().print(&$args);
        )*
        output().maybe_flush();
    }
}

#[macro_export]
macro_rules! out_line {
    ($first: expr $(, $args:expr )* ) => {
        {
            out!($first $(,$args)*);
            output().put(b'\n');
            output().maybe_flush();
        }
    };
    () => {
        {
            output().put(b'\n');
            output().maybe_flush();
        }
    };
}
}
pub mod task_io_settings {
pub enum TaskIoType {
    Std,
    File(String),
}

pub struct TaskIoSettings {
    pub is_interactive: bool,
    pub input: TaskIoType,
    pub output: TaskIoType,
}
}
pub mod task_runner {
use std::io::Write;

use super::input::Input;
use super::output::Output;
use super::output::OUTPUT;
use super::task_io_settings::TaskIoSettings;
use super::task_io_settings::TaskIoType;

pub fn run_task<Res>(io: TaskIoSettings, run: impl FnOnce(Input) -> Res) -> Res {
    let output: Box<dyn Write> = match io.output {
        TaskIoType::Std => Box::new(std::io::stdout()),
        TaskIoType::File(file) => {
            let out_file = std::fs::File::create(file).unwrap();
            Box::new(out_file)
        }
    };

    unsafe {
        OUTPUT = Some(Output::new(output));
    }

    let input = match io.input {
        TaskIoType::Std => {
            let sin = std::io::stdin();
            Input::new(Box::new(sin))
        }
        TaskIoType::File(file) => Input::new_file(file),
    };

    run(input)
}
}
}
pub mod misc {
pub mod dbg_macro {
#[macro_export]
#[allow(unused_macros)]
macro_rules! dbg {
    ($first_val:expr, $($val:expr),+ $(,)?) => {
        eprint!("[{}:{}] {} = {:?}",
                    file!(), line!(), stringify!($first_val), &$first_val);
        ($(eprint!(", {} = {:?}", stringify!($val), &$val)),+,);
        eprintln!();
    };
    ($first_val:expr) => {
        eprintln!("[{}:{}] {} = {:?}",
                    file!(), line!(), stringify!($first_val), &$first_val)
    };
}
}
pub mod gen_vector {
pub fn gen_vec<T>(n: usize, f: impl FnMut(usize) -> T) -> Vec<T> {
    (0..n).map(f).collect()
}
}
pub mod min_max {
pub trait UpdateMinMax: PartialOrd + Sized {
    #[inline(always)]
    fn update_min(&mut self, other: Self) -> bool {
        if other < *self {
            *self = other;
            true
        } else {
            false
        }
    }

    #[inline(always)]
    fn update_max(&mut self, other: Self) -> bool {
        if other > *self {
            *self = other;
            true
        } else {
            false
        }
    }
}

impl<T: PartialOrd + Sized> UpdateMinMax for T {}

pub trait FindMinMaxPos {
    fn index_of_min(&self) -> usize;
    fn index_of_max(&self) -> usize;
}

impl<T: PartialOrd> FindMinMaxPos for [T] {
    fn index_of_min(&self) -> usize {
        let mut pos_of_best = 0;
        for (idx, val) in self.iter().enumerate().skip(1) {
            if val < &self[pos_of_best] {
                pos_of_best = idx;
            }
        }
        pos_of_best
    }

    fn index_of_max(&self) -> usize {
        let mut pos_of_best = 0;
        for (idx, val) in self.iter().enumerate().skip(1) {
            if val > &self[pos_of_best] {
                pos_of_best = idx;
            }
        }
        pos_of_best
    }
}

pub fn index_of_min_by<T, F>(n: usize, f: F) -> usize
where
    T: PartialOrd,
    F: Fn(usize) -> T,
{
    assert!(n > 0);
    let mut best_idx = 0;
    let mut best_val = f(0);
    for idx in 1..n {
        let cur_val = f(idx);
        if cur_val < best_val {
            best_val = cur_val;
            best_idx = idx;
        }
    }
    best_idx
}

pub fn index_of_max_by<T, F>(n: usize, f: F) -> usize
where
    T: PartialOrd,
    F: Fn(usize) -> T,
{
    assert!(n > 0);
    let mut best_idx = 0;
    let mut best_val = f(0);
    for idx in 1..n {
        let cur_val = f(idx);
        if cur_val > best_val {
            best_val = cur_val;
            best_idx = idx;
        }
    }
    best_idx
}
}
}
}
fn main() {
    crate::solution::submit();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 2136kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1325ms
memory: 22756kb

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:

1318594
3208018
5570526
7340845
9223347
11149865
12332210
13476823
14788280
16172895
17768627
19336633
20693779
22005236
23389851
25073157
26760338
28509336
30294967
32093959
33976461
35893858
37754030
39588384
41470886
43388283
45309771
47309654
48837539
50417767
52079411
53762717
55190044
56577630...

result:

ok 200000 lines

Test #3:

score: 0
Accepted
time: 1302ms
memory: 22688kb

input:

200000
847759212 808195187
499393947 158845704
286713001 829058634
347836790 268095042
525802369 342098012
260721485 611292083
95451146 853465743
666288241 921988396
958024432 522176958
284971271 952579505
408975858 657474613
444942472 596256250
291446883 538551864
942712385 142670067
239468458 9590...

output:

1398661
1990331
2912658
4186260
5510021
7421286
8925937
10233209
11427663
12466304
13739906
15048281
16438721
17917204
19556134
21034617
22945882
24964675
27046288
28988324
30624067
32102550
33629849
35258767
36683909
38129744
39608227
41135526
42764444
44559165
46466041
48377306
49860205
51250645
5...

result:

ok 200000 lines

Test #4:

score: 0
Accepted
time: 1303ms
memory: 23720kb

input:

200000
453045091 809721921
853476741 595698118
218851090 887561745
864896419 760665890
291906050 833777661
706333418 479486544
207093005 36386646
969262171 137545723
501777026 470632513
238108337 821895650
757244578 277013047
715147479 651214680
995278884 359331973
20441197 903583173
61588145 378817...

output:

1629450
3451675
5862264
7342961
8475016
9707673
11350240
13021035
14824028
16466595
18145506
19755199
21397766
23219991
25058891
26869771
28383182
29992875
31635442
33457667
35296567
37269548
39205891
41028116
42867016
44839997
46268352
47600752
48988255
50421419
51854715
53368126
54897681
56507374
...

result:

ok 200000 lines

Test #5:

score: 0
Accepted
time: 1385ms
memory: 23660kb

input:

200000
724371 812164590
786885 853213841
375367 446887348
442587 266053048
910413 644441954
304737 493015342
449866 304716006
711453 152694644
405700 232509173
921335 223801102
979624 725734275
524990 894904581
975621 908452940
211492 159635302
996047 882815311
201533 598711233
152477 256633677
9411...

output:

112065
210146
299616
337074
391448
445884
500608
562757
637222
714160
812241
882389
944538
1019003
1095941
1179290
1276070
1329394
1383830
1438554
1500703
1564162
1638627
1715565
1798914
1886244
1975154
2064372
2159112
2230385
2293760
2357219
2421075
2486440
2560905
2636978
2713916
2797265
2883902
2...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 1387ms
memory: 22900kb

input:

200000
82260 816973645
63190 30304976
15365 98123005
79313 698909248
88351 460688945
45258 145977968
35624 362819795
34062 929296068
13142 373585892
93631 33870837
47414 576582646
25940 764754575
8424 255583152
73559 151261046
51329 935294030
89414 108264540
14984 966447646
70866 477634636
7290 9827...

output:

13886
30185
60597
84857
106218
121551
137850
159549
187975
207878
228613
247795
267766
282648
297981
314280
332886
353621
374388
396087
418706
437819
458554
479321
499571
520306
541073
562772
582630
603365
624132
645831
668408
688579
709314
730081
751780
774399
798048
821818
847209
872827
901523
930...

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 1244ms
memory: 22476kb

input:

200000
1286 819121925
8997 273901462
8502 181755051
7515 175443695
5821 856272297
7390 111029219
5073 269357259
1581 35806553
7694 913461554
8300 307364045
8256 33038036
5700 229695181
250 919848697
7280 624783228
434 719961279
1232 128882963
8258 924021143
3834 843971163
5625 811204037
1492 2383695...

output:

10995
13359
18477
23804
38945
55481
60947
66065
70271
75389
80027
84800
89342
93179
97100
101148
106126
111244
116478
121825
128995
137178
145792
155005
164337
174083
183478
191218
197417
203657
211242
219019
226857
233378
240963
248740
256578
264569
272752
280960
289628
298655
306432
314270
322261
...

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 958ms
memory: 23696kb

input:

200000
567 821597362
373 531417185
779 814789710
275 754605445
952 666936589
710 124558017
702 537686619
862 50955474
368 675370982
298 782978552
302 481759264
979 473352314
43 395227840
286 954544414
336 150250305
150 259994546
687 928911202
544 406240134
464 667581860
838 887654894
448 771976144
6...

output:

2235
2529
8117
9377
11127
12070
13052
14782
17841
27938
30643
32380
33341
34322
35554
40606
41587
48349
49885
50880
55974
61036
62947
63942
65127
67401
71096
73392
83699
85485
91937
97919
99466
100691
109601
116546
117649
119086
120067
121062
123036
127602
135828
136809
137804
139170
140993
143831
1...

result:

ok 200000 lines

Test #9:

score: 0
Accepted
time: 658ms
memory: 22528kb

input:

200000
342509701 342369477
832528915 833461380
305083321 305636073
97787821 97798679
401112695 400166019
206883814 207488357
445079803 443330686
821303339 823004195
951351563 950383862
236686106 237217287
770566641 771324127
877496005 877642151
663255937 664202372
135673848 136103612
150951930 15070...

output:

4774
13192
28262
41294
54737
69177
87401
108979
136735
171516
203369
235932
272900
312322
349380
390783
439807
483352
532557
582602
633629
687385
738524
790936
844462
900935
961981
1024307
1084112
1146567
1211897
1274425
1338357
1406537
1479843
1556923
1633866
1711704
1791657
1881450
1970659
2062277...

result:

ok 200000 lines

Test #10:

score: 0
Accepted
time: 791ms
memory: 22428kb

input:

200000
424022414 503814435
806902283 120847887
159591289 767965342
995943523 2143610
92544520 834485542
527264427 400514062
828167614 99803183
413473955 513851792
24326747 951399406
6268451 987557869
6272849 987547914
870148328 65988204
303041365 624808224
484331263 443537008
37039932 926091659
4153...

output:

925350356
999391812
999994451
1000006025
1000021200
1000037835
1000056852
1000076740
1000097083
1000120901
1000147884
1000181988
1000216572
1000251650
1000286776
1000323768
1000366528
1000422287
1000481162
1000540533
1000608040
1000675799
1000746490
1000821377
1000897452
1000976676
1001058192
100114...

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 806ms
memory: 22556kb

input:

200000
9759806 12862172
8415499 95736535
1664414 820629803
7565617 186586129
261111 972339624
7956621 143743367
6294429 322756312
4413454 523200143
3368006 635522804
7403517 204183948
608424 934830718
4422409 522274240
1913974 793736435
8057121 133077799
5980092 355887936
3993010 567818961
4942527 4...

output:

10000783
20011188
30022081
40022551
50024199
60026734
70028178
80028243
90028965
100046652
110055224
120055198
130055194
140057106
150062462
160062436
170062432
180064899
190064522
200064261
210064094
220063840
230063579
240063412
250063301
260063275
270063271
280063802
290064997
300063037
310060827...

result:

ok 200000 lines

Test #12:

score: 0
Accepted
time: 849ms
memory: 22576kb

input:

200000
496345 466577657
386215 586183375
35313 961776167
224787 757007012
129801 860004317
534510 426004787
538049 421998089
582677 373345535
638985 313251583
440542 527987482
314859 661869183
464254 501661850
381786 590849519
336796 638644881
436826 532036806
967339 17549076
948496 27686222
435981 ...

output:

1002712
2004799
3009688
4018445
5020295
6024231
7024510
8027273
9033770
10033936
11035128
12037972
13041280
14044477
15046153
16047926
17051947
18054285
19055635
20058952
21060245
22064572
23064761
24066353
25066487
26068892
27069602
28071028
29071938
30075808
31076639
32077776
33081667
34082393
350...

result:

ok 200000 lines

Test #13:

score: 0
Accepted
time: 987ms
memory: 23656kb

input:

200000
15216 836840562
70964 236430015
63200 319769248
72638 218445383
50711 453882897
7142 922491104
31371 662544679
60197 352769322
41403 554098222
76954 173314909
83661 102670370
92697 39042364
10030 892110253
39376 576601232
48265 480542224
74934 195010760
92547 39963180
7838 915208475
81256 128...

output:

104238
207651
309282
409662
510001
616589
720325
821076
925357
1030343
1131525
1232102
1332478
1433483
1538744
1642201
1747262
1847472
1947556
2047760
2154162
2255836
2355863
2457381
2557722
2657969
2757985
2861246
2968808
3073504
3180373
3284338
3388918
3489105
3589161
3692633
3794227
3904391
40047...

result:

ok 200000 lines

Test #14:

score: 0
Accepted
time: 846ms
memory: 22584kb

input:

200000
4678 497931091
2640 716453432
6128 342231079
8613 73961599
6966 252076583
3235 652413490
6687 281932985
5435 417357447
8145 123716301
1029 890108476
8087 130103799
9604 21356741
3855 586162704
3077 669287066
6905 258832414
8309 106104565
9921 4362813
4232 545009314
5371 423589629
3869 5846781...

output:

14579
25122
38514
54746
65555
76413
99719
113491
128752
140022
153279
167111
179004
192410
202723
215381
226126
236576
247249
257830
267919
280431
294595
304934
315546
328726
341429
358430
371825
382901
394180
405288
417371
431424
442612
453822
473579
493771
503880
521850
533608
544570
556337
568376...

result:

ok 200000 lines

Test #15:

score: 0
Accepted
time: 623ms
memory: 22468kb

input:

200000
27 972604774
156 832885943
161 827754255
877 67082798
943 31056414
243 740861264
60 937391032
229 756995050
222 763374572
716 231870198
445 522461729
509 452792900
588 369495498
661 290499149
818 122716973
63 933851278
128 863054306
528 431656637
270 710563993
979 12062387
276 703934949
483 4...

output:

6882
15009
18343
26780
28171
30634
48686
50820
57412
58718
60404
61525
68888
74001
75071
77154
78786
80464
88174
91233
94246
95615
97463
103806
106975
110006
113520
115308
123130
128798
137120
140594
142982
145385
146791
148761
155966
158695
162930
164268
165619
166792
170367
172525
176505
178059
18...

result:

ok 200000 lines

Test #16:

score: 0
Accepted
time: 702ms
memory: 22708kb

input:

200000
11 892126160
2 986862649
83 118159385
50 474606235
30 681179212
92 43004615
77 181587331
94 33800665
26 726163332
19 800955104
7 933100010
9 911106127
32 663731276
58 382884421
78 172731234
41 568328829
67 290835641
49 480293195
13 861453787
21 784813797
28 708545692
79 159193875
83 113012768...

output:

317
11873
13115
14025
14330
14983
19602
27044
28254
28746
32462
33642
38161
42404
44581
48582
49445
50652
55013
56448
61812
61939
62720
63555
64046
68780
72247
75938
77932
79081
81666
83359
85092
88610
92584
93935
101257
109306
111290
117823
119842
121331
123366
124841
124962
128531
135178
136626
13...

result:

ok 200000 lines