Problem:
Score : 700 points

Problem Statement

You are given a string s of length n.
Does a tree with n vertices that satisfies the following conditions exist?

The vertices are numbered 1,2,..., n.

The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i.

If the i-th character in s is 1, we can have a connected component of size i by removing one edge from the tree.

If the i-th character in s is 0, we cannot have a connected component of size i by removing any one edge from the tree.

If such a tree exists, construct one such tree.

Constraints

2 \leq n \leq 10^5

s is a string of length n consisting of 0 and 1.

Input

Input is given from Standard Input in the following format:

s

Output

If a tree with n vertices that satisfies the conditions does not exist, print -1.

If a tree with n vertices that satisfies the conditions exist, print n-1 lines.
The i-th line should contain u_i and v_i with a space in between.
If there are multiple trees that satisfy the conditions, any such tree will be accepted.

Sample Input 1

1111

Sample Output 1

-1

It is impossible to have a connected component of size n after removing one edge from a tree with n vertices.

Sample Input 2

1110

Sample Output 2

1 2
2 3
3 4

If Edge 1 or Edge 3 is removed, we will have a connected component of size 1 and another of size 3. If Edge 2 is removed, we will have two connected components, each of size 2.

Sample Input 3

1010

Sample Output 3

1 2
1 3
1 4

Removing any edge will result in a connected component of size 1 and another of size 3.

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

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 check(s: &Vec<u32>) -> bool {
    let n = s.len();
    if s[0] == 0 {
        return false;
    }
    if s[n - 1] == 1 {
        return false;
    }
    for i in 0..n / 2 {
        if s[i] != s[n - i - 2] {
            return false;
        }
    }
    true
}

struct Tree {
    id: usize,
    child: Vec<Tree>,
}

impl Tree {
    fn new(id: usize) -> Tree {
        Tree {
            id: id,
            child: Vec::new(),
        }
    }

    fn add_child(&mut self, mut sorted_child_nums: Vec<usize>) {
        assert!(self.child.is_empty());
        if sorted_child_nums.len() == 0 {
            return;
        }
        if sorted_child_nums.len() == 1 {
            for i in 0..sorted_child_nums[0] - 1 {
                self.child.push(Tree::new(self.id + i + 1));
            }
            return;
        }

        let max_child_num = sorted_child_nums.pop().unwrap();
        let second_child_num = sorted_child_nums[sorted_child_nums.len() - 1];

        self.child.push(Tree::new(self.id + 1));
        self.child[0].add_child(sorted_child_nums);

        for i in second_child_num..max_child_num {
            self.child.push(Tree::new(self.id + i));
        }
    }

    fn print(&self) {
        for ref child in self.child.iter() {
            println!("{0} {1}", self.id + 1, child.id + 1);
            child.print();
        }
    }
}

fn main() {
    let s = read::<String>()
        .chars()
        .map(|x| x.to_digit(10).unwrap())
        .collect::<Vec<u32>>();
    if !check(&s) {
        println!("-1");
        return;
    }
    let n = s.len();

    let mut odd_elements = Vec::new();
    let mut even_elements = Vec::new();

    for i in 1..n / 2 {
        let num = i + 1;
        if s[i] == 1 && num >= 1 {
            if num % 2 == 1 {
                odd_elements.push(num);
            } else {
                even_elements.push(num);
            }
        }
    }
    // println!("even elements {:?}", &even_elements);
    // println!("odd elements {:?}", &odd_elements);

    // make 0-indexed tree.
    let mut root = Tree::new(0);
    let mut idx_for_odd_max = 0;
    if !odd_elements.is_empty() {
        idx_for_odd_max = if let Some(&x) = odd_elements.iter().max() {
            x
        } else {
            1
        };
        let mut odd_root = Tree::new(1);
        odd_root.add_child(odd_elements);
        root.child.push(odd_root);
    }

    let mut idx_for_even_max = idx_for_odd_max;
    if !even_elements.is_empty() {
        idx_for_even_max = if let Some(&x) = even_elements.iter().max() {
            x + idx_for_odd_max
        } else {
            1 + idx_for_odd_max
        };
        let mut even_root = Tree::new(idx_for_odd_max + 1);
        even_root.add_child(even_elements);
        root.child.push(even_root);
    }

    for i in idx_for_even_max + 1..n {
        root.child.push(Tree::new(i));
    }

    root.print();
}