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 (Python):
s=input()
if s[-1]=='1':
  print(-1)
  exit()
if s[-2]=='0':
  print(-1)
  exit()

t=s[:-1]
D=[]
for i in range((len(t)+1)//2):
  if t[i]!=t[-1-i]:
    print(-1)
    exit()
m=1
A=[]
for i in range(1,len(s)//2+1):
    A.append((m,i+1))
    if s[i-1]=='1':
        m=i+1
for i in range(len(s)//2+2,len(s)+1):
    A.append((m,i))
for i in A:
    print(*i)

Solution (Python):
S = input()
eda = []
flag = False
N = len(S)
if S[-1] == '1':
  flag = True
if S[0] == '0':
  flag = True
if S[-2] == '0':
  flag = True
for k in range((N-1)//2):
  if S[k] != S[-k-2]:
    flag = True
  if S[k] == '1':
    eda.append(k+1)
if N%2 == 0:
  if S[N//2 -1] == '1':
    eda.append(N//2)
if flag:
  print(-1)
  exit()
ans = []
eda.reverse()
before = eda.pop()
while eda:
  after = eda.pop()
  for k in range(before, after):
    ans.append((k, after))
  before = after
ans.append((before, before+1))
for k in range(before+2, N+1):
  ans.append((before+1, k))
while ans:
  item = ans.pop()
  print(item[0], item[1])

Solution (Python):











S = input()
eda = []
flag = False
N = len(S)
if S[-1] == '1':
  flag = True
if S[0] == '0':
  flag = True
if S[-2] == '0':
  flag = True
for k in range((N-1)//2):
  if S[k] != S[-k-2]:
    flag = True
  if S[k] == '1':
    eda.append(k+1)
if N%2 == 0:
  if S[N//2 -1] == '1':
    eda.append(N//2)
if flag:
  print(-1)
  exit()
ans = []
eda.reverse()
before = eda.pop()
while eda:
  after = eda.pop()
  for k in range(before, after):
    ans.append((k, after))
  before = after
ans.append((before, before+1))
for k in range(before+2, N+1):
  ans.append((before+1, k))
while ans:
  item = ans.pop()
  print(item[0], item[1])

Solution (Python):
s=list(map(int,list(input())))

def main(s):
  n=len(s)
  if s[0]!=1 or s[-1]!=0:return [[-1]]
  for k in range(n//2-1):
    if s[k]!=s[n-k-2]:return [[-1]]
  uv=[(1,2)]
  t=2
  i=3
  for x in s[1:-1]:
    uv.append((t,i))
    if x==1:
      t=i
    i+=1
  return uv
for x in main(s):
  print(*x,sep=' ')

Solution (Python):
s=input()
n=len(s)

def check():
    if s[0]=="0" or s[-1] =="1":
        return False
    for i in range(n):
        if s[i] != s[n-i-2]:
            return False
    return True

if not check():
    print(-1)
    exit()

now=1
for i in range(n-1):
    print(now,i+2)
    if s[i]=="1":
        now=i+2

Solution (Python):
def ex():print(-1);exit()

s=input()
N=len(s)
if not (s[0]=='1' and s[-1]=='0'):
    ex()
for i in range(N//2):
    if s[i]!=s[N-i-2]:
        ex()
ans=[]
m=1
for i in range(1,N//2+1):
    ans.append((m,i+1))
    if s[i-1]=='1':
        m=i+1
for i in range(N//2+2,N+1):
    ans.append((m,i))
for t in ans:
    print(*t)

Solution (Python):
s = input()
if(s[0]=='0')|(s[-1]=='1'):
    print(-1)
    exit()

n = len(s)
size = []
for i in range(1,n//2):
    sl = s[i]
    sr = s[n-2-i]
    if(sl != sr):
        print(-1)
        exit()
    if(sl=='1'):
        size.append(i+1)

size.append(n-1)
ans = []
now = 1
for si in size:
    for j in range(now+1,si+2):
        ans.append(' '.join(map(str,[now,j])))
    now = si+1

print('\n'.join(ans))

Solution (Python):
s = input()
if s[0] == "0" or s[-1] == "1":
    print(-1)
    exit()
n = len(s)
if n == 2:
    if s == "10":
        print(1, 2)
        exit()
    else:
        print(-1)
        exit()

m = n // 2
tmp = m + 1
ANS = []
for i in reversed(range(1, m + 1)):
    j = n - i
    if s[i - 1] == "1" and s[j - 1] == "1":
        ANS.append((tmp, i))
        tmp = i
    elif s[i - 1] == "0" and s[j - 1] == "0":
        ANS.append((tmp, i))
    else:
        print(-1)
        exit()
for i in range(m + 2, n + 1):
    ANS.append((m + 1, i))

for a, b in ANS:
    print(a, b)

Solution (Python):
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  


S = LI2()
n = len(S)

if S[-1] == 1 or S[0] == 0 or S[-2] == 0:
    print(-1)
    exit()

for i in range(n-1):
    if S[i] != S[-2-i]:
        print(-1)
        exit()


k = S.count(1)  
for i in range(k):
    print(i+1,i+2)

a = 1  
b = k+2  
for i in range(n-1):
    if S[i] == 1:
        a += 1
    else:
        print(a,b)
        b += 1

Solution (Python):
def main():
    s = "0" + input()
    ans = []
    f = True
    for i in range(len(s)//2):
        if s[i] != s[len(s)-1-i]:
            f = False
            break
    if s[1] == "0" or s[-2] == "0":
        f = False
    if f:
        ans = []
        p = len(s)-1
        for i in reversed(range(1, len(s)-1)):
            c = s[i]
            ans.append([i, p])
            if c == "1":
                p = i
        for u, v in ans:
            print(u, v)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = "*" + input()
    N = len(S) - 1

    if S[N] == "1":
        return print(-1)
    if S[1] == "0":
        return print(-1)

    edge = []
    cur_u = 1
    cur_v = 2

    for i in range(1, N // 2 + 1):
        if S[i] != S[N - i]:
            return print(-1)

        edge.append([cur_u, cur_v])
        if S[i] == "1":
            cur_u = cur_v
        cur_v += 1

    for i in range(cur_v, N + 1):
        edge.append([cur_u, i])

    for i in range(N - 1):
        print(*edge[i])


if __name__ == '__main__':
    main()

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=list(map(int,list(input())))
n=len(s)

if s[-1]==1 or s[0]==0:
    print(-1)
    quit()

for i in range(n-1):
    if s[i]!=s[-2-i]:
        print(-1)
        quit()
s[-1]=1
now=n
for i in range(n-1)[::-1]:
    print(i+1,now)
    if s[i]==1:
        now=i+1

Solution (Python):
s = input()

if s[0] == '0' or s[-2] == '0' or s[-1] == '1':  
    print(-1)
elif s[:-1] != s[-2::-1]:
    print(-1)
else:
    half = len(s) // 2
    one_indices = [i+1 for i in range(1, half) if s[i] == '1'] 

    parents = [0] * (len(s) + 1)
    parent_index = 1
    for index in one_indices:
        for i in range(parent_index, index):
            parents[i] = index
        parent_index = index

    root = parent_index + 1
    parents[parent_index] = root
    for index in range(root + 1, len(s) + 1):
        parents[index] = root

    for node, parent in enumerate(parents):
        if parent == 0: 
            continue
        print(node, parent)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

s = input()
n = len(s)

if s[n-1] == "1" or s[0] == "0":
    print(-1)
    sys.exit()

for i in range((n-1) // 2):
    if s[i] != s[n-2-i]:
        print(-1)
        sys.exit()

j = 0
for i in range(1,n):
    if s[i] == "1":
        for k in range(j,i):
            print(k+1,i+1)
        j = i

for k in range(j+1,n):
    print(j+1,k+1)

Solution (Python):
s=list(input())
n=len(s)
if s[0]=='0' or s[-1]=='1':
  print(-1)
else:
  s.pop()
  sr=s.copy()
  sr.reverse()
  if s!=sr:
    print(-1)
  else:
    ans=[]
    now=1
    cnt=1
    for x in s:
      if x=='1':
        ans.append([now,now+cnt])
        now+=cnt
        cnt=1
      else:
        ans.append([now,now+cnt])
        cnt+=1
    for x in ans:
      print(x[0],x[1])

Solution (Python):
s=input()
n=len(s)
f=1
if s[-1]=="1":
  f=0
if s[0]=="0":
  f=0
for i in range(n-1):
  if s[i]!=s[-2-i]:
    f=0
    break
    
s=s[:-1]+"1"
if f:
  k=0
  for i in range(n):
    if s[i]=="1":
      for j in range(k,i):
        print(j+1,i+1)
      k=i
else:
  print(-1)

Solution (Python):
s = input()
if s[-1] == "1":
  print(-1)
  exit()
s = s[:-1]
if s != s[::-1] or s[0] == "0":
  print(-1)
  exit()
s += "1"
n = len(s)
now = 1
for i, t in enumerate(s, 1):
  if t == "1":
    for j in range(now, i):
      print(j, i)
      now = i

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def ng():
    if s[0]=="0" or s[-1]=="1":return True
    for i in range(n):
        if i>n-2-i:break
        if s[i]!=s[n-2-i]:return True
    return False

s=SI()
n=len(s)

if ng():
    print(-1)
    exit()

aa=[]
for i in range(n//2):
    if s[i]=="1":aa.append(i+1)
aa.append(n)

ans=[]
for i in range(len(aa)-1):ans.append([i+1,i+2])

j=len(aa)+1
for i,(a0,a1) in enumerate(zip(aa,aa[1:])):
    for _ in range(a1-a0-1):
        ans.append([i+2,j])
        j+=1

for u,v in ans:print(u,v)

Solution (Python):
s = input().strip()
n = len(s)
s = "0"+s
flag = 0
if s[n]=="1" or s[1]=="0":
    flag = 1
else:
    for i in range(1,n):
        if s[i]!=s[n-i]:
            flag = 1
            break
if flag==1:
    print(-1)
else:
    A = [1]
    for i in range(2,n):
        if s[i]=="1":
            while A:
                print(A.pop(),i)
            A = [i]
        else:
            A.append(i)
    print(n-1,n)

Solution (Python):
import sys
s=input()
n=len(s)
if s[-1]=='1':
  print(-1)
  sys.exit()
if s[0]=='0':
  print(-1)
  sys.exit()
for i in range(n-1):
  if s[i]!=s[n-2-i]:
    print(-1)
    sys.exit()
ans=['1','2']
print(' '.join(ans))
current=2
for i in range(1,n-1):
  ans=[]
  ans.append(str(current))
  ans.append(str(i+2))
  print(' '.join(ans))
  if s[i]=='1':
    current=i+2

Solution (Python):
s=input()
if s[0]=="0":exit(print(-1))
if s[-1]=="1":exit(print(-1))
for i in range(len(s)-1):
  if s[i]!=s[(len(s)-1)-(i+1)]:exit(print(-1))
ans=[]
for i in range(len(s)-1):
  if s[i]=="1":
    for j in ans:print(j+1,i+1)
    ans=[]
  ans.append(i)
for j in ans:print(j+1,len(s))

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate,combinations,permutations

from heapq import heapify,heappop,heappush


from functools import lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    

    
    
    
    
    

    s=input()
    N=len(s)
    f=1
    if s[-1]=="1" or s[0]=="0":
        f=0
    for i in range(1,N//2+1):
        if s[i-1]!=s[N-i-1]:
            f=0
            break
    if not f:
        print(-1)
        return
    
    il=[]
    edge=[]
    for i in range(1,N//2+1):
        if s[i-1]=="0":
            il.append(i)
        else:
            for j in il:
                edge.append((i,j))
            il=[i]
    i=N//2+1
    for j in il:
        edge.append((i,j))
    j=i
    for i in range(N//2+2,N+1):
        edge.append((j,i))

    for e in edge:
        print(*e)







if __name__ == "__main__":
    main()

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
	return list(map(int,input().split()))
def m(): 
	return map(int,input().split())
def onem(): 
	return int(input())
def s(x): 
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): 
	return " ".join(map(str,x))
def max2(x): 
	return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

s = input()[:-1]

if s[0] == "1" and s[-1] == "0":
	k = (len(s)-2)//2

	for i in range(k):
		if s[i] != s[-(2 + i)]:
			print(-1)
			exit()
	else:
		
		la = len(s)

		for i in range(la-2,-1,-1):
			if s[i] == "1":
				print(i+1,la)
				la = i+1
			else:
				print(i+1,la)
else:
	print(-1)

Solution (Python):
s = input()
n = len(s)
ok = s[0] == '1' and s[n-1] == '0'
for i in range(n-1):
    ok = ok and s[i] == s[n-2-i]
if not ok:
    print(-1)
    exit()
s2 = s[:n//2]
i = s2.rindex('1')
for k in range(i, n-1):
    print(n, k+1)
while i > 0:
    j = i - 1
    while s[j] != '1':
        j -= 1
    for k in range(j, i):
        print(i+1, k+1)
    i = j

Solution (Python):
S = input()
N = len(S)

if S[-1] == '1' or S[0] == '0':
    print(-1)

else:
    for i in range(N - 1):
        if S[i] != S[N - 2 - i]:
            print(-1)
            break
    else:
        tmp = 1
        for i in range(N - 1):
            if S[i] == '1':
                print(tmp, i + 2)
                tmp = i + 2
            else:
                print(tmp, i + 2)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    N = len(S)
    if S[0] == '0' or S[-1] == '1':
        print(-1)
        return
    cnt = 0
    flag = True
    for i in range(N - 1):
        if S[i] != S[N - i - 2]:
            flag = False
            break
        if S[i] == '1':
            cnt += 1
    if not flag:
        print(-1)
        return
    
    edge = []
    for i in range(cnt):
        edge.append((i + 1,i + 2))
    
    extend = 0
    now = cnt + 2
    vertex = 2
    for i in range(1,N - 1):
        if S[i] == '0':
            extend += 1
        else:
            for _ in range(extend):
                edge.append((vertex,now))
                now += 1
            extend = 0
            vertex += 1

    if now == N + 1:
        print('\n'.join(' '.join(map(str,a)) for a in edge))
    else:
        print(-1)
if __name__ == '__main__':
    main()

Solution (Python):
s = list(input())
n = len(s)
if s[-1] == "1":
    print(-1)
    exit()
if s[:-1] != s[:-1][::-1]:
    print(-1)
    exit()
if s[0] == "0":
    print(-1)
    exit()

before = -1
for i in range(n // 2):
    if s[i] == "1":
        num = i - before
        for j in range(num):
            print(before+2, i+2-j)
        before = i

for j in range(n-2-before):
    print(before+2, before+3+j)

Solution (Python):
def check(S):
    size = len(S)
    if S[0]=="0" or S[-1]=="1":
        return False
    else:
        for i in range(size-1):
            a, b = i, size-i-2
            if (S[a]=="1" and S[b]=="0") or (S[a]=="0" and S[b]=="1"):
                return False
        return True


S = input()
if check(S):
    N = len(S)
    l = [1]
    p = False
    for i in range(2, N+1):
        if p:
            l.append(i)
        else:
            print(l[-1], i)
        p = (S[i-1]=="1")
    for i in range(len(l)-1):
        print(l[i], l[i+1])
else:
    print(-1)

Solution (Python):
S = input()

def check(S):
    size = len(S)
    if S[0]=="0" or S[-1]=="1":
        return False
    else:
        for i in range(size-1):
            a, b = i, size-i-2
            if (S[a]=="1" and S[b]=="0") or (S[a]=="0" and S[b]=="1"):
                return False
        return True

if check(S):
    N = len(S)
    l = [1]
    p = False
    for i in range(2, N+1):
        if p:
            l.append(i)
            if S[i-1]=="1":
                p = True
            else:
                p = False
        else:
            print(l[-1], i)
            if S[i-1]=="1":
                p = True
    sl = len(l)
    for i in range(sl-1):
        print(l[i], l[i+1])
else:
    print(-1)

Solution (Python):
s=input()
if s[0]=='0' or s[-1]=='1' or s[:-1]!=s[:-1][::-1]:
    print(-1)
    exit(0)
e=[]
bi=0
for i,j in enumerate(s[:-1]):
    e.append([bi,i+1])
    if j=='1':
        bi=i+1
for i,j in e:
    print(i+1,j+1)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

s = input()
n = len(s)
if s[0]=="0" or s[-2]=="0" or s[-1]=="1":
    print("-1")
elif any(s[i]!=s[-2-i] for i in range(n-1)):
    print("-1")
else:
    i = 1
    ps = set([i])
    es = []
    for c in s[1:]:
        i += 1
        if c=="0":
            ps.add(i)
        else:
            for u in ps:
                es.append("%s %s" % (u,i))
            ps = set([i])
    for u in ps:
        if u!=n:
            es.append("%s %s" % (u, n))
    write("\n".join(es))

Solution (Python):
s = list(input())
n = len(s)
if s[n - 1] == "1" or s[0] == "0":
    print(-1)
    exit()
for i in range((n - 1) // 2):
    if not s[i] == s[n - 2 - i]:
        print(-1)
        exit()
l = n - s.count("0") + 1
x = [0] * l
j = 0
for i in range(n // 2):
    if s[i] == "1":
        j += 1
    else:
        x[j] += 1
        x[l - 1 - j] += 1
        if j == l - 1 - j and n % 2 == 0 and i == (n - 1) // 2:
            x[j] -= 1
for i in range(l - 1):
    print(i + 1, i + 2)
k = n - s.count("0") + 2
for i in range(l):
    for _ in range(x[i]):
        print(i + 1, k)
        k += 1

Solution (Python):
s = input()

if s[0] == '0' or s[-1] == '1' or s[:-1] != s[:-1][::-1]:
    print(-1)
    exit(0)

edges = []
head = 0
for idx, i in enumerate(s[:-1]):
    edges.append([head, idx + 1])
    if i == '1':
        head = idx + 1
for i, j in edges:
    print(i + 1, j + 1)

Solution (Python):
def main():
    S = list(input())

    N = len(S)

    if (S[0] == '0') or (S[-1] == '1'):
        print (-1)
        return 0

    lst = []
    for i in range((N - 1) // 2):
        if S[i] != S[N - 2 - i]:
            print (-1)
            return 0
        if S[i] == '1':
            lst.append(i + 1)
    if N % 2 == 0 and S[N//2 - 1] == '1':
        lst.append(N//2)
    

    if lst[-1] * 2 != N:
        center = lst[-1] + 1
        for x in range(lst[-1] * 2 + 2, N + 1):
            print (center, x)

        before = 1
        n = lst[-1] * 2 + 2
        tmp = 1
        for tmp in lst[1:]:
            print (before, tmp)
            print (n - before, n - tmp)
            for x in range(tmp - before - 1):
                print (before + 1 + x, tmp)
                print (n - (before + 1 + x), n - tmp)
            before = tmp
        print (tmp, center)
        print (n - tmp, center)

    if lst[-1] * 2 == N:
        before = 1
        n = lst[-1] * 2 + 1
        tmp = 1
        for tmp in lst[1:]:
            print (before, tmp)
            print (n - before, n - tmp)
            for x in range(tmp - before - 1):
                print (before + 1 + x, tmp)
                print (n - (before + 1 + x), n - tmp)
            before = tmp
        print (tmp, n - tmp)

if __name__ == '__main__':
    main()

Solution (Python):
def Tree():
    S = input()
    N = len(S)

    if S[0] == "0" or S[-1] == "1":
        return []

    for i in range(N - 1):
        if S[i] != S[N - i - 2]:
            return []

    res = []
    path = S.count("1")
    for i in range(1, path + 1):
        res.append((i, i + 1))

    u = len(res) + 1
    v = 1
    for s in S[:-1]:
        if s == "1":
            v += 1
        else:
            u += 1
            res.append((v, u))

    return res


if __name__ == "__main__":
    tree = Tree()
    if tree:
        for x, y in tree:
            print(x, y)
    else:
        print(-1)

Solution (Python):
def no():
    print(-1)
    exit()


s = input()
n = len(s)

if s[-1] == "1":
    no()

s = s[:-1]

if s != s[::-1]:
    no()

if s[0] == "0":
    no()

li = [0]
adj = [[] for _ in range(n + 1)]
for v, e in enumerate(s, 1):
    if e == "1":
        for u in li:
            adj[u].append(v)
        li = []

    li.append(v)

adj[n-1].append(n)

for u, vs in enumerate(adj[1:], 1):
    for v in vs:
        print(u, v)

Solution (Python):
s=input()
n=len(s)
if s[-1]=="1":
    print(-1)
    exit()

if s[0]=="0":
    print(-1)
    exit()

data=[]
for i in range(0,n-1):
    if s[i]=="1":
        data.append(i+1)
        if s[n-2-i]=="0":
            print(-1)
            exit()
m=len(data)
edge=[]
for i in range(1,m):
    edge.append((i,i+1))
index=m+1
for i in range(1,m):
    if i!=1:
        size=data[-i]
        nextsize=data[-i-1]
        E=size-1-nextsize
        count=0
        while E>count:
            edge.append((i,index))
            index+=1
            count+=1
    else:
        size=n
        nextsize=data[-2]
        E=size-1-nextsize
        count=0
        while E>count:
            edge.append((i,index))
            index+=1
            count+=1

for i in range(n-1):
    u,v=edge[i]
    print(u,v)

Solution (Python):
s=input()
n=len(s)
if s[0]=="0" or s[-1]=="1":print(-1);exit()
for i in range(n-1):
  if s[i]!=s[-i-2]:print(-1);exit()
b=[]
for i in range(n-1):
  if s[i]=="1":
    for j in b:print(j+1,i+1)
    b=[]
  b.append(i)
for j in b:print(j+1,n)

Solution (Python):
s=input()
if s[0]=='0':
  print(-1)
elif s[-1]=='1':
  print(-1)
else:
  l=len(s)
  for i in range(l-1):
    if s[i]!=s[l-i-2]:
      print(-1)
      exit()
  ans=[]
  base=1
  for i in range(l-1):
    if s[i]=='1':
      print(base,i+2)
      base=i+2
    else:
      print(base,i+2)

Solution (Python):
s = list(map(int, input()))
n = len(s)
if s[0]==0 or s[-1] == 1 or any(s[i]!=s[i] for i in range(n//2)):
    print(-1)
    exit()
G = [[] for i in range(n)]
cur = 0
for i in range(n-1):
    G[cur].append(i+1)
    G[i+1].append(cur)

    if s[i]:
        cur = i+1

root = n//2
from collections import deque
size = [1]*n
ans = [0]*n
edges = []
def bfs1(root):
    rev = [(root, -1)]
    for i in range(n):
        cur, par = rev[i]
        for to in G[cur]:
            if to != par:
                rev.append((to, cur))
    for i in reversed(range(1,n)):
        cur, par = rev[i]
        size[par] += size[cur]
        ans[size[cur]] = 1
        ans[n-size[cur]] = 1
        edges.append([cur+1, par+1])
bfs1(0)

if any(ans[i+1]!=s[i] for i in range(n-1)):
    print(-1)
    exit()

for i in edges:
    print(*i)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

s = input().rstrip()
N = len(s)
if s[0] == '0' or s[-1] == '1' or s[:-1] != s[:-1][::-1]:
    print(-1)
    exit()
subtree = [[] for _ in range(N+1)]
prev = 1
for i in range(2, N+1):
    if s[i-1] == '1' or i == N:
        subtree[i] = [prev] + [1] * (i-prev-1)
        prev = i

i = 1
def dfs(size):
    global i
    v = i
    for c in subtree[size]:
        i += 1
        print(v, i)
        dfs(c)

dfs(N)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)
S = '0' + S
 
if S[1] == '0' or S[N] == '1' or S != S[::-1]:
    print(-1)
    exit()

edges = []
base = 1
for i in range(1, N):
    edges.append((base, i+1))
    if S[i] == '1':
        base = i + 1
[print(*edge) for edge in  edges]

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



s = list(input())
n = len(s)

for i in range((n-1)//2+1):
    if s[i] != s[n-2-i]:
        print(-1)
        exit()

if s[0] == '0':
    print(-1)
    exit()

if s[n-1] == '1':
    print(-1)
    exit()

from_ = 1
to_ = 2
ans = []
for i in range(n-1):
    ans.append((from_,to_))
    if s[i] == '1':
        from_ = to_
        to_ += 1
    else:
        to_ += 1

for a in ans:
    print(*a)

Solution (Python):
S = input()
n = len(S)
m = n // 2
if S[0] == '0' or S[-1] == '1':
  print(-1)
  quit()

ans = [[1, 2]]
node = 1
now = 3
for i in range(m):
  if S[i] != S[n-i-2]:
    print(-1)
    quit()
  else:
    if i == 0:
      continue
    ans.append([node, now])
    if S[i] == '0':
      now += 1
    else:
      node = now
      now += 1

for i in range(now, n+1):
  ans.append([node, i])

for a in ans:
  print(*a)

Solution (Python):
s = input()
n = len(s)

if s[0] != "1" or s[n - 1] != "0":
  print("-1")
  exit()

for i in range(n):
  if s[i] != s[n - 2 - i]:
    print("-1")
    exit()

x = 1
for i in range(1, n):
  print(x, i + 1)
  if s[i - 1] == "1": x = i + 1

Solution (Python):
import sys


def main():
    s = list(input())
    l = len(s)
    if s[0] != "1" or s[-1] != "0":
        print(-1)
    else:
        for i in range(l//2):
            if s[i] != s[l-i-2]:
                print(-1)
                exit()
        s = s[::-1]
        s[0] = "1"
        now = 0
        ans = []
        while now<l-1:
            c = 1
            ans.append((l-now,l-(now+c)))
            while s[now+c] == "0":
                c += 1
                ans.append((l-now,l-(now+c)))
            now += c
        for x,y in ans:
            print(x,y)

if __name__ == "__main__":
    main()

Solution (Python):
s=input()
n=len(s)
if s[0]=="0" or s[-1]=="1" or any(s[i]!=s[n-i-2] for i in range(n-1)):
	print(-1)
	exit()
ans=[]
now=0
for i,c in enumerate(s[:-1]):
	if c=="1":
		ans.append("{} {}".format(now+1,i+2))
		now=i+1
	else:
		ans.append("{} {}".format(now+1,i+2))
print(*ans,sep="\n")

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
n = len(s)
s = '0'+s
if s[1]=='0' or s[n]=='1':
    print(-1)
    exit()
for i in range(1,n):
    if s[i]!=s[n-i]:
        print(-1)
        exit()
e = []
p = 1
for i in range(2,n+1):
    if s[i]=='1' or i==n:
        for j in range(p,i):
            e.append((j,i))
        p = i
for z in e:
    print("{} {}".format(z[0],z[1]))

Solution (Python):
s = input()
N = len(s)
flag = False
for i in range(N):
  if s[i]=='1':
    if s[N-2-i]!='1':
      print(-1)
      break
else:
  if s[0]=='0' or s[-1]=='1':
    print(-1)
  else:
    s = list(s)
    s[-1] = '1'
    ls = []
    for i in range(N):
      if s[i]=='1':
        ls.append(i)
    ps = 0
    for i in range(N-1):
      if i==ls[ps]:
        ps += 1
      print(i+1,ls[ps]+1)

Solution (Python):
S=[int(c) for c in input()]
N=len(S)
r=all([S[i]==S[N-i-2] for i in range(N//2)]) and S[0] and not S[-1]
t=[(1,2)]
e=2
for i in range(1,(N-1)//2):
    t.append((e,i+2))
    if S[i]:
        e=i+2
f=1
if N%2==0:
    t.append((e,N-e+1))
    if S[N//2-1]:
        f=0
for i in range(0,(N-1)//2):
    t.append([e if t[i][j]==e and f else (N-e+1 if t[i][j]==N-t[i][j]+1 and f else N-t[i][j]+1) for j in range(2)])
if r:
    print(*[str(l[0])+" "+str(l[1]) for l in t],sep='\n')
else:
    print(-1)

Solution (Python):

s = input()
n = len(s)
if s[-1] == '1':
  print(-1)
  exit()
t = s[:-1]
if t[::-1] != t:
  print(-1)
  exit()
if s[0] == '0':
  print(-1)
  exit()
print(0+1,1+1)
now = 0
for i in range(2,n):
  print(now+1,i+1)
  if s[i-1] == '1':
    now = i

Solution (Python):
s = input()
n = len(s)

if s[n - 1] == '1' or s[0] == '0':
    print(-1)
    exit()

for i in range(n):
    if s[i] != s[n - i - 2]:
        print(-1)
        exit()

cur_s = 2
cur_p = 2
print(1, 2)
for i in range(n - 2):
    if s[i + 1] == '1':
        print(cur_s + 1, cur_p)
        cur_p = cur_s + 1
    else:
        print(cur_s + 1, cur_p)
    cur_s += 1

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = '-' + sr()
N = len(S) - 1

def solve(S):
    if S[1] == '0' or S[N] == '1':
        return None
    prev = 1
    graph = []
    for i in range(1, N//2 + 1):
        if S[i] != S[N-i]:
            return None
        if S[i] == '0':
            continue
        for x in range(prev, i):
            graph.append('{} {}'.format(x, i))
        prev = i
    for x in range(prev, N):
        graph.append('{} {}'.format(x, N))
    return graph

graph = solve(S)
if graph is None:
    print(-1)
else:
    print('\n'.join(graph))