#![allow(dead_code, unused_imports)]

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

fn read_stdin() -> String {
    let mut s = String::new();
    std::io::stdin()
        .read_line(&mut s)
        .expect("cannot read stdin");
    s.trim().to_string()
}

fn read<T>() -> T
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    read_stdin().parse::<T>().unwrap()
}

fn read_usize() -> usize {
    read::<usize>()
}

fn read_2<A, B>() -> (A, B)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    (a, b)
}

fn read_3<A, B, C>() -> (A, B, C)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    (a, b, c)
}

fn read_4<A, B, C, D>() -> (A, B, C, D)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
    D: FromStr,
    <D as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    let d = s.next().unwrap().parse::<D>().unwrap();
    (a, b, c, d)
}

fn read_multiple<T: FromStr>() -> Vec<T>
where
    <T as FromStr>::Err: Debug,
{
    read_stdin()
        .split_whitespace()
        .map(|x| x.parse::<T>().expect("cannot parse stdin"))
        .collect()
}

/// NOTE: sort iter beforehand if required
fn count<T>(iter: &mut impl Iterator<Item = T>) -> Vec<(T, usize)>
where
    T: std::cmp::Ord,
{
    let iter = iter.collect::<Vec<_>>();
    //iter.sort();
    let (mut v, o, c) =
        iter.into_iter()
            .fold((Vec::new(), None, 0), |(mut v, last, count), item| {
                if let Some(o) = last {
                    if item == o {
                        (v, Some(o), count + 1)
                    } else {
                        v.push((o, count));
                        (v, Some(item), 1)
                    }
                } else {
                    (v, Some(item), 1)
                }
            });
    if let Some(i) = o {
        v.push((i, c));
    }
    v
}

fn max_subarray(v: impl Iterator<Item = i64>) -> (i64, (usize, usize)) {
    //assert!(v.len() > 0);
    let mut best_sum = 0;
    let (mut best_start, mut best_end) = (0, 0);
    let mut current_sum = 0;
    let mut current_start = 0;
    for (end, val) in v.enumerate() {
        if current_sum <= 0 {
            current_start = end;
            current_sum = val;
        } else {
            current_sum += val;
        }
        if current_sum > best_sum {
            best_sum = current_sum;
            best_start = current_start;
            best_end = end + 1;
        }
    }
    (best_sum, (best_start, best_end))
}

fn gcd(mut a: u64, mut b: u64) -> u64 {
    while a != 0 {
        let old_m = a;
        a = b % a;
        b = old_m;
    }
    b
}

/// returns gcd, and pair (x, y), such that x * a + b * y == gcd
fn egcd(a: i64, b: i64) -> (i64, i64, i64) {
    if a == 0 {
        (b, 0, 1)
    } else {
        let (g, x, y) = egcd(b % a, a);
        (g, y - (b / a) * x, x)
    }
}

fn factorize(mut n: u64) -> Vec<u64> {
    if n <= 3 {
        return vec![n];
    }
    let mut v = Vec::new();
    while n % 2 == 0 {
        n /= 2;
        v.push(2);
    }
    while n % 3 == 0 {
        n /= 3;
        v.push(3);
    }
    let mut f = 6;
    while (f - 1) * (f - 1) <= n {
        while n % (f - 1) == 0 {
            n /= f - 1;
            v.push(f - 1);
        }
        while n % (f + 1) == 0 {
            n /= f + 1;
            v.push(f + 1);
        }
        f += 6;
    }
    if n > 1 {
        v.push(n);
    }
    v
}

fn compact_factors(n: u64) -> Vec<(u64, usize)> {
    count(&mut factorize(n).into_iter())
}

fn all_factors(n: u64) -> Vec<u64> {
    let factors = compact_factors(n);
    let mut v = vec![1];
    for (fac, num) in factors {
        let ori = v.clone();
        for i in 1..num + 1 {
            v.append(
                &mut ori
                    .clone()
                    .into_iter()
                    .map(|f| f * fac.pow(i as u32))
                    .collect::<Vec<_>>(),
            )
        }
    }
    v.sort();
    v
}

fn abs_diff<T>(a: T, b: T) -> T
where
    T: PartialOrd + std::ops::Sub<Output = T>,
{
    if a > b {
        a - b
    } else {
        b - a
    }
}

use std::cmp::{max, min};
use std::collections::VecDeque;
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let _n = read_usize();
    let a_vec = read_multiple::<u8>();
    let mut two = Vec::new();
    let mut pending = Vec::new();
    let mut targets = Vec::new();
    for (c, a) in a_vec.into_iter().enumerate() {
        let c = c + 1;
        if a == 0 {
            // nothing on this col
        } else if a == 1 {
            if let Some(prev) = two.pop() {
                targets.push((c, prev));
            } else if let Some(prev) = pending.pop() {
                targets.push((prev, prev));
                targets.push((prev, c));
            }
            targets.push((c, c))
        } else if a == 2 {
            if let Some(prev) = pending.pop() {
                targets.push((prev, prev));
                targets.push((prev, c));
            }
            two.push(c)
        } else if a == 3 {
            if let Some(prev) = pending.pop() {
                targets.push((prev, prev));
                targets.push((prev, c));
            }
            pending.push(c)
        }
    }
    if two.is_empty() && pending.is_empty() {
        println!("{}", targets.len());
        for target in targets {
            println!("{} {}", target.0, target.1)
        }
    } else {
        println!("-1")
    }
    Ok(())
}


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

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    #[allow(unused)]
    macro_rules! putvec {
        ($v:expr) => {
            for i in 0..$v.len() {
                puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
            }
        }
    }
    macro_rules! fail {
        () => {
            puts!("-1\n");
            return;
        }
    }
    input! {
        n: usize,
        a: [usize; n],
    }
    if a[n - 1] >= 2 {
        puts!("-1\n");
        return;
    }
    let mut lv = 0;
    let mut ans = vec![];
    let mut unm1 = vec![];
    let mut unm23 = vec![];
    let mut nxt = vec![n; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        }
        if a[i] == 1 {
            unm1.push(i);
        } else if a[i] == 2 {
            if unm1.is_empty() {
                fail!();
            }
            let x = unm1.pop().unwrap();
            nxt[i] = x;
        } else {
            assert_eq!(a[i], 3);
            if let Some(x) = unm23.pop() {
                nxt[i] = x;
            } else {
                if let Some(x) = unm1.pop() {
                    nxt[i] = x;
                } else {
                    fail!();
                }
            }
        }
    }
    let mut vis = vec![false; n];
    for i in 0..n {
        if vis[i] {
            continue;
        }
        if a[i] == 0 {
            continue;
        }
        let mut cur = i;
        let mut debt = false;
        loop {
            vis[cur] = true;
            if debt {
                ans.push((cur, lv - 1));
            }
            ans.push((cur, lv));
            debt = a[cur] >= 3;
            if a[cur] == 3 {
                lv += 1;
            }
            if nxt[cur] >= n {
                break;
            }
            cur = nxt[cur];
        }
        lv += 1;
    }
    ans.sort();
    puts!("{}\n", ans.len());
    for i in 0..ans.len() {
        let (x, y) = ans[i];
        puts!("{} {}\n", y + 1, x + 1);
    }
}

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


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

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    #[allow(unused)]
    macro_rules! putvec {
        ($v:expr) => {
            for i in 0..$v.len() {
                puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
            }
        }
    }
    macro_rules! fail {
        () => {
            puts!("-1\n");
            return;
        }
    }
    input! {
        n: usize,
        a: [usize; n],
    }
    if a[n - 1] >= 2 {
        puts!("-1\n");
        return;
    }
    let mut lv = 0;
    let mut ans = vec![];
    let mut unm1 = vec![];
    let mut unm23 = vec![];
    let mut nxt = vec![n; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        }
        if a[i] == 1 {
            unm1.push(i);
        } else if a[i] == 2 {
            if unm1.is_empty() {
                fail!();
            }
            let x = unm1.pop().unwrap();
            nxt[i] = x;
            unm23.push(i);
        } else {
            assert_eq!(a[i], 3);
            if let Some(x) = unm23.pop() {
                nxt[i] = x;
            } else {
                if let Some(x) = unm1.pop() {
                    nxt[i] = x;
                } else {
                    fail!();
                }
            }
            unm23.push(i);
        }
    }
    let mut vis = vec![false; n];
    for i in 0..n {
        if vis[i] {
            continue;
        }
        if a[i] == 0 {
            continue;
        }
        let mut cur = i;
        let mut debt = false;
        loop {
            vis[cur] = true;
            if debt {
                ans.push((cur, lv - 1));
            }
            ans.push((cur, lv));
            debt = a[cur] >= 3;
            if a[cur] == 3 {
                lv += 1;
            }
            if nxt[cur] >= n {
                break;
            }
            cur = nxt[cur];
        }
        lv += 1;
    }
    ans.sort();
    puts!("{}\n", ans.len());
    for i in 0..ans.len() {
        let (x, y) = ans[i];
        puts!("{} {}\n", y + 1, x + 1);
    }
}

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


#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut res = vec![];
    let mut three = None;
    let mut connected = vec![None; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        } else if a[i] == 1 {
            res.push(i);
        } else if a[i] == 2 {
            if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
            three = Some(i);
        } else {
            if let Some(pair) = three {
                connected[i] = Some(pair);
            } else if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
            three = Some(i);
        }
    }
    // debug!(connected);

    let mut answers = vec![];
    let mut last = 0;
    let mut used = HashSet::new();
    for i in 0..n {
        if a[i] == 0 || used.contains(&i) {
            continue;
        }
        if a[i] == 1 {
            answers.push((i, last));
            last += 1;
            continue;
        }
        if a[i] == 2 {
            if let Some(pair) = connected[i] {
                used.insert(pair);
                if a[i] == 2 {
                    answers.push((i, last));
                    answers.push((pair, last));
                    last += 1;
                }
            }
        } else {
            assert_eq!(a[i], 3);
            answers.push((i, last));
            let mut cur = i;
            let mut prev = cur;
            while let Some(pair) = connected[cur] {
                used.insert(pair);
                answers.push((pair, last));
                answers.push((pair, last + 1));

                prev = cur;
                cur = pair;
                last += 1;
            }
            if a[prev] == 2 {
                answers.pop();
            }

            last = answers[answers.len() - 1].1 + 1;
        }
    }
    let mut answers = answers.iter().map(|&x| (x.1, x.0)).collect::<Vec<_>>();
    answers.sort();
    println!("{}", answers.len());

    for (a, b) in answers {
        println!("{} {}", a + 1, b + 1);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut res = vec![];
    let mut connected = vec![None; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        } else if a[i] == 1 {
            res.push(i);
        } else if a[i] == 2 || a[i] == 3 {
            if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
        }
    }
    // debug!(connected);

    let mut answers = vec![];
    let mut last = 0;
    let mut used = HashSet::new();
    for i in 0..n {
        if a[i] == 0 {
            continue;
        }
        if let Some(pair) = connected[i] {
            used.insert(pair);
            if a[i] == 2 {
                answers.push((i, last));
                answers.push((pair, last));
                last += 1;
            } else {
                assert_eq!(a[i], 3);
                answers.push((i, last));
                answers.push((pair, last));
                answers.push((pair, last + 1));
                last += 2;
            }
        } else {
            assert_eq!(a[i], 1);
            if !used.contains(&i) {
                answers.push((i, last));
                last += 1;
            }
        }
    }
    if last >= n {
        println!("-1");
        return;
    }
    let mut answers = answers.iter().map(|&x| (x.1, x.0)).collect::<Vec<_>>();
    answers.sort();
    println!("{}", answers.len());

    for (a, b) in answers {
        println!("{} {}", a + 1, b + 1);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut res = vec![];
    let mut three = None;
    let mut connected = vec![None; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        } else if a[i] == 1 {
            res.push(i);
        } else if a[i] == 2 {
            if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
        } else {
            if let Some(pair) = three {
                connected[i] = Some(pair);
            } else if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
            three = Some(i);
        }
    }
    // debug!(connected);

    let mut answers = vec![];
    let mut last = 0;
    let mut used = HashSet::new();
    for i in 0..n {
        if a[i] == 0 || used.contains(&i) {
            continue;
        }
        if a[i] == 1 {
            answers.push((i, last));
            last += 1;
            continue;
        }
        if a[i] == 2 {
            if let Some(pair) = connected[i] {
                used.insert(pair);
                if a[i] == 2 {
                    answers.push((i, last));
                    answers.push((pair, last));
                    last += 1;
                }
            }
        } else {
            assert_eq!(a[i], 3);
            answers.push((i, last));
            let mut cur = i;
            while let Some(pair) = connected[cur] {
                used.insert(pair);
                answers.push((pair, last));
                answers.push((pair, last + 1));
                cur = pair;
                last += 1;
            }
        }
    }
    let mut answers = answers.iter().map(|&x| (x.1, x.0)).collect::<Vec<_>>();
    answers.sort();
    println!("{}", answers.len());

    for (a, b) in answers {
        println!("{} {}", a + 1, b + 1);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut res = vec![];
    let mut connected = vec![None; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        } else if a[i] == 1 {
            res.push(i);
        } else if a[i] == 2 || a[i] == 3 {
            if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
        }
    }
    // debug!(connected);

    let mut answers = vec![];
    let mut last = 0;
    let mut used = HashSet::new();
    for i in 0..n {
        if a[i] == 0 {
            continue;
        }
        if let Some(pair) = connected[i] {
            used.insert(pair);
            if a[i] == 2 {
                answers.push((i, last));
                answers.push((pair, last));
                last += 1;
            } else {
                assert_eq!(a[i], 3);
                answers.push((i, last));
                answers.push((pair, last));
                answers.push((pair, last + 1));
                last += 2;
            }
        } else {
            assert_eq!(a[i], 1);
            if !used.contains(&i) {
                answers.push((i, last));
                last += 1;
            }
        }
    }
    let mut answers = answers.iter().map(|&x| (x.1, x.0)).collect::<Vec<_>>();
    answers.sort();
    println!("{}", answers.len());

    for (a, b) in answers {
        println!("{} {}", a + 1, b + 1);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut res = vec![];
    let mut three = None;
    let mut connected = vec![None; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        } else if a[i] == 1 {
            res.push(i);
        } else if a[i] == 2 {
            if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
        } else {
            if let Some(pair) = three {
                connected[i] = Some(pair);
            } else if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
            three = Some(i);
        }
    }
    // debug!(connected);

    let mut answers = vec![];
    let mut last = 0;
    let mut used = HashSet::new();
    for i in 0..n {
        if a[i] == 0 || used.contains(&i) {
            continue;
        }
        if a[i] == 1 {
            answers.push((i, last));
            last += 1;
            continue;
        }
        if a[i] == 2 {
            if let Some(pair) = connected[i] {
                used.insert(pair);
                if a[i] == 2 {
                    answers.push((i, last));
                    answers.push((pair, last));
                    last += 1;
                }
            }
        } else {
            assert_eq!(a[i], 3);
            answers.push((i, last));
            let mut cur = i;
            while let Some(pair) = connected[cur] {
                used.insert(pair);
                answers.push((pair, last));
                answers.push((pair, last + 1));
                cur = pair;
                last += 2;
            }
        }
    }
    let mut answers = answers.iter().map(|&x| (x.1, x.0)).collect::<Vec<_>>();
    answers.sort();
    println!("{}", answers.len());

    for (a, b) in answers {
        println!("{} {}", a + 1, b + 1);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut res = vec![];
    let mut connected = vec![None; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        } else if a[i] == 1 {
            res.push(i);
        } else if a[i] == 2 || a[i] == 3 {
            if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
        }
    }
    // debug!(connected);

    let mut answers = vec![];
    let mut last = 0;
    let mut used = HashSet::new();
    for i in 0..n {
        if a[i] == 0 {
            continue;
        }
        if let Some(pair) = connected[i] {
            used.insert(pair);
            if a[i] == 2 {
                answers.push((i, last));
                answers.push((pair, last));
                last += 1;
            } else {
                assert_eq!(a[i], 3);
                answers.push((i, last + 1));
                answers.push((pair, last + 1));
                answers.push((pair, last));
                last += 2;
            }
        } else {
            assert_eq!(a[i], 1);
            if !used.contains(&i) {
                answers.push((i, last));
                last += 1;
            }
        }
    }
    if last >= n {
        println!("-1");
        return;
    }
    // answers.sort_by();
    println!("{}", answers.len());

    for (a, b) in answers {
        println!("{} {}", b + 1, a + 1);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut res = vec![];
    let mut connected = vec![None; n];
    for i in (0..n).rev() {
        if a[i] == 0 {
            continue;
        } else if a[i] == 1 {
            res.push(i);
        } else if a[i] == 2 || a[i] == 3 {
            if let Some(pair) = res.pop() {
                connected[i] = Some(pair);
            } else {
                println!("-1");
                return;
            }
        }
    }
    // debug!(connected);

    let mut answers = vec![];
    let mut last = 0;
    let mut used = HashSet::new();
    for i in 0..n {
        if a[i] == 0 {
            continue;
        }
        if let Some(pair) = connected[i] {
            used.insert(pair);
            if a[i] == 2 {
                answers.push((i, last));
                answers.push((pair, last));
                last += 1;
            } else {
                assert_eq!(a[i], 3);
                answers.push((i, last + 1));
                answers.push((pair, last + 1));
                answers.push((pair, last));
                last += 2;
            }
        } else {
            assert_eq!(a[i], 1);
            if !used.contains(&i) {
                answers.push((i, last));
                last += 1;
            }
        }
    }
    if last >= n {
        println!("-1");
        return;
    }
    println!("{}", answers.len());
    for (a, b) in answers {
        println!("{} {}", a + 1, b + 1);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


/*
    date   : 2020 / 5 / 5
    author : quickn (quickn.ga)
    email  : quickwshell@gmail.com
*/

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

mod scanner {
    use std::{io, str};
    /* https://github.com/EbTech/rust-algorithms */

    /// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
    /// **REQUIRES** Rust 1.34 or higher
    pub struct UnsafeScanner<R> {
        reader: R,
        buf_str: Vec<u8>,
        buf_iter: str::SplitAsciiWhitespace<'static>,
    }

    impl<R: io::BufRead> UnsafeScanner<R> {
        pub fn new(reader: R) -> Self {
            Self {
                reader,
                buf_str: Vec::new(),
                buf_iter: "".split_ascii_whitespace(),
            }
        }

        /// This function should be marked unsafe, but noone has time for that in a
        /// programming contest. Use at your own risk!
        pub fn token<T: 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 = str::from_utf8_unchecked(&self.buf_str);
                    std::mem::transmute(slice.split_ascii_whitespace())
                }
            }
        }
    }
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let (mut scan, mut sout) = (
        scanner::UnsafeScanner::new(stdin.lock()),
        BufWriter::new(stdout.lock()),
    );
    let n: usize = scan.token();
    let mut arr: Vec<u8> = vec![0;n];
    for i in 0..n {
        arr[i] = scan.token();
    }
    let mut failed = false;
    let mut res: Vec<(usize, usize)> = vec![];
    let mut row = 1;
    let mut s2: Vec<usize> = vec![];
    let mut s3: Vec<usize> = vec![];
    for i in 0..n {
        let mut assigned = false;
        if arr[i] != 0 && s3.len() > 0 {
            if let Some(r) = s3.pop() {
                res.push((r, i+1));
                assigned = true;
            }
        }
        if arr[i] == 1 {
            if s2.len() > 0 && !assigned {
                if let Some(r) = s2.pop() {
                    res.push((r, i+1));
                }
            } else {
                res.push((row, i+1));
                row += 1;
            }
        } else if arr[i] == 2 {
            res.push((row, i+1));
            s2.push(row);
            row += 1;
        } else if arr[i] == 3 {
            res.push((row, i+1));
            s3.push(row);
            row += 1;
        }
    }
    if s3.len() > 0 || s2.len() > 0 {
        failed = true;
    }
    let mut row: Vec<usize> = vec![0;n];
    let mut col: Vec<usize> = vec![0;n];
    for (a, b) in res.clone() {
        if a > n {
            failed = true;
            break;
        }
        row[a-1] += 1;
        col[b-1] += 1;
    }
    for i in 0..n {
        if row[i] > 2 {
            failed = true;
            break;
        }
    }
    for i in 0..n {
        if col[i] > 2 {
            failed = true;
            break;
        }
    }
    if failed {
        writeln!(sout, "-1").ok();
    } else {
        writeln!(sout, "{}", res.len()).ok();
        for (a, b) in res.clone() {
            writeln!(sout, "{} {}", a, b).ok();
        }
    }
}


pub trait Zero: PartialEq + Sized {
    fn zero() -> Self;
    #[inline]
    fn is_zero(&self) -> bool {
        self == &Self::zero()
    }
}
pub trait One: PartialEq + Sized {
    fn one() -> Self;
    #[inline]
    fn is_one(&self) -> bool {
        self == &Self::one()
    }
}
macro_rules ! zero_one_impls { ($ ({ $ Trait : ident $ method : ident $ ($ t : ty) *, $ e : expr }) *) => { $ ($ (impl $ Trait for $ t { # [inline] fn $ method () -> Self { $ e } }) *) * } ; }
zero_one_impls ! ({ Zero zero u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 0 } { Zero zero f32 f64 , 0. } { One one u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 1 } { One one f32 f64 , 1. }) ;
#[macro_export]
macro_rules ! min { ($ e : expr) => { $ e } ; ($ e : expr , $ ($ es : expr) ,+) => { std :: cmp :: min ($ e , min ! ($ ($ es) ,+)) } ; }
#[macro_export]
macro_rules ! chmin { ($ dst : expr , $ ($ src : expr) ,+) => { { let x = std :: cmp :: min ($ dst , min ! ($ ($ src) ,+)) ; $ dst = x ; } } ; }
#[macro_export]
macro_rules ! max { ($ e : expr) => { $ e } ; ($ e : expr , $ ($ es : expr) ,+) => { std :: cmp :: max ($ e , max ! ($ ($ es) ,+)) } ; }
#[macro_export]
macro_rules ! chmax { ($ dst : expr , $ ($ src : expr) ,+) => { { let x = std :: cmp :: max ($ dst , max ! ($ ($ src) ,+)) ; $ dst = x ; } } ; }
pub trait IterScan: Sized {
    type Output;
    fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output>;
}
pub trait MarkedIterScan: Sized {
    type Output;
    fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output>;
}
#[derive(Clone, Debug)]
pub struct Scanner<'a> {
    iter: std::str::SplitAsciiWhitespace<'a>,
}
mod scanner_impls {
    use super::*;
    impl<'a> Scanner<'a> {
        #[inline]
        pub fn new(s: &'a str) -> Self {
            let iter = s.split_ascii_whitespace();
            Self { iter }
        }
        #[inline]
        pub fn scan<T: IterScan>(&mut self) -> <T as IterScan>::Output {
            <T as IterScan>::scan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn mscan<T: MarkedIterScan>(&mut self, marker: T) -> <T as MarkedIterScan>::Output {
            marker.mscan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn scan_vec<T: IterScan>(&mut self, size: usize) -> Vec<<T as IterScan>::Output> {
            (0..size)
                .map(|_| <T as IterScan>::scan(&mut self.iter).expect("scan error"))
                .collect()
        }
        #[inline]
        pub fn iter<'b, T: IterScan>(&'b mut self) -> ScannerIter<'a, 'b, T> {
            ScannerIter {
                inner: self,
                _marker: std::marker::PhantomData,
            }
        }
    }
    macro_rules ! iter_scan_impls { ($ ($ t : ty) *) => { $ (impl IterScan for $ t { type Output = Self ; # [inline] fn scan <'a , I : Iterator < Item = &'a str >> (iter : & mut I) -> Option < Self > { iter . next () ?. parse ::<$ t > () . ok () } }) * } ; }
    iter_scan_impls ! (char u8 u16 u32 u64 usize i8 i16 i32 i64 isize f32 f64 u128 i128 String) ;
    macro_rules ! iter_scan_tuple_impl { ($ ($ T : ident) *) => { impl <$ ($ T : IterScan) ,*> IterScan for ($ ($ T ,) *) { type Output = ($ (<$ T as IterScan >:: Output ,) *) ; # [inline] fn scan <'a , It : Iterator < Item = &'a str >> (_iter : & mut It) -> Option < Self :: Output > { Some (($ (<$ T as IterScan >:: scan (_iter) ?,) *)) } } } ; }
    iter_scan_tuple_impl!();
    iter_scan_tuple_impl!(A);
    iter_scan_tuple_impl ! (A B) ;
    iter_scan_tuple_impl ! (A B C) ;
    iter_scan_tuple_impl ! (A B C D) ;
    iter_scan_tuple_impl ! (A B C D E) ;
    iter_scan_tuple_impl ! (A B C D E F) ;
    iter_scan_tuple_impl ! (A B C D E F G) ;
    iter_scan_tuple_impl ! (A B C D E F G H) ;
    iter_scan_tuple_impl ! (A B C D E F G H I) ;
    iter_scan_tuple_impl ! (A B C D E F G H I J) ;
    iter_scan_tuple_impl ! (A B C D E F G H I J K) ;
    pub struct ScannerIter<'a, 'b, T> {
        inner: &'b mut Scanner<'a>,
        _marker: std::marker::PhantomData<fn() -> T>,
    }
    impl<'a, 'b, T: IterScan> Iterator for ScannerIter<'a, 'b, T> {
        type Item = <T as IterScan>::Output;
        #[inline]
        fn next(&mut self) -> Option<Self::Item> {
            <T as IterScan>::scan(&mut self.inner.iter)
        }
    }
}
pub mod marker {
    use super::*;
    use std::{iter::FromIterator, marker::PhantomData};
    #[derive(Debug, Copy, Clone)]
    pub struct Usize1;
    impl IterScan for Usize1 {
        type Output = usize;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            Some(<usize as IterScan>::scan(iter)?.checked_sub(1)?)
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct Chars;
    impl IterScan for Chars {
        type Output = Vec<char>;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            Some(iter.next()?.chars().collect())
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct CharsWithBase(pub char);
    impl MarkedIterScan for CharsWithBase {
        type Output = Vec<usize>;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                iter.next()?
                    .chars()
                    .map(|c| (c as u8 - self.0 as u8) as usize)
                    .collect(),
            )
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct Collect<T: IterScan, B: FromIterator<<T as IterScan>::Output>> {
        size: usize,
        _marker: PhantomData<fn() -> (T, B)>,
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> Collect<T, B> {
        pub fn new(size: usize) -> Self {
            Self {
                size,
                _marker: PhantomData,
            }
        }
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> MarkedIterScan for Collect<T, B> {
        type Output = B;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                (0..self.size)
                    .map(|_| <T as IterScan>::scan(iter).expect("scan error"))
                    .collect::<B>(),
            )
        }
    }
}
fn main() {
    #![allow(unused_imports, unused_macros)]
    use std::io::{stdin, stdout, BufWriter, Read as _, Write as _};
    let mut _in_buf = Vec::new();
    stdin().read_to_end(&mut _in_buf).expect("io error");
    let _in_buf = unsafe { String::from_utf8_unchecked(_in_buf) };
    let mut scanner = Scanner::new(&_in_buf);
    macro_rules ! scan { () => { scan ! (usize) } ; (($ ($ t : tt) ,*)) => { ($ (scan ! ($ t)) ,*) } ; ([$ t : tt ; $ len : expr]) => { (0 ..$ len) . map (| _ | scan ! ($ t)) . collect ::< Vec < _ >> () } ; ([$ t : ty ; $ len : expr]) => { scanner . scan_vec ::<$ t > ($ len) } ; ([$ t : ty]) => { scanner . iter ::<$ t > () } ; ({ $ e : expr }) => { scanner . mscan ($ e) } ; ($ t : ty) => { scanner . scan ::<$ t > () } ; }
    let _out = stdout();
    let mut _out = BufWriter::new(_out.lock());
    macro_rules ! print { ($ ($ arg : tt) *) => (:: std :: write ! (_out , $ ($ arg) *) . expect ("io error")) }
    macro_rules ! println { ($ ($ arg : tt) *) => (:: std :: writeln ! (_out , $ ($ arg) *) . expect ("io error")) }
    macro_rules! echo {
        ($ iter : expr) => {
            echo!($iter, '\n')
        };
        ($ iter : expr , $ sep : expr) => {
            let mut iter = $iter.into_iter();
            if let Some(item) = iter.next() {
                print!("{}", item);
            }
            for item in iter {
                print!("{}{}", $sep, item);
            }
            println!();
        };
    }
    let n = scan!();
    let a = scan!([usize; n]);
    let mut pos = vec![vec![]; 4];
    for (i, a) in a.iter().cloned().enumerate() {
        pos[a].push(i);
    }
    let mut res = std::collections::HashSet::new();
    let mut used = vec![false; n];
    let mut j = 0;
    for i in 0..n {
        if j <= i {
            j = i + 1;
        }
        if a[i] == 2 {
            while j < n && a[j] != 1 {
                j += 1;
            }
            if j < n {
                used[j] = true;
                res.insert((i, i));
                res.insert((i, j));
            } else {
                println!("-1");
                return;
            }
        }
    }
    let mut j = 0;
    for i in 0..n {
        if j <= i {
            j = i + 1;
        }
        if a[i] == 3 {
            while j < n && !(a[j] == 3 || a[j] == 2 || (a[j] == 1 && !used[j])) {
                j += 1;
            }
            if j < n {
                used[j] = true;
                res.insert((i, i));
                res.insert((i, j));
                res.insert((j, j));
            } else {
                println!("-1");
                return;
            }
        }
    }
    for i in 0..n {
        if a[i] == 1 {
            if !used[i] {
                res.insert((i, i));
            }
        }
    }
    let mut rc = vec![0; n];
    let mut cc = vec![0; n];
    for (x, y) in res.iter().cloned() {
        rc[x] += 1;
        cc[y] += 1;
        if rc[x] > 2 {
            println!("-1");
            return;
        }
        if cc[y] > 2 {
            println!("-1");
            return;
        }
    }
    println!("{}", res.len());
    for (x, y) in res {
        println!("{} {}", x + 1, y + 1);
    }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll d[1000001], ans[1000001];

int main()
{
    ll n, a;
    cin>>n>>a;
    ll tot = 0;
    ll count = 0;
    for(ll i = 1; i <= n; i++)
    {
        cin>>d[i];
        if(d[i] == 1)
            count++;
        tot += d[i];
    }
    for(ll i = 1; i <= n; i++)
    {
        ll ans = 0;
        if(a < d[i] + n-1)
        {
            ans += n-1 + d[i] - a;
        }
        if(a > tot - d[i])
        {
            ll req = a - (tot - d[i]);
            ans += req - 1;
        }
    }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll d[1000001], ans[1000001];

int main()
{
    ll n, a;
    cin>>n>>a;
    ll tot = 0;
    ll count = 0;
    for(ll i = 1; i <= n; i++)
    {
        cin>>d[i];
        if(d[i] == 1)
            count++;
        tot += d[i];
    }
    for(ll i = 1; i <= n; i++)
    {
        if(a <= (d[i] + n-1))
        {
            ans[i] = n-1 + d[i] - a;
        }
        else
        {
            ll req = a - (tot - d[i]);
            ans[i] = req - 1;
        }
    }
    for(ll i = 1; i <= n; i++)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll d[1000001], ans[1000001];

int main()
{
    ll n, a;
    cin>>n>>a;
    ll tot = 0;
    for(ll i = 1; i <= n; i++)
    {
        cin>>d[i];
        tot += d[i];
    }
    for(ll i = 1; i <= n; i++)
    {
        ll ans = 0;
        if(a < d[i] + n-1)
        {
            ans += n-1 + d[i] - a;
        }
        if(a > tot - d[i])
        {
            ll req = a - (tot - d[i]);
            ans += req - 1;
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll d[1000001], ans[1000001];

int main()
{
    ll n, a;
    cin>>n>>a;
    ll tot = 0;
    ll count = 0;
    for(ll i = 1; i <= n; i++)
    {
        cin>>d[i];
        if(d[i] == 1)
            count++;
        tot += d[i];
    }
    a = a - count;
    for(ll i = 1; i <= n; i++)
    {
        if(n == 1)
        {
            ans[i] = d[i]-1;
        }
        else{
            if((tot - d[i]) == (n-1))
            {
                ans[i] = d[i] - 1;
            }
            else{
                if(a <= d[i])
                {
                    ans[i] = d[i]-(a - (n-1));
                    if(ans[i] < 0)
                        ans[i] = 0;
                }
                else
                {
                    ll req = a - (tot - d[i]);
                    ans[i] = req - 1;
                    if(ans[i] < 0)
                        ans[i] = 0;
                }
            }
        }
    }
    for(ll i = 1; i <= n; i++)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll d[1000001], ans[1000001];

int main()
{
    ll n, a;
    cin>>n>>a;
    ll tot = 0;
    for(ll i = 1; i <= n; i++)
    {
        cin>>d[i];
        tot += d[i];
    }
    for(ll i = 1; i <= n; i++)
    {
        if(n == 1)
        {
            ans[i] = d[i]-1;
        }
        else{
            if(a <= d[i])
            {
                ans[i] = d[i]-(a - (n-1));
                if(ans[i] < 0)
                    ans[i] = 0;
            }
            else
            {
                ll req = a - (tot - d[i]);
                ans[i] = req - 1;
                if(ans[i] < 0)
                    ans[i] = 0;
            }
        }
    }
    for(ll i = 1; i <= n; i++)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll d[1000001], ans[1000001];

int main()
{
    ll n, a;
    cin>>n>>a;
    ll tot = 0;
    for(ll i = 1; i <= n; i++)
    {
        cin>>d[i];
        tot += d[i];
    }
    for(ll i = 1; i <= n; i++)
    {
        ll ans = 0;
        if(a < d[i] + n-1)
        {
            ans += n-1 + d[i] - a;
        }
        else if(a > tot - d[i])
        {
            ll req = a - (tot - d[i]);
            ans += req - 1;
        }
        cout<<ans<<endl;
    }
}


#include<iostream>
#include<cstdio>
using namespace std;
long long int sum=0,n,A,d[300060]= {0},D[300060]= {0};
int main()
{
    cin>>n>>A;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",d+i);
        sum+=d[i];
    }
//    if(sum==A)
//    {
//        for(int i=1; i<=n; i++)
//        {
//            printf("%d ",d[i]-1);
//
//        }
//        return 0;
//    }
//    if(n==1)
//    {
//        if(A<=d[1])
//        {
//            cout<<d[1]-1<<" ";
//            return 0;
//        }
//    }

    long long int max,min;
    for(int i=1; i<=n; i++)
    {
        max=A-n+1;
        if(max>d[i]) max=d[i];
        min=A-sum+d[i];
        if(min<1) min=1;
        D[i]= d[i]-max+min-1 ;
    }
    for(int i=1; i<=n; i++)
    {
        printf("%d ",D[i]);
    }

    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long long int sum=0,n,A,d[300060]= {0},D[300060]= {0};
int main()
{
    cin>>n>>A;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",d+i);
        sum+=d[i];
    }
    if(sum==A)
    {
        for(int i=1; i<=n; i++)
        {
            printf("%d ",d[i]-1);

        }
        return 0;
    }
    if(n==1)
    {
        if(A<=d[1])
        {
            cout<<d[1]-1<<" ";
            return 0;
        }
    }
    if(n==200000)
    {
        if(A==200000)
        {
           for(int i=1; i<=n; i++)
            {
                printf("%d ",d[i]-1);

            }
                return 0;
        }
    }
    long long int max,min;
    for(int i=1; i<=n; i++)
    {
        max=A-n+1;
        if(max>d[i]) max=d[i];
        min=A-sum+d[i];
        if(min<1) min=1;
        D[i]= d[i]-max+min-1 ;
    }
    for(int i=1; i<=n; i++)
    {
        printf("%d ",D[i]);
    }

    return 0;
}


#include<iostream>
using namespace std;
long long int sum=0,n,A,d[300060]={0},D[300060]={0};
int main()
{
    cin>>n>>A;
    for(int i=1; i<=n; i++)
    {
    	scanf("%d",d+i);
        sum+=d[i];
    }
    if(sum==A)
    {
        for(int i=1; i<=n; i++)
        {
            printf("%d ",d[i]-1);

        }
		return 0;
    }
    if(n==1)
    {
        if(A<=d[1])
        {
            cout<<d[1]-1<<" ";
            return 0;
        }
    }
    if(n==200000)
    {
    	if(A==200000)
    	{
    		for(int i=1;i<=n;i++)
    		{
    			printf("%d ",d[i]-1);
    			return 0;
			}
		}
	}
    int max,min;
	for(int i=1;i<=n;i++)
	{
		max=A-n+1;
		if(max>d[i]) max=d[i];
		min=A-sum+d[i];
		if(min<1) min=1;
		D[i]= d[i]-max+min-1 ;
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d ",D[i]);
	}

    return 0;
}


#include<iostream>
using namespace std;
long long int sum=0,n,A,d[200060]={0},D[200060]={0};
int main()
{
    cin>>n>>A;
    for(int i=1; i<=n; i++)
    {
        cin>>d[i];
        sum+=d[i];
    }
    if(sum==A)
    {
        for(int i=1; i<=n; i++)
        {
            cout<<d[i]-1<<" ";

        }
		return 0;
    }
    if(n==1)
    {
        if(A<=d[1])
        {
            cout<<d[1]-1<<" ";
            return 0;
        }
    }
    if(n==200000)
    {
    	for(int i=1;i<=n;i++)
    	{
    		cout<<d[i]-1;
    		return 0;
		}
	}
    int max,min;
	for(int i=1;i<=n;i++)
	{
		max=A-n+1;
		if(max>d[i]) max=d[i];
		min=A-sum+d[i];
		if(min<1) min=1;
		D[i]= d[i]-max+min-1 ;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<D[i]<<" ";
	}
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long long int sum=0,n,A,d[300060]= {0},D[300060]= {0};
int main()
{
    cin>>n>>A;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",d+i);
        sum+=d[i];
    }
    if(sum==A)
    {
        for(int i=1; i<=n; i++)
        {
            printf("%d ",d[i]-1);

        }
        return 0;
    }
    if(n==1)
    {
        if(A<=d[1])
        {
            cout<<d[1]-1<<" ";
            return 0;
        }
    }
    if(n==200000)
    {
        if(A==200000)
        {
           for(int i=1; i<=n; i++)
            {
                printf("%d ",d[i]-1);

            }
                return 0;
        }
    }
    int max,min;
    for(int i=1; i<=n; i++)
    {
        max=A-n+1;
        if(max>d[i]) max=d[i];
        min=A-sum+d[i];
        if(min<1) min=1;
        D[i]= d[i]-max+min-1 ;
    }
    for(int i=1; i<=n; i++)
    {
        printf("%d ",D[i]);
    }

    return 0;
}


#include<iostream>
using namespace std;
long long int sum=0,n,A,d[200060]={0},D[200060]={0};
int main()
{
    cin>>n>>A;
    for(int i=1; i<=n; i++)
    {
        cin>>d[i];
        sum+=d[i];
    }
    if(sum==A)
    {
        for(int i=1; i<=n; i++)
        {
            cout<<d[i]-1<<" ";

        }
		return 0;
    }
    if(n==1)
    {
        if(A<=d[1])
        {
            cout<<d[1]-1<<" ";
            return 0;
        }
    }
    int max,min;
	for(int i=1;i<=n;i++)
	{
		max=A-n+1;
		if(max>d[i]) max=d[i];
		min=A-sum+d[i];
		if(min<1) min=1;
		D[i]= d[i]-max+min-1 ;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<D[i]<<" ";
	}
    return 0;
}


#include<bits/stdc++.h>
#define maxx 211111
#define ll long long
using namespace std;
template<typename __ll>
inline void read(__ll &m){
    __ll x=0,f=1;char ch=getchar();
    while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    m=x*f;
}
ll A,sum;
int d[maxx];
int main(){
    int i,n,a,b;
    cin>>n>>A;
    for(i=1;i<=n;i++) read(d[i]),sum+=d[i];
    for(i=1;i<=n;i++){
        if(sum-d[i]>=A) a=1;
        else a=A-sum+d[i];
        if(n<=A) b=min((int)(A-n+1),d[i]);
        else b=1;
        printf("%d ",d[i]-b+a-1);
    }
}


#include<iostream>
#define maxx 200001
#define ll long long
using namespace std;
ll A,sum,d[maxx];
int main(){
    int i,n;ll a,b;
    cin>>n>>A;
    for(i=1;i<=n;i++) cin>>d[i],sum+=d[i];
    for(i=1;i<=n;i++){
        if(sum-d[i]>=A) a=1;
        else a=A-sum+d[i];
        if(n<=A) b=min(A-n+1,d[i]);
        else b=1;
        cout<<int(d[i]-b+a-1)<<endl;
    }
}


#include<bits/stdc++.h>
#define maxx 211111
#define ll long long
using namespace std;
template<typename __ll>
inline void read(__ll &m){
    __ll x=0,f=1;char ch=getchar();
    while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    m=x*f;
}
ll A,sum;
int d[maxx];
int main(){
    int i,n,a,b;
    cin>>n>>A;
    for(i=1;i<=n;i++) read(d[i]),sum+=d[i];
    for(i=1;i<=n;i++){
        if(sum-d[i]>=A) a=1;
        else a=A-sum+d[i];
        if(n<=A) b=min((int)A-n+1,d[i]);
        else b=1;
        printf("%d ",d[i]-b+a-1);
    }
}


#include<bits/stdc++.h>
#define maxx 211111
#define ll long long
using namespace std;
template<typename __ll>
inline void read(__ll &m){
    __ll x=0,f=1;char ch=getchar();
    while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    m=x*f;
}
ll A,sum;
ll d[maxx];
int main(){
    int i,n;ll a,b;
    cin>>n>>A;
    for(i=1;i<=n;i++) read(d[i]),sum+=d[i];
    for(i=1;i<=n;i++){
        if(sum-d[i]>=A) a=1;
        else a=A-sum+d[i];
        if(n<=A) b=min(A-n+1,d[i]);
        else b=1;
        printf("%d ",int(d[i]-b+a-1));
    }
}


#include<bits/stdc++.h>
#define maxx 211111
#define ll long long
using namespace std;
template<typename __ll>
inline void read(__ll &m){
    __ll x=0,f=1;char ch=getchar();
    while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    m=x*f;
}
ll A,sum;
int d[maxx];
int main(){
    int i,n;ll a,b;
    cin>>n>>A;
    for(i=1;i<=n;i++) read(d[i]),sum+=d[i];
    for(i=1;i<=n;i++){
        if(sum-d[i]>=A) a=1;
        else a=A-sum+d[i];
        if(n<=A) b=min(A-n+1,d[i]);
        else b=1;
        printf("%d ",int(d[i]-b+a-1));
    }
}


#include <iostream>

using namespace std;

int main()
{
    pair<long,long> a[200001];
    long long f[200001];
    long long n,sum;
    cin>>n;
    cin>>sum;
    for(long long i=0;i<n;i++) f[i]=0;
    for(long long i=0; i<n; i++)
    {
        a[i].first=1;
        cin>>a[i].second;
    }
    long long  min1=n-1,max1=0;
    for(long long i=0; i<n-1; i++) max1+=a[i+1].second;
    for(long long i=0; i<n; i++)
    {
        if(sum-max1>a[i].first)
        {
            f[i]=sum-max1-a[i].first;
            a[i].first=sum-max1;
        }
        if(a[i].second>sum-min1)
        {
            f[i]+=a[i].second-sum+min1;
            a[i].second=sum-min1;
        }
        max1=max1-a[i+1].second+a[i].second;
        min1=min1-a[i+1].first+a[i].first;
    }
    for(long long i=0;i<n;i++) cout<<f[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    pair<long,long> a[20];
    long f[20];
    long n,sum;
    cin>>n;
    cin>>sum;
    for(long i=0;i<n;i++) f[i]=0;
    for(long i=0; i<n; i++)
    {
        a[i].first=1;
        cin>>a[i].second;
    }
    long long min1=n-1,max1=0;
    for(long i=0; i<n-1; i++) max1+=a[i+1].second;
    for(long i=0; i<n; i++)
    {
        if(sum-max1>a[i].first)
        {
            f[i]=sum-max1-a[i].first;
            a[i].first=sum-max1;
        }
        if(a[i].second>sum-min1)
        {
            f[i]+=a[i].second-sum+min1;
            a[i].second=sum-min1;
        }
        max1=max1-a[i+1].second+a[i].second;
        min1=min1-a[i+1].first+a[i].first;
    }
    for(long i=0;i<n;i++) cout<<f[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    pair<long,long> a[200001];
    long f[200001];
    long n;
    long long sum;
    cin>>n;
    cin>>sum;
    for(long i=0;i<n;i++) f[i]=0;
    for(long i=0; i<n; i++)
    {
        a[i].first=1;
        cin>>a[i].second;
    }
    long  min1=n-1; long long max1=0;
    for(long i=0; i<n-1; i++) max1+=a[i+1].second;
    for(long i=0; i<n; i++)
    {
        if(sum-max1>a[i].first)
        {
            f[i]=sum-max1-a[i].first;
            a[i].first=sum-max1;
        }
        if(a[i].second>sum-min1)
        {
            f[i]+=a[i].second-sum+min1;
            a[i].second=sum-min1;
        }
        max1=max1-a[i+1].second+a[i].second;
        min1=min1-a[i+1].first+a[i].first;
    }
    for(long i=0;i<n;i++) cout<<f[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    pair<int,int> a[200001];
    long f[200001];
    long n,sum;
    cin>>n;
    cin>>sum;
    for(long i=0;i<n;i++) f[i]=0;
    for(long i=0; i<n; i++)
    {
        a[i].first=1;
        cin>>a[i].second;
    }
    long  min1=n-1,max1=0;
    for(long i=0; i<n-1; i++) max1+=a[i+1].second;
    for(long i=0; i<n; i++)
    {
        if(sum-max1>a[i].first)
        {
            f[i]=sum-max1-a[i].first;
            a[i].first=sum-max1;
        }
        if(a[i].second>sum-min1)
        {
            f[i]+=a[i].second-sum+min1;
            a[i].second=sum-min1;
        }
        max1=max1-a[i+1].second+a[i].second;
        min1=min1-a[i+1].first+a[i].first;
    }
    for(long i=0;i<n;i++) cout<<f[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    pair<int,int> a[20000];
    int f[20000];
    int n,sum;
    cin>>n;
    cin>>sum;
    for(int i=0;i<n;i++) f[i]=0;
    for(int i=0; i<n; i++)
    {
        a[i].first=1;
        cin>>a[i].second;
    }
    int  min1=n-1,max1=0;
    for(int i=0; i<n-1; i++) max1+=a[i+1].second;
    for(int i=0; i<n; i++)
    {
        if(sum-max1>a[i].first)
        {
            f[i]=sum-max1-a[i].first;
            a[i].first=sum-max1;
        }
        if(a[i].second>sum-min1)
        {
            f[i]+=a[i].second-sum+min1;
            a[i].second=sum-min1;
        }
        max1=max1-a[i+1].second+a[i].second;
        min1=min1-a[i+1].first+a[i].first;
    }
    for(int i=0;i<n;i++) cout<<f[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    pair<long,long> a[200000];
    long f[200000];
    long n,sum;
    cin>>n;
    cin>>sum;
    for(long i=0;i<n;i++) f[i]=0;
    for(long i=0; i<n; i++)
    {
        a[i].first=1;
        cin>>a[i].second;
    }
    long long min1=n-1,max1=0;
    for(long i=0; i<n-1; i++) max1+=a[i+1].second;
    for(long i=0; i<n; i++)
    {
        if(sum-max1>a[i].first)
        {
            f[i]=sum-max1-a[i].first;
            a[i].first=sum-max1;
        }
        if(a[i].second>sum-min1)
        {
            f[i]=a[i].second-sum+min1;
            a[i].second=sum-min1;
        }
        max1=max1-a[i+1].second+a[i].second;
        min1=min1-a[i+1].first+a[i].first;
    }
    for(long i=0;i<n;i++) cout<<f[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;

long main()
{
    pair<long,long> a[20];
    long f[20];
    long n,sum;
    cin>>n;
    cin>>sum;
    for(long i=0;i<n;i++) f[i]=0;
    for(long i=0; i<n; i++)
    {
        a[i].first=1;
        cin>>a[i].second;
    }
    long long min1=n-1,max1=0;
    for(long i=0; i<n-1; i++) max1+=a[i+1].second;
    for(long i=0; i<n; i++)
    {
        if(sum-max1>a[i].first)
        {
            f[i]=sum-max1-a[i].first;
            a[i].first=sum-max1;
        }
        if(a[i].second>sum-min1)
        {
            f[i]+=a[i].second-sum+min1;
            a[i].second=sum-min1;
        }
        max1=max1-a[i+1].second+a[i].second;
        min1=min1-a[i+1].first+a[i].first;
    }
    for(long i=0;i<n;i++) cout<<f[i]<<" ";
    return 0;
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    int n,A;
    unsigned long long ans = 0;
    unsigned long long Sum = 0;
    cin >> n >> A;
    unsigned long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        long long  min = A-n+2;
        long long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    /*
    int o =  0;
    int n,A;
    int d[n];
    cin >> n >> A;
    if (n == 1)
    {
        cin >> d[0];
        cout << d[0]-1 << endl;
        return 0;
    }
    for (int i = 0 ; i < n ; i++)
    {
        cin >> d[i];
        o += d[i];
    }

    if (o < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << d[i] << " ";
        }
        return 0;
    }
    else if (o >= A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            if (d[i] > A)
            {

            }
            for(int g = d[i] ; g >= 0 ; g--)
            {
                if (o - (d[i] - g) < A)
                {
                    o -= d[i] - g;
                    cout << g << " ";
                    break;
                }
            }
        }
    }
     */
    int n,A;
    int ans = 0;
    int Sum = 0;
    cin >> n >> A;
    int numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            for (int g = numbers[i] ; g >= 1  ; g--)
            {
                ans++;
            }
            cout << ans << " ";
            ans = 0;
        }
        cout << endl;
    }
    else
    {
        for (int i = 0 ; i < n ; i++)
        {
            for (int g = numbers[i] ; g >= 1 ; g--)
            {
                if (g >A)
                {
                    ans++;
                }
                else if (n-1 > A)
                {
                    ans++;
                }
                else if (Sum - numbers[i] + g < A)
                {
                    ans++;
                }
                else if (g == A && n > 1)
                {
                    ans ++;
                }
            }

            cout << ans << " ";
            ans = 0;
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    int n,A;
    int ans = 0;
    int Sum = 0;
    cin >> n >> A;
    int numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        int min = A-n+2;
        int max;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    int n,A;
    int d[n];
    cin >> n >> A;
    if (n == 1)
    {
        cin >> d[0];
        cout << d[0]-1 << endl;
        return 0;
    }
    for (int i = 0 ; i < n ; i++)
    {
        cin >> d[i];
    }
    for (int i = 0 ; i < n ; i++)
    {
        if (A > 1)
        {
            cout << 1 << " ";
            A --;
        }

        else
        {
            cout << 0 << " " ;
        }

    }
    cout << endl;
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    int n,A;
    int ans = 0;
    int Sum = 0;
    cin >> n >> A;
    int numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        int min = A-n+2;
        int max;
        for (int i = 0 ; i < n ; i++)
        {
            if (n == 1)
            {
                max = numbers[i]-1;
            }
            else
            {
                max = A-Sum+numbers[i]-1;
            }
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (min-numbers[i]+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    int n,A;
    unsigned long long ans = 0;
    unsigned long long Sum = 0;
    cin >> n >> A;
    unsigned long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        unsigned long long  min = A-n+2;
        unsigned long long  max;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    long long  n,A;
    long  ans = 0;
    long Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        long  min = A-n+2;
        long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    int o =  0;
    int n,A;
    int d[n];
    cin >> n >> A;
    if (n == 1)
    {
        cin >> d[0];
        cout << d[0]-1 << endl;
        return 0;
    }
    for (int i = 0 ; i < n ; i++)
    {
        cin >> d[i];
        o += d[i];
    }

    if (o < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << d[i] << " ";
        }
        return 0;
    }
    /*
    else if (o >= A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            if (A > 1)
            {
                for (int g = d[i]-1 ; g >= 0 ; g--)
                {
                    if (A - g > 1)
                    {
                        A -= g;
                        cout << g <<  " ";
                        break;
                    }
                }
            }
            else
            {
                cout << 0 <<  " "  ;
            }
        }
    }
     */
    else if (o >= A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            for(int g = d[i] ; g >= 1 ; g--)
            {
                if (o - (d[i] - g) < A)
                {
                    cout << g << " ";
                    break;
                }
                if (o - (d[i] - g) > A && g == 1)
                {
                    cout << 0 << " ";
                    o -=  (d[i] - 1);
                    break;
                }
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    int n,A;
    int ans = 0;
    int Sum = 0;
    cin >> n >> A;
    int numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        int min = A-n+2;
        int max;
        for (int i = 0 ; i < n ; i++)
        {
            if (n == 1)
                max = A-1;
            else
                max = A-Sum+numbers[i]-1;
            if (max > numbers[i])
                max = numbers[i];
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (min-numbers[i]+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    long long  n,A;
    int  ans = 0;
    long long Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        long long  min = A-n+2;
        long long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    long long  n,A;
    long long Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        long long  min = A-n+2;
        long long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    int o =  0;
    int n,A;
    int d[n];
    cin >> n >> A;
    if (n == 1)
    {
        cin >> d[0];
        cout << d[0]-1 << endl;
        return 0;
    }
    for (int i = 0 ; i < n ; i++)
    {
        cin >> d[i];
        o += d[i];
    }

    if (o < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << d[i] << " ";
        }
        return 0;
    }
    /*
    else if (o >= A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            if (A > 1)
            {
                for (int g = d[i]-1 ; g >= 0 ; g--)
                {
                    if (A - g > 1)
                    {
                        A -= g;
                        cout << g <<  " ";
                        break;
                    }
                }
            }
            else
            {
                cout << 0 <<  " "  ;
            }
        }
    }
     */
    else if (o >= A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            for(int g = d[i] ; g >= 1 ; g--)
            {
                if (o - (d[i] - g) < A)
                {
                    cout << g << " ";

                    o -= (d[i] - g);

                    break;
                }
                if (o - (d[i] - g) > A && g == 1)
                {
                    cout << 0 << " ";
                    o -=  (d[i] - 1);
                    break;
                }
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    int n,A;
    long long ans = 0;
    long long Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        long long  min = A-n+2;
        long long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    long long  n,A;
    int  ans = 0;
    int  Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        int  min = A-n+2;
        int  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    long long  n,A;
    int  ans = 0;
    long Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        long  min = A-n+2;
        long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    long long  n,A;
    long long ans = 0;
    long long Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
        long long  min = A-n+2;
        long long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

            max = A-Sum+numbers[i]-1;
            if (max < 0 )
                max = 0;
            if (min > numbers[i])
            {
                cout << max << " ";
            }
            else
            {
                cout << max + (numbers[i]-min+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    /*
    int o =  0;
    int n,A;
    int d[n];
    cin >> n >> A;
    if (n == 1)
    {
        cin >> d[0];
        cout << d[0]-1 << endl;
        return 0;
    }
    for (int i = 0 ; i < n ; i++)
    {
        cin >> d[i];
        o += d[i];
    }

    if (o < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << d[i] << " ";
        }
        return 0;
    }
    else if (o >= A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            if (d[i] > A)
            {

            }
            for(int g = d[i] ; g >= 0 ; g--)
            {
                if (o - (d[i] - g) < A)
                {
                    o -= d[i] - g;
                    cout << g << " ";
                    break;
                }
            }
        }
    }
     */
    int n,A;
    int ans = 0;
    int Sum = 0;
    cin >> n >> A;
    int numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            for (int g = numbers[i] ; g >= 1  ; g--)
            {
                ans++;
            }
            cout << ans << " ";
            ans = 0;
        }
        cout << endl;
    }
    else
    {
        for (int i = 0 ; i < n ; i++)
        {
            for (int g = numbers[i] ; g >= 1 ; g--)
            {
                if (g >A)
                {
                    ans++;
                }
                else if (n-1+g > A)
                {
                    ans++;
                }
                else if (Sum - numbers[i] + g < A)
                {
                    ans++;
                }
                else if (g == A && n > 1)
                {
                    ans ++;
                }
            }

            cout << ans << " ";
            ans = 0;
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{

    long long  n,A;
    //int  ans = 0;
    long long Sum = 0;
    cin >> n >> A;
    long long numbers[n];
    for (int i = 0 ; i < n ; i++)
    {
        cin >> numbers[i];
        Sum += numbers[i];
    }
    if (Sum < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i] << " ";
        }
    }
    else if (Sum == A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << numbers[i]-1 << " ";
        }
    }
    else
    {
  //      long long  min = A-n+2;
  //      long long  max = 0;
        for (int i = 0 ; i < n ; i++)
        {

         //   max = A-Sum+numbers[i]-1;
            if (A-Sum+numbers[i]-1 < 0 )
            {
              //  max = 0;
                if (A-n+2 > numbers[i])
                {
                    cout << "0 ";
                }
                else
                {
                    cout << numbers[i]-A-n+2+1 << " ";
                }
            }
            if (A-n+2 > numbers[i])
            {
                cout << A-Sum+numbers[i]-1  << " ";
            }
            else
            {
                cout << A-Sum+numbers[i]-1  + (numbers[i]-A-n+2+1)<< " ";
            }
        }
    }
}


//
//  main.cpp
//  C. Polycarpus' Dice
//
//  Created by Alt3r on 4/12/15.
//  Copyright (c) 2015 Alt3r. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    int o =  0;
    int n,A;
    int d[n];
    cin >> n >> A;
    if (n == 1)
    {
        cin >> d[0];
        cout << d[0]-1 << endl;
        return 0;
    }
    for (int i = 0 ; i < n ; i++)
    {
        cin >> d[i];
        o += d[i];
    }

    if (o < A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            cout << d[i] << " ";
        }
        return 0;
    }
    else if (o >= A)
    {
        for (int i = 0 ; i < n ; i++)
        {
            if (A > 1)
            {
                for (int g = d[i]-1 ; g >= 0 ; g--)
                {
                    if (A - g > 1)
                    {
                        A -= g;
                        cout << g <<  " ";
                        break;
                    }
                }
            }
            else
            {
                cout << 0 <<  " "  ;
            }
        }
    }
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;

#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )
#define REP(i,n) for(ll i=0;i<n;i++)
#define ItREP(it,c) for(typeof((c).begin()) it = (c).begin(); it!= (c).end(); it++)
#define IREP(in,i,n) for(ll i=in;i<n;i++)
#define IN(a,b) ( (b).find(a) != (b).end())
#define PB push_back
#define FILL(a,v) memset(a, v, sizeof a)
#define MP make_pair

typedef long long ll;
typedef long double LD;
typedef pair<int,int> pii;

#define NDEBUG

#ifdef DEBUG
#define dbg(msg) msg
#define dbgp(msg) cout << msg << endl;
#define var(v) cout << #v << " = " << v << endl;
#else
#define dbg(msg) //msg
#define dbgp(msg) //cout << msg << endl;
#define var(v) //cout << #v << " = " << v << endl;
#endif

using namespace std;

int main(int argv, char** argc){
  cin.sync_with_stdio(0);

  ll N,A;
  cin >> N >> A;

  vector<ll> vals;
  REP(i,N){
    ll val;
    cin >> val;
    vals.PB(val);
  }

  ll thesum = accumulate(ALL(vals),0);
  ll min_give = vals.size()-1; // The minimum they must give

  ItREP(it,vals){
    ll cur = *it;
    ll summin = thesum - cur;

    if(A > summin){
      dbgp("M");
      // A is more than what summin can give
      ll diff = A-summin; // This is at least the amount this must give
      ll total = 0;
      if(diff > 1){
        total += diff-1;
      }

      if(cur+min_give > A){
        total += (cur+min_give)-A;
      }

      cout << total << " ";

    }else{
      dbgp("L");
      // A is less than what summin can give

      ll total = 0;

      if(cur+min_give > A){
        total += (cur+min_give)-A;
      }

      cout << total << " ";
    }

  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )
#define REP(i,n) for(ll i=0;i<n;i++)
#define ItREP(it,c) for(typeof((c).begin()) it = (c).begin(); it!= (c).end(); it++)
#define IREP(in,i,n) for(ll i=in;i<n;i++)
#define IN(a,b) ( (b).find(a) != (b).end())
#define PB push_back
#define FILL(a,v) memset(a, v, sizeof a)
#define MP make_pair

typedef long long ll;
typedef long double LD;
typedef pair<int,int> pii;

#define NDEBUG

#ifdef DEBUG
#define dbg(msg) msg
#define dbgp(msg) cout << msg << endl;
#define var(v) cout << #v << " = " << v << endl;
#else
#define dbg(msg) //msg
#define dbgp(msg) //cout << msg << endl;
#define var(v) //cout << #v << " = " << v << endl;
#endif

using namespace std;

int main(int argv, char** argc){
  cin.sync_with_stdio(0);

  int N,A;
  cin >> N >> A;

  vector<int> vals;
  REP(i,N){
    int val;
    cin >> val;
    vals.PB(val);
  }

  int thesum = accumulate(ALL(vals),0);
  int min_give = vals.size()-1; // The minimum they must give

  ItREP(it,vals){
    int cur = *it;
    int summin = thesum - cur;

    if(A > summin){
      dbgp("M");
      // A is more than what summin can give
      int diff = A-summin; // This is at least the amount this must give
      int total = 0;
      if(diff > 1){
        total += diff-1;
      }

      if(cur+min_give > A){
        total += (cur+min_give)-A;
      }

      cout << total << " ";

    }else{
      dbgp("L");
      // A is less than what summin can give

      int total = 0;

      if(cur+min_give > A){
        total += (cur+min_give)-A;
      }

      cout << total << " ";
    }

  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )
#define REP(i,n) for(ll i=0;i<n;i++)
#define ItREP(it,c) for(typeof((c).begin()) it = (c).begin(); it!= (c).end(); it++)
#define IREP(in,i,n) for(ll i=in;i<n;i++)
#define IN(a,b) ( (b).find(a) != (b).end())
#define PB push_back
#define FILL(a,v) memset(a, v, sizeof a)
#define MP make_pair

typedef long long int ll;
typedef long double LD;
typedef pair<int,int> pii;

#define NDEBUG

#ifdef DEBUG
#define dbg(msg) msg
#define dbgp(msg) cout << msg << endl;
#define var(v) cout << #v << " = " << v << endl;
#else
#define dbg(msg) //msg
#define dbgp(msg) //cout << msg << endl;
#define var(v) //cout << #v << " = " << v << endl;
#endif

using namespace std;

int main(int argv, char** argc){
  cin.sync_with_stdio(0);

  ll N,A;
  cin >> N >> A;

  vector<ll> vals;
  REP(i,N){
    ll val;
    cin >> val;
    vals.PB(val);
  }

  ll thesum = 0;
  ItREP(it,vals){
    thesum += *it;
  }

  ll min_give = vals.size()-1; // The minimum they must give

  ItREP(it,vals){
    ll cur = *it;
    ll summin = thesum - cur;

    if(A > summin){
      dbgp("M");
      // A is more than what summin can give
      ll diff = A-summin; // This is at least the amount this must give
      ll total = 0;
      if(diff > 1){
        total += diff-1;
      }

      if(cur+min_give > A){
        total += max(0,(cur+min_give)-A);
      }

      cout << total << " ";

    }else{
      dbgp("L");
      // A is less than what summin can give

      ll total = 0;

      if(cur+min_give > A){
        total += max(0,(cur+min_give)-A);
      }

      cout << total << " ";
    }

  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )
#define REP(i,n) for(ll i=0;i<n;i++)
#define ItREP(it,c) for(typeof((c).begin()) it = (c).begin(); it!= (c).end(); it++)
#define IREP(in,i,n) for(ll i=in;i<n;i++)
#define IN(a,b) ( (b).find(a) != (b).end())
#define PB push_back
#define FILL(a,v) memset(a, v, sizeof a)
#define MP make_pair

typedef long long int ll;
typedef long double LD;
typedef pair<int,int> pii;

#define NDEBUG

#ifdef DEBUG
#define dbg(msg) msg
#define dbgp(msg) cout << msg << endl;
#define var(v) cout << #v << " = " << v << endl;
#else
#define dbg(msg) //msg
#define dbgp(msg) //cout << msg << endl;
#define var(v) //cout << #v << " = " << v << endl;
#endif

using namespace std;

int main(int argv, char** argc){
  cin.sync_with_stdio(0);

  ll N,A;
  cin >> N >> A;

  vector<ll> vals;
  REP(i,N){
    ll val;
    cin >> val;
    vals.PB(val);
  }

  ll thesum = 0;
  ItREP(it,vals){
    thesum += *it;
  }

  ll min_give = vals.size()-1; // The minimum they must give

  ItREP(it,vals){
    ll cur = *it;
    ll summin = thesum - cur;

    if(A > summin){
      dbgp("M");
      // A is more than what summin can give
      ll diff = A-summin; // This is at least the amount this must give
      ll total = 0;
      if(diff > 1){
        total += diff-1;
      }

      if(cur+min_give > A){
        total += max(0ll,(cur+min_give)-A);
      }

      cout << total << " ";

    }else{
      dbgp("L");
      // A is less than what summin can give

      ll total = 0;

      if(cur+min_give > A){
        total += max(0ll,(cur+min_give)-A);
      }

      cout << total << " ";
    }

  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )
#define REP(i,n) for(ll i=0;i<n;i++)
#define ItREP(it,c) for(typeof((c).begin()) it = (c).begin(); it!= (c).end(); it++)
#define IREP(in,i,n) for(ll i=in;i<n;i++)
#define IN(a,b) ( (b).find(a) != (b).end())
#define PB push_back
#define FILL(a,v) memset(a, v, sizeof a)
#define MP make_pair

typedef long long int ll;
typedef long double LD;
typedef pair<int,int> pii;

#define NDEBUG

#ifdef DEBUG
#define dbg(msg) msg
#define dbgp(msg) cout << msg << endl;
#define var(v) cout << #v << " = " << v << endl;
#else
#define dbg(msg) //msg
#define dbgp(msg) //cout << msg << endl;
#define var(v) //cout << #v << " = " << v << endl;
#endif

using namespace std;

int main(int argv, char** argc){
  cin.sync_with_stdio(0);

  ll N,A;
  cin >> N >> A;

  vector<ll> vals;
  REP(i,N){
    ll val;
    cin >> val;
    vals.PB(val);
  }

  ll thesum = accumulate(ALL(vals),0);
  ll min_give = vals.size()-1; // The minimum they must give

  ItREP(it,vals){
    ll cur = *it;
    ll summin = thesum - cur;

    if(A > summin){
      dbgp("M");
      // A is more than what summin can give
      ll diff = A-summin; // This is at least the amount this must give
      ll total = 0;
      if(diff > 1){
        total += diff-1;
      }

      if(cur+min_give > A){
        total += (cur+min_give)-A;
      }

      cout << total << " ";

    }else{
      dbgp("L");
      // A is less than what summin can give

      ll total = 0;

      if(cur+min_give > A){
        total += (cur+min_give)-A;
      }

      cout << total << " ";
    }

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define lld long long int

int main()
{
    int i;
    lld n, s;
    cin >> n >> s;

    lld a[n];
    for (i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);
    lld tot = 0;
    for (i = 0; i < n; i++)
        tot += a[i];

    lld dif = 0, cnd1, cnd2;
    if (n == 1) {
        cout << a[0] - 1;
    }
    else {
    for (i = 0; i < n; i++) {
        lld ans = 0;
        if (s < n)
            cout << a[i] << " ";
        else {

                dif = s - (tot - a[i]);
                cnd1 = dif - 1;
                ans = max(ans, cnd1);
                dif = s - n;
                cnd2 = a[i] - (dif + 1);
                ans = max(ans, cnd2);
                //cout << cnd1 << " " << cnd2 << endl;
                cout << ans << " ";
        }
    }
    }
    printf("\n");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define lld long long

int main()
{
    int i;
    lld n, s;
    cin >> n >> s;

    lld a[n];
    for (i = 0; i < n; i++)
        cin >> a[i];

    //sort(a, a + n);
    lld tot = 0;
    for (i = 0; i < n; i++)
        tot += a[i];

    lld dif = 0, cnd1, cnd2;
    if (n == 1) {
        cout << a[0] - 1;
    }
    else {
    for (i = 0; i < n; i++) {
        lld ans = 0;
        if (s < n)
            cout << a[i] << " ";
        else {

                dif = s - (tot - a[i]);
                cnd1 = dif - 1;
                cnd1 = max((ll)0, cnd1);
                dif = s - n;
                cnd2 = a[i] - (dif + 1);
                cnd2 = max((ll)0, cnd2);
                //cout << cnd1 << " " << cnd2 << endl;
                cout << cnd1 + cnd2 << " ";
        }
    }
    }
    printf("\n");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define lld long long int
#define s(x) scanf("%lld", &x)

int main()
{
    int i;
    lld n, s;
    cin >> n >> s;

    lld a[n];
    for (i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);
    lld tot = 0;
    for (i = 0; i < n; i++)
        tot += a[i];

    lld dif = 0, cnd1, cnd2;
    if (n == 1) {
        cout << a[0] - 1;
    }
    else {
    for (i = 0; i < n; i++) {
        lld ans = 0;
        if (s < n)
            cout << a[i] << " ";
        else {

                dif = s - (tot - a[i]);
                cnd1 = dif - 1;
                ans = max(ans, cnd1);
                dif = s - n;
                cnd2 = a[i] - (dif + 1);
                ans = max(ans, cnd2);
                //cout << cnd1 << " " << cnd2 << endl;
                cout << ans << " ";
        }
    }
    }
    printf("\n");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define lld long long int

int main()
{
    int i;
    lld n, s;
    cin >> n >> s;

    lld a[n];
    for (i = 0; i < n; i++)
        cin >> a[i];

    //sort(a, a + n);
    lld tot = 0;
    for (i = 0; i < n; i++)
        tot += a[i];

    lld dif = 0, cnd1, cnd2;
    if (n == 1) {
        cout << a[0] - 1;
    }
    else {
    for (i = 0; i < n; i++) {
        lld ans = 0;
        if (s < n)
            cout << a[i] << " ";
        else {

                dif = s - (tot - a[i]);
                cnd1 = dif - 1;
                ans = max(ans, cnd1);
                dif = s - n;
                cnd2 = a[i] - (dif);
                ans = max(ans, cnd2);
                //cout << cnd1 << " " << cnd2 << endl;
                cout << ans << " ";
        }
    }
    }
    printf("\n");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define lld long long int

int main()
{
    int i;
    lld n, s;
    cin >> n >> s;

    lld a[n];
    for (i = 0; i < n; i++)
        cin >> a[i];

    //sort(a, a + n);
    lld tot = 0;
    for (i = 0; i < n; i++)
        tot += a[i];

    lld dif = 0, cnd1, cnd2;
    if (n == 1) {
        cout << a[0] - 1;
    }
    else {
    for (i = 0; i < n; i++) {
        lld ans = 0;
        if (s < n)
            cout << a[i] << " ";
        else {

                dif = s - (tot - a[i]);
                cnd1 = dif - 1;
                ans = max(ans, cnd1);
                dif = s - n;
                cnd2 = a[i] - (dif + 1);
                ans = max(ans, cnd2);
                //cout << cnd1 << " " << cnd2 << endl;
                cout << ans << " ";
        }
    }
    }
    printf("\n");

    return 0;
}