macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let _n = parse_line!(usize);
    let a = parse_line_to_vec!(usize);
    let mut maxs = vec![0; 1000001];
    for &x in a.iter() {
        maxs[x] = x;
    }
    for i in 1..maxs.len() {
        maxs[i] = std::cmp::max(maxs[i], maxs[i - 1]);
    }
    let mut result = 0;
    for x in a {
        result = std::cmp::max(result, maxs.last().unwrap() % x);
        for i in (x * 2..maxs.len()).step_by(x) {
            result = std::cmp::max(result, maxs[i] % x);
        }
    }
    writeln!(writer, "{}", result).unwrap();
}

fn main() {
    let tests = 1; // parse_line!(usize);
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    for _ in 0..tests {
        solve(&mut writer);
    }
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let _n = parse_line!(usize);
    let a = parse_line_to_vec!(usize);
    let mut maxs = vec![0; 1000001];
    for &x in a.iter() {
        maxs[x] = x;
    }
    for i in 1..maxs.len() {
        maxs[i] = std::cmp::max(maxs[i], maxs[i - 1]);
    }
    let mut result = 0;
    for x in a.into_iter().collect::<std::collections::BTreeSet<usize>>() {
        result = std::cmp::max(result, maxs.last().unwrap() % x);
        for &val in maxs.iter().skip(x * 2 - 1).step_by(x) {
            result = std::cmp::max(result, val % x);
        }
    }
    writeln!(writer, "{}", result).unwrap();
}

fn main() {
    let tests = 1; // parse_line!(usize);
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    for _ in 0..tests {
        solve(&mut writer);
    }
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let _n = parse_line!(usize);
    let a = parse_line_to_vec!(usize);
    let mut maxs = vec![0; 1000001];
    for &x in a.iter() {
        maxs[x] = x;
    }
    for i in 1..maxs.len() {
        maxs[i] = std::cmp::max(maxs[i], maxs[i - 1]);
    }
    let mut result = 0;
    for x in a.into_iter().collect::<std::collections::BTreeSet<usize>>() {
        result = std::cmp::max(result, maxs.last().unwrap() % x);
        for val in maxs.iter().skip(x * 2).step_by(x) {
            result = std::cmp::max(result, val % x);
        }
    }
    writeln!(writer, "{}", result).unwrap();
}

fn main() {
    let tests = 1; // parse_line!(usize);
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    for _ in 0..tests {
        solve(&mut writer);
    }
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	maxN = 2000005
)

var A [maxN]int
var MI [maxN]int

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	for i := 0; i < N; i++ {
		x := fsc.NextInt()
		A[x] = 1
	}
	for i := 1; i < maxN; i++ {
		if A[i] == 1 {
			MI[i] = i
		} else {
			MI[i] = MI[i-1]
		}
	}
	ma := 0
	for i := 1; i < 1000001; i++ {
		if A[i] == 1 {
			for j := 2; j*i-1 < maxN; j++ {
				// fmt.Println(i, j, j*i-1)
				ma = IntMax(ma, MI[j*i-1]%i)
			}
		}
	}
	fmt.Println(ma)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}


import sys
range = xrange
input = raw_input

maxi = 0
n = int(input())
A = [int(x) for x in input().split()]

big = 10**6 + 1
count = [0]*(2*big)
for a in A:
    count[a] = 1

prevs = []
prev = -1
for i in range(2 * big):
    prevs.append(prev)
    if count[i]:
        prev = i

for i in range(1, big):
    if count[i]:
        for j in range(2*i, big + i, i):
            maxi = max(maxi, i - j + prevs[j])

print maxi


import sys
range = xrange
input = raw_input

maxi = 0
n = int(input())
A = [int(x) for x in input().split()]

big = 10**6 + 1
count = [0]*big
for a in A:
    count[a] = 1

prevs = []
prev = -1
for i in range(big):
    prevs.append(prev)
    if count[i]:
        prev = i

for i in range(1, big):
    if count[i]:
        for j in range(2*i, big + i, i):
            maxi = max(maxi, i - j + prevs[j])

print maxi


import sys
range = xrange
input = raw_input

maxi = 0
n = int(input())
A = [int(x) for x in input().split()]

big = 2 * 10**6 + 1
count = [0]*big
for a in A:
    count[a] = 1

prevs = []
prev = -1
for i in range(big):
    prevs.append(prev)
    if count[i]:
        prev = i

for i in range(1, big):
    if count[i]:
        for j in range(2*i, big, i):
            maxi = max(maxi, i - j + prevs[j])

print maxi


import sys
range = xrange
input = raw_input

maxi = 0
n = int(input())
A = [int(x) for x in input().split()]

big = 10**6 + 1
count = [0]*big
for a in A:
    count[a] = 1

prevs = []
prev = -1
for i in range(big):
    prevs.append(prev)
    if count[i]:
        prev = i

for i in range(1, big):
    if count[i]:
        for j in range(2*i, big, i):
            maxi = max(maxi, i - j + prevs[j])

print maxi


import sys
range = xrange
input = raw_input

maxi = 0
n = int(input())
A = [int(x) for x in input().split()]

big = 10**6 + 1
count = [0]*big
for a in A:
    count[a] = 1

prevs = []
prev = -1
for i in range(2 * big):
    prevs.append(prev)
    if count[i]:
        prev = i

for i in range(1, big):
    if count[i]:
        for j in range(2*i, big + i, i):
            maxi = max(maxi, i - j + prevs[j])

print maxi


import sys
range = xrange
input = raw_input

maxi = 0
n = int(input())
A = [int(x) for x in input().split()]

big = 10**6 + 1
count = [0]*big
for a in A:
    count[a] = 1

prevs = []
prev = -1
for i in range(big):
    prevs.append(prev)
    if count[i]:
        prev = i

for i in range(1, big):
    if count[i]:
        for j in range(2*i, big, i):
            k = prevs[j]
            if j - k < i:
                maxi = max(maxi, j - k)

print maxi


"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""

import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect

from types import GeneratorType
BUFSIZE = 8192
class SortedList:
    def __init__(self, iterable=[], _load=200):
        """Initialize sorted list instance."""
        values = sorted(iterable)
        self._len = _len = len(values)
        self._load = _load
        self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
        self._list_lens = [len(_list) for _list in _lists]
        self._mins = [_list[0] for _list in _lists]
        self._fen_tree = []
        self._rebuild = True

    def _fen_build(self):
        """Build a fenwick tree instance."""
        self._fen_tree[:] = self._list_lens
        _fen_tree = self._fen_tree
        for i in range(len(_fen_tree)):
            if i | i + 1 < len(_fen_tree):
                _fen_tree[i | i + 1] += _fen_tree[i]
        self._rebuild = False

    def _fen_update(self, index, value):
        """Update `fen_tree[index] += value`."""
        if not self._rebuild:
            _fen_tree = self._fen_tree
            while index < len(_fen_tree):
                _fen_tree[index] += value
                index |= index + 1

    def _fen_query(self, end):
        """Return `sum(_fen_tree[:end])`."""
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        x = 0
        while end:
            x += _fen_tree[end - 1]
            end &= end - 1
        return x

    def _fen_findkth(self, k):
        """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
        _list_lens = self._list_lens
        if k < _list_lens[0]:
            return 0, k
        if k >= self._len - _list_lens[-1]:
            return len(_list_lens) - 1, k + _list_lens[-1] - self._len
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        idx = -1
        for d in reversed(range(len(_fen_tree).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                idx = right_idx
                k -= _fen_tree[idx]
        return idx + 1, k

    def _delete(self, pos, idx):
        """Delete value at the given `(pos, idx)`."""
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len -= 1
        self._fen_update(pos, -1)
        del _lists[pos][idx]
        _list_lens[pos] -= 1

        if _list_lens[pos]:
            _mins[pos] = _lists[pos][0]
        else:
            del _lists[pos]
            del _list_lens[pos]
            del _mins[pos]
            self._rebuild = True

    def _loc_left(self, value):
        """Return an index pair that corresponds to the first position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        lo, pos = -1, len(_lists) - 1
        while lo + 1 < pos:
            mi = (lo + pos) >> 1
            if value <= _mins[mi]:
                pos = mi
            else:
                lo = mi

        if pos and value <= _lists[pos - 1][-1]:
            pos -= 1

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value <= _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def _loc_right(self, value):
        """Return an index pair that corresponds to the last position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        pos, hi = 0, len(_lists)
        while pos + 1 < hi:
            mi = (pos + hi) >> 1
            if value < _mins[mi]:
                hi = mi
            else:
                pos = mi

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value < _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def add(self, value):
        """Add `value` to sorted list."""
        _load = self._load
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len += 1
        if _lists:
            pos, idx = self._loc_right(value)
            self._fen_update(pos, 1)
            _list = _lists[pos]
            _list.insert(idx, value)
            _list_lens[pos] += 1
            _mins[pos] = _list[0]
            if _load + _load < len(_list):
                _lists.insert(pos + 1, _list[_load:])
                _list_lens.insert(pos + 1, len(_list) - _load)
                _mins.insert(pos + 1, _list[_load])
                _list_lens[pos] = _load
                del _list[_load:]
                self._rebuild = True
        else:
            _lists.append([value])
            _mins.append(value)
            _list_lens.append(1)
            self._rebuild = True

    def discard(self, value):
        """Remove `value` from sorted list if it is a member."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_right(value)
            if idx and _lists[pos][idx - 1] == value:
                self._delete(pos, idx - 1)

    def remove(self, value):
        """Remove `value` from sorted list; `value` must be a member."""
        _len = self._len
        self.discard(value)
        if _len == self._len:
            raise ValueError('{0!r} not in list'.format(value))

    def pop(self, index=-1):
        """Remove and return value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        value = self._lists[pos][idx]
        self._delete(pos, idx)
        return value

    def bisect_left(self, value):
        """Return the first index to insert `value` in the sorted list."""
        pos, idx = self._loc_left(value)
        return self._fen_query(pos) + idx

    def bisect_right(self, value):
        """Return the last index to insert `value` in the sorted list."""
        pos, idx = self._loc_right(value)
        return self._fen_query(pos) + idx

    def count(self, value):
        """Return number of occurrences of `value` in the sorted list."""
        return self.bisect_right(value) - self.bisect_left(value)

    def __len__(self):
        """Return the size of the sorted list."""
        return self._len

    def __getitem__(self, index):
        """Lookup value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        return self._lists[pos][idx]

    def __delitem__(self, index):
        """Remove value at `index` from sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        self._delete(pos, idx)

    def __contains__(self, value):
        """Return true if `value` is an element of the sorted list."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_left(value)
            return idx < len(_lists[pos]) and _lists[pos][idx] == value
        return False

    def __iter__(self):
        """Return an iterator over the sorted list."""
        return (value for _list in self._lists for value in _list)

    def __reversed__(self):
        """Return a reverse iterator over the sorted list."""
        return (value for _list in reversed(self._lists) for value in reversed(_list))

    def __repr__(self):
        """Return string representation of sorted list."""
        return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import collections as col
import math, string

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

MOD = 10**9+7
#t=int(input())
t=1
p=10**9+7
def ncr_util():

    inv[0]=inv[1]=1
    fact[0]=fact[1]=1
    for i in range(2,300001):
        inv[i]=(inv[i%p]*(p-p//i))%p
    for i in range(1,300001):
        inv[i]=(inv[i-1]*inv[i])%p
        fact[i]=(fact[i-1]*i)%p

def solve():
    ans,ind=0,-1
    MAXN=2*(10**6)+2
    l1=[-1]*(2*(10**6)+2)

    for i in l:
        l1[i+1]=i
    l1[0]=0
    for i in range(1,MAXN):
        if l1[i]==-1:
            l1[i]=l1[i-1]
    maxi=2*max(l)

    for i in range(len(l)):
        m=2
        j=l[i]*2
        #print(123,j)
        while j<=maxi:
            ans=max(l1[j]%l[i],ans)
            #print(124,j,l1[j],l[i])
            j+=l[i]

    return ans
for _ in range(t):
    n=int(input())
    #n=int(input())
    #n,m=(map(int,input().split()))
    #n1=n
    #x=int(input())
    #b=int(input())
    #n,m,k=map(int,input().split())
    #l,r=map(int,input().split())
    #n=int(input())
    #s=input()
    #s1=input()
    #p=input()
    l=list(map(int,input().split()))
    l=list(set(l))
    l.sort()
    #l.sort()
    #l.sort(revrese=True)
    #l2=list(map(int,input().split()))
    #l=str(n)
    #l.sort(reverse=True)
    #l2.sort(reverse=True)
    #l1.sort(reverse=True)
    print(solve())


"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""

import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect

from types import GeneratorType
BUFSIZE = 8192
class SortedList:
    def __init__(self, iterable=[], _load=200):
        """Initialize sorted list instance."""
        values = sorted(iterable)
        self._len = _len = len(values)
        self._load = _load
        self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
        self._list_lens = [len(_list) for _list in _lists]
        self._mins = [_list[0] for _list in _lists]
        self._fen_tree = []
        self._rebuild = True

    def _fen_build(self):
        """Build a fenwick tree instance."""
        self._fen_tree[:] = self._list_lens
        _fen_tree = self._fen_tree
        for i in range(len(_fen_tree)):
            if i | i + 1 < len(_fen_tree):
                _fen_tree[i | i + 1] += _fen_tree[i]
        self._rebuild = False

    def _fen_update(self, index, value):
        """Update `fen_tree[index] += value`."""
        if not self._rebuild:
            _fen_tree = self._fen_tree
            while index < len(_fen_tree):
                _fen_tree[index] += value
                index |= index + 1

    def _fen_query(self, end):
        """Return `sum(_fen_tree[:end])`."""
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        x = 0
        while end:
            x += _fen_tree[end - 1]
            end &= end - 1
        return x

    def _fen_findkth(self, k):
        """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
        _list_lens = self._list_lens
        if k < _list_lens[0]:
            return 0, k
        if k >= self._len - _list_lens[-1]:
            return len(_list_lens) - 1, k + _list_lens[-1] - self._len
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        idx = -1
        for d in reversed(range(len(_fen_tree).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                idx = right_idx
                k -= _fen_tree[idx]
        return idx + 1, k

    def _delete(self, pos, idx):
        """Delete value at the given `(pos, idx)`."""
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len -= 1
        self._fen_update(pos, -1)
        del _lists[pos][idx]
        _list_lens[pos] -= 1

        if _list_lens[pos]:
            _mins[pos] = _lists[pos][0]
        else:
            del _lists[pos]
            del _list_lens[pos]
            del _mins[pos]
            self._rebuild = True

    def _loc_left(self, value):
        """Return an index pair that corresponds to the first position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        lo, pos = -1, len(_lists) - 1
        while lo + 1 < pos:
            mi = (lo + pos) >> 1
            if value <= _mins[mi]:
                pos = mi
            else:
                lo = mi

        if pos and value <= _lists[pos - 1][-1]:
            pos -= 1

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value <= _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def _loc_right(self, value):
        """Return an index pair that corresponds to the last position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        pos, hi = 0, len(_lists)
        while pos + 1 < hi:
            mi = (pos + hi) >> 1
            if value < _mins[mi]:
                hi = mi
            else:
                pos = mi

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value < _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def add(self, value):
        """Add `value` to sorted list."""
        _load = self._load
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len += 1
        if _lists:
            pos, idx = self._loc_right(value)
            self._fen_update(pos, 1)
            _list = _lists[pos]
            _list.insert(idx, value)
            _list_lens[pos] += 1
            _mins[pos] = _list[0]
            if _load + _load < len(_list):
                _lists.insert(pos + 1, _list[_load:])
                _list_lens.insert(pos + 1, len(_list) - _load)
                _mins.insert(pos + 1, _list[_load])
                _list_lens[pos] = _load
                del _list[_load:]
                self._rebuild = True
        else:
            _lists.append([value])
            _mins.append(value)
            _list_lens.append(1)
            self._rebuild = True

    def discard(self, value):
        """Remove `value` from sorted list if it is a member."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_right(value)
            if idx and _lists[pos][idx - 1] == value:
                self._delete(pos, idx - 1)

    def remove(self, value):
        """Remove `value` from sorted list; `value` must be a member."""
        _len = self._len
        self.discard(value)
        if _len == self._len:
            raise ValueError('{0!r} not in list'.format(value))

    def pop(self, index=-1):
        """Remove and return value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        value = self._lists[pos][idx]
        self._delete(pos, idx)
        return value

    def bisect_left(self, value):
        """Return the first index to insert `value` in the sorted list."""
        pos, idx = self._loc_left(value)
        return self._fen_query(pos) + idx

    def bisect_right(self, value):
        """Return the last index to insert `value` in the sorted list."""
        pos, idx = self._loc_right(value)
        return self._fen_query(pos) + idx

    def count(self, value):
        """Return number of occurrences of `value` in the sorted list."""
        return self.bisect_right(value) - self.bisect_left(value)

    def __len__(self):
        """Return the size of the sorted list."""
        return self._len

    def __getitem__(self, index):
        """Lookup value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        return self._lists[pos][idx]

    def __delitem__(self, index):
        """Remove value at `index` from sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        self._delete(pos, idx)

    def __contains__(self, value):
        """Return true if `value` is an element of the sorted list."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_left(value)
            return idx < len(_lists[pos]) and _lists[pos][idx] == value
        return False

    def __iter__(self):
        """Return an iterator over the sorted list."""
        return (value for _list in self._lists for value in _list)

    def __reversed__(self):
        """Return a reverse iterator over the sorted list."""
        return (value for _list in reversed(self._lists) for value in reversed(_list))

    def __repr__(self):
        """Return string representation of sorted list."""
        return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import collections as col
import math, string

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

MOD = 10**9+7
#t=int(input())
t=1
p=10**9+7
def ncr_util():

    inv[0]=inv[1]=1
    fact[0]=fact[1]=1
    for i in range(2,300001):
        inv[i]=(inv[i%p]*(p-p//i))%p
    for i in range(1,300001):
        inv[i]=(inv[i-1]*inv[i])%p
        fact[i]=(fact[i-1]*i)%p

def solve():
    ans,ind=0,-1
    for i in range(len(l)):
        if l[i]>2 and l[i]%2!=0:
            ans=1
        if l[i]>2 and ind==-1:
            ind=i
    if ind==-1:
        return ans
    else:
        maxi=2*max(l)
        for i in range(ind,len(l)):
            m=2
            j=l[i]
            while j<=maxi:
                pos=bisect.bisect_right(l,j+l[i])
                pos-=1
                if pos<len(l):
                    ans=max(l[pos]%l[i],ans)
                #print(124,j,pos)
                j+=l[i]

    return ans
for _ in range(t):
    n=int(input())
    #n=int(input())
    #n,m=(map(int,input().split()))
    #n1=n
    #x=int(input())
    #b=int(input())
    #n,m,k=map(int,input().split())
    #l,r=map(int,input().split())
    #n=int(input())
    #s=input()
    #s1=input()
    #p=input()
    l=list(map(int,input().split()))
    l=list(set(l))
    l.sort()
    #l.sort()
    #l.sort(revrese=True)
    #l2=list(map(int,input().split()))
    #l=str(n)
    #l.sort(reverse=True)
    #l2.sort(reverse=True)
    #l1.sort(reverse=True)
    print(solve())


n = int(input())
a = sorted(list(set(map(int, input().split()))))
n = len(a)

lb = [0] + [-1] * 2000000
for x in a: lb[x] = x
for i in range(1,2000001):
  if (lb[i] == -1): lb[i] = lb[i-1]

ans = 0
for i in range(n):
  for j in range(2,2000000):
    if (a[i]*j > 1000000):
      ans = max(ans, a[-1] % a[i])
      break
    else: ans = max(ans, lb[j*a[i]-1] % a[i])
print(ans)


def lower_bound(a, x):
  lo, hi = 0, len(a)
  while (lo != hi - 1):
    mid = (lo + hi)//2
    if (a[mid] < x): lo = mid
    else: hi = mid
  return a[lo]

n = int(input())
a = sorted(list(set(map(int, input().split()))))
n = len(a)
ans = 0

for i in range(n):
  for j in range(2,1000000//a[i]+2):
    lb = lower_bound(a, j*a[i])
    if (lb >= a[i]): ans = max(ans, lb % a[i])
print(ans)


def lower_bound(a, x):
  lo, hi = 0, len(a)
  while (lo != hi - 1):
    mid = (lo + hi)//2
    if (a[mid] < x): lo = mid
    else: hi = mid
  return a[lo]

n = int(input())
a = sorted(list(set(map(int, input().split()))))
ans = 0

for i in range(n):
  for j in range(2,1000000//a[i]+2):
    lb = lower_bound(a, j*a[i])
    if (lb >= a[i]): ans = max(ans, lb % a[i])
print(ans)


n=int(input())
l=list(map(int,input().split(' ')))
l=list(set(l))
lb=[-1]*3000001
# print(l)
for i in l:
    lb[i+1]=i
for i in range(1,1000001):
    if(lb[i]==-1):
        lb[i]=lb[i-1]
ans=0
maxi=2*l[-1]
for i in l:
    x=i
    while x<=maxi:
        if lb[x+i]>=i:
            ans=max(ans,lb[x+i]%i)
        x+=i
print(ans)


#include<bits/stdc++.h>
using namespace std;
vector<char>v;
int main()
{
    long sz,i;
    string s;
    while(cin>>s)
    {
        v.clear();
        int c=0,k=0,pos=-1;
        sz=s.size();
        if(s[0]=='#'||s[sz-1]=='(')
        {
            cout<<-1<<endl;
            continue;
        }
        for(i=0; i<sz; i++)
        {
            if(s[i]=='(') v.push_back(s[i]);
            if(s[i]==')'||s[i]=='#')
            {
                if(s[i]=='#')
                {
                    c++;
                    pos=i+1;
                }
                if(v.empty())
                {
                    k=1;
                    break;
                }
                v.erase(v.begin());
            }
        }
        /*for(i=0;i<v.size();i++)
            cout<<v[i];
        cout<<endl;*/
        if(k==1||pos<v.size()) cout<<-1<<endl;
        else
        {
            for(i=1; i<c; i++) cout<<1<<endl;
            cout<<v.size()+1<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long sz,i,j,fir,se,he,p;
    string s;
    while(cin>>s)
    {
        long fir=0,se=0,he=0;
        sz=s.size();
        if(s[0]=='#')
        {
            cout<<-1<<endl;
            continue;
        }
        for(i=0; i<sz; i++)
        {
            if(s[i]=='(') fir++;
            if(s[i]==')') se++;
            if(s[i]=='#') he++;
        }
        if(fir==se)
            cout<<-1<<endl;
        else
        {
            if(fir-(se+he)<0)
            {
                cout<<-1<<endl;
                continue;
            }
            for(i=1;i<he;i++)
                cout<<1<<endl;
            cout<<fir-(se+he-1)<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long sz,i,j,fir,se,he,p,n,a[100005];
    string s;
    while(cin>>s)
    {
        long fir=0,se=0,he=0;
        sz=s.size();
        for(i=0; i<sz; i++)
        {
            if(s[i]=='(') fir++;
            if(s[i]==')') se++;
            if(s[i]=='#') he++;
        }
        if(fir==se||(he*2+se)<fir)
            cout<<-1<<endl;
        else
        {
            p=fir-se;
            if(he*2+se==fir)
                for(i=1; i<=he; i++)
                    cout<<2<<endl;
            else if(he+se==fir)
                for(i=1; i<=he; i++)
                    cout<<1<<endl;
            else
            {
                for(i=1; i<=he; i++)
                {
                    if(p>1)
                        a[i]=2;
                    if(p==1)
                        a[i]=1;
                    p=p-2;
                    if(p<0)
                        p=0;
                }
                for(i=he; i>=1; i--)
                {
                    if(a[i]==0)
                    {
                        a[i]=1;
                        a[he-i+1]=1;
                    }
                }
                for(i=1; i<=he; i++)
                    cout<<a[i]<<endl;
            }
        }
    }
    return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string str;

    cin>>str;

    int len=str.size();

    int count=0,ans=0,sp_count=0;

    for(int i=0;i<len;i++)
    {
        if(count-sp_count<0)
        {
            cout<<-1<<endl;
            return 0;
        }

        if(str[i]=='(')
            count++;
        else if(str[i]==')')
            count--;
        else
            sp_count++;
    }

   int new_count=0,k=0,temp=sp_count;
   while(1)
   {
    if(str[k++]=='#')
        temp--;
    if(temp==0)
        break;
   }

   for(int i=k;i<len;i++)
   {
    if(str[i]=='(')
            new_count++;
        else if(str[i]==')')
           new_count--;
   }
   if(new_count>0){
    cout<<-1<<endl;
        return 0;
   }

    if(str[len-1]=='(')
    {
        cout<<-1<<endl;
        return 0;
    }

    if(sp_count>count)
        cout<<-1<<endl;

    else
        {
            count = 0;

            for(int i=0;i<len;i++)
            {

                if(str[i]=='(')
                    count++;
                else
                    if(str[i]==')')
                        count--;

                else
                    if(sp_count>1)
                        {

                            cout<<1<<endl;
                            count--;
                            sp_count--;
                        }
            }

            if(sp_count)
                cout<<count<<endl;
        }
    return 0;
}


#include <iostream>
#include<string>
using namespace std;

int main()
{
    string str;
    cin>>str;
    int len=str.size();

    int count=0,sp_count=0,index=0;

    bool beautiful=true;

    for(int i=0;i<len;i++)
    {
        if(count-sp_count<0)
        {
            beautiful=false;
            break;
        }

        if(str[i]=='(')
            count++;
        else
            {
                if(str[i]=='#')
                {
                    sp_count++;
                    index=i;
                }

                count--;
            }
    }

    if(count<0)
        beautiful=false;
    else
    {
        int temp=0;

        for(int i=index+1;i<len;i++)
        {
            if(str[i]=='(')
            temp++;
            else temp--;
        }
        if(temp>0 ||str[len-1]=='(')
            beautiful=false;
    }

    if(beautiful==true)
    {
        for(int i=0;i<sp_count-1;i++)
        {
            cout<<1<<endl;
        }
        cout<<count+1<<endl;
    }

    else{
        cout<<-1<<endl;
    }

    return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string str;

    cin>>str;

    int len=str.size();

    int count=0,ans=0,sp_count=0;

    for(int i=0;i<len;i++)
    {
        if(count-sp_count<0)
        {
            cout<<-1<<endl;
            return 0;
        }

        if(str[i]=='(')
            count++;
        else if(str[i]==')')
            count--;
        else
            sp_count++;
    }

    if(sp_count>count)
        cout<<-1<<endl;

    else
        {
            count = 0;

            for(int i=0;i<len;i++)
            {

                if(str[i]=='(')
                    count++;
                else
                    if(str[i]==')')
                        count--;

                else
                    if(sp_count>1)
                        {

                            cout<<1<<endl;
                            count--;
                            sp_count--;
                        }
            }

            if(sp_count)
                cout<<count<<endl;
        }
    return 0;
}


#include <iostream>
#include<string>
using namespace std;

int main()
{
    string str;
    cin>>str;
    int len=str.size();

    int count=0,sp_count=0,index=0;

    bool beautiful=true;

    for(int i=0;i<len;i++)
    {
        if(sp_count+count<0)
        {
            beautiful=false;
            break;
        }

        if(str[i]=='(')
            count++;
        else
            {
                if(str[i]=='#')
                {
                    sp_count++;
                    index=i;
                }

                count--;
            }
    }

    if(count<0)
        beautiful=false;
    else
    {
        int temp=0;

        for(int i=index+1;i<len;i++)
        {
            if(str[i]=='(')
            temp++;
            else temp--;
        }
        if(temp>0 ||str[len-1]=='(')
            beautiful=false;
    }

    if(beautiful==true)
    {
        for(int i=0;i<sp_count-1;i++)
        {
            cout<<1<<endl;
        }
        cout<<count+1<<endl;
    }

    else{
        cout<<-1<<endl;
    }

    return 0;
}


#include <iostream>
#include<string>
using namespace std;

int main()
{
    string str;
    cin>>str;
    int len=str.size();

    int count=0,sp_count=0,index=0;

    bool beautiful=true;

    for(int i=0;i<len;i++)
    {
        if(count<0)
        {
            beautiful=false;
            break;
        }

        if(str[i]=='(')
            count++;
        else
            {
                if(str[i]=='#')
                {
                    sp_count++;
                    index=i;
                }

                count--;
            }
    }

    if(count<0)
        beautiful=false;
    else
    {
        int temp=0;

        for(int i=index+1;i<len;i++)
        {
            if(str[i]=='(')
            temp++;
            else temp--;
        }
        if(temp>0 ||str[len-1]=='(')
            beautiful=false;
    }

    if(beautiful==true)
    {
        for(int i=0;i<sp_count-1;i++)
        {
            cout<<1<<endl;
        }
        cout<<count+1<<endl;
    }

    else{
        cout<<-1<<endl;
    }

    return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string str;

    cin>>str;

    int len=str.size();

    int count=0,ans=0,sp_count=0;

    for(int i=0;i<len;i++)
    {
        if(count<0)
        {
            cout<<-1<<endl;
            return 0;
        }

        if(str[i]=='(')
            count++;
        else if(str[i]==')')
            count--;
        else
            sp_count++;
    }

    if(sp_count>count)
        cout<<-1<<endl;

    else
        {
            count = 0;

            for(int i=0;i<len;i++)
            {

                if(str[i]=='(')
                    count++;
                else
                    if(str[i]==')')
                        count--;

                else
                    if(sp_count>1)
                        {

                            cout<<1<<endl;
                            count--;
                            sp_count--;
                        }
            }

            if(sp_count)
                cout<<count<<endl;
        }
    return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string str;

    cin>>str;

    int len=str.size();

    int count=0,ans=0,sp_count=0;

    for(int i=0;i<len;i++)
    {
        if(count-sp_count<0)
        {
            cout<<-1<<endl;
            return 0;
        }

        if(str[i]=='(')
            count++;
        else if(str[i]==')')
            count--;
        else
            sp_count++;
    }

    if(str[len-1]=='(')
    {
        cout<<-1<<endl;
        return 0;
    }

    if(sp_count>count)
        cout<<-1<<endl;

    else
        {
            count = 0;

            for(int i=0;i<len;i++)
            {

                if(str[i]=='(')
                    count++;
                else
                    if(str[i]==')')
                        count--;

                else
                    if(sp_count>1)
                        {

                            cout<<1<<endl;
                            count--;
                            sp_count--;
                        }
            }

            if(sp_count)
                cout<<count<<endl;
        }
    return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string str;

    cin>>str;

    int len=str.size();

    int count=0,ans=0,sp_count=0;

    for(int i=0;i<len;i++)
    {
        if(count-sp_count<0)
        {
            cout<<-1<<endl;
            return 0;
        }

        if(str[i]=='(')
            count++;
        else if(str[i]==')')
            count--;
        else
            sp_count++;
    }

   int new_count=0,k=0,temp=sp_count;
   while(1)
   {
    if(str[k++]=='#')
        temp--;
    if(temp==0)
        break;
   }

   for(int i=k;i<len;i++)
   {
    if(str[i]=='(')
            count++;
        else if(str[i]==')')
            count--;
   }
   if(count>0){
    cout<<-1<<endl;
        return 0;
   }

    if(str[len-1]=='(')
    {
        cout<<-1<<endl;
        return 0;
    }

    if(sp_count>count)
        cout<<-1<<endl;

    else
        {
            count = 0;

            for(int i=0;i<len;i++)
            {

                if(str[i]=='(')
                    count++;
                else
                    if(str[i]==')')
                        count--;

                else
                    if(sp_count>1)
                        {

                            cout<<1<<endl;
                            count--;
                            sp_count--;
                        }
            }

            if(sp_count)
                cout<<count<<endl;
        }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s)) //LASTBIT
#define EPS 1e-7
#define PI  3.1415926535897932384626433832795028841971693993
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second

//////////////////////
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
//////////////////////

const int N = 1000010;

string s;
ll ans[N];

int main()
{
	ios::sync_with_stdio(0);
	cin >> s;
	int n = 0;
	ll foo = 0;
	int uit = -1;
	for(int i=0;i<s.size();++i)
	{
		if( s[i] == '(' ) foo++;
		else if(s[i]=='#')
		{
			uit = i;
			if(foo==0)
			{
				cout << "-1\n";
				return 0;
			}
			else
			{
				ans[n++] = 1;
				foo--;
			}
		}
		else foo--;
		if(foo<0)
		{
			cout << "-1\n";
			return 0;
		}
	}
	if(uit!=-1)
	{
		int cnt = 0;
		for(int i=s.size()-1;i>uit;--i)
		{

			if(s[i]=='(') cnt++;
			else cnt--;
			if(cnt>0)
			{
				cout << "-1\n";
				return 0;
			}
		}
	}
	ans[n-1] += foo;
	for(int i=0;i<n;++i) cout << ans[i] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s)) //LASTBIT
#define EPS 1e-7
#define PI  3.1415926535897932384626433832795028841971693993
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second

//////////////////////
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
//////////////////////

const int N = 1000010;

string s;
ll ans[N];

int main()
{
    ios::sync_with_stdio(0);
    cin >> s;
    int n = 0;
    ll foo = 0;
    for(int i=0;i<s.size();++i)
    {

        if( s[i] == '(' ) foo++;
        else if(s[i]=='#')
        {
            if(foo==0)
            {
                cout << "-1\n";
                return 0;
            }
            else
            {
                ans[n++] = 1;
                foo--;
            }
        }
        else foo--;
        if(foo<0)
        {
            cout << "-1\n";
            return 0;
        }
    }
    ans[n-1] += foo;
    for(int i=0;i<n;++i)
    {
        cout << ans[i] << endl;
    }
    return 0;
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s)) //LASTBIT
#define EPS 1e-7
#define PI  3.1415926535897932384626433832795028841971693993
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second

//////////////////////
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
//////////////////////

const int N = 1000010;

string s;
ll ans[N];

int main()
{
    ios::sync_with_stdio(0);
    cin >> s;
    int n = 0;
    ll foo = 0;
    int uit = -1;
    for(int i=0;i<s.size();++i)
    {
        if( s[i] == '(' ) foo++;
        else if(s[i]=='#')
        {
            uit = i;
            if(foo==0)
            {
                cout << "-1\n";
                return 0;
            }
            else
            {
                ans[n++] = 1;
                foo--;
            }
        }
        else foo--;
        if(foo<0)
        {
            cout << "-1\n";
            return 0;
        }
    }
    if(uit!=-1)
    {
        int cnt = 0;
        for(int i=s.size()-1;i>uit;--i)
        {

            if(s[i]=='(') cnt++;
            else cnt--;
            if(cnt>0)
            {
                cout << "-1\n";
                return 0;
            }
        }
    }

    ans[n-1] += foo;
    for(int i=0;i<n;++i) cout << ans[i] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s)) //LASTBIT
#define EPS 1e-7
#define PI  3.1415926535897932384626433832795028841971693993
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second

//////////////////////
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
//////////////////////

const int N = 1000010;

string s;
ll ans[N];

int main()
{
	ios::sync_with_stdio(0);
	cin >> s;
	int n = 0;
	ll foo = 0;
	int uit = -1;
	for(int i=0;i<s.size();++i)
	{

		if( s[i] == '(' ) foo++;
		else if(s[i]=='#')
		{
			uit = i;
			if(foo==0)
			{
				cout << "-1\n";
				return 0;
			}
			else
			{
				ans[n++] = 1;
				foo--;
			}
		}
		else foo--;
		if(foo<0)
		{
			cout << "-1\n";
			return 0;
		}
	}
	if(uit!=-1)
	{
		int cnt = 0;
		for(int i=uit+1;i<s.size();++i)
		{
			if(s[i]=='(') cnt++;
			else
			{
				if(cnt==0)
				{
					cout << "-1\n";
					return 0;
				}
				else cnt--;
			}
		}
		if(cnt!=0)
		{
			cout << "-1\n";
			return 0;
		}
	}
	ans[n-1] += foo;
	for(int i=0;i<n;++i) cout << ans[i] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3F3F3F3F3FLL
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define LSONE(s) ((s)&(-s)) //LASTBIT
#define EPS 1e-7
#define PI  3.1415926535897932384626433832795028841971693993
#define DEG_to_RAD(X)   (X * PI / 180)
#define F first
#define S second

//////////////////////
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
//////////////////////

const int N = 1000010;

string s;
ll ans[N];

int main()
{
	ios::sync_with_stdio(0);
	cin >> s;
	int n = 0;
	ll foo = 0;
	for(int i=0;i<s.size();++i)
	{
		if(s[i]=='#')
		{
			if(foo==0)
			{
				cout << "-1\n";
				return 0;
			}
			else
			{
				ans[n++] = foo;
				foo = 0;
			}
		}
		else if(s[i]=='(') foo++;
		else
		{
			if(foo==0)
			{
				if(n==0)
				{
					cout << "-1\n";
					return 0;
				}
				else
				{
					if(ans[n-1]==0)
					{
						cout << "-1\n";
						return 0;
					}
					else
					{
						ans[n-1]--;
						if(ans[n-1]==0)
						{
							cout << "-1\n";
							return 0;
						}
					}
				}
			}
			else foo--;
		}
	}
	for(int i=0;i<n;++i)
	{
		cout << ans[i] << endl;
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define INF 1000000001
#define MAXN 1111111
#define MAXM 400005
using namespace std;
char s[111111];
vector<int>g, ans;
int main() {
    scanf("%s", s);
    int len = strlen(s);
    int lst = -1, l = 0, r = 0;
    int flag = 1;
    int num = 0;
    for(int i = 0; i < len; i++)
        if(s[i] == '#') num++;
    int now = 0, tk = 0;
    for(int i = 0; i < len; i++) {
        if(l < r) {
            flag = 0;
            break;
        }

        if(s[i] == '#') {
            if(l == r) {
                flag = 0;
                break;
            }
            now++;
            if(now < num) {
                ans.push_back(1);
                s[i] = ')';
                r++;
            } else {
                lst = i;
            }
            continue;
        }
        if(s[i] == '(') {
            l++;
        } else {
            r++;
        }
        if(l < r) flag = 0;
    }
    int k = l - r;
    l = 0, r = 0;
    if(k <= 0 && lst >= 0) flag = 0;
    for(int i = 0; i < len; i++) {
        if(i == lst) {
            r += k;
            ans.push_back(k);
        } else {
            if(s[i] == ')') r++;
            else l++;
        }
        if(l < r) flag = 0;
    }
    if(!flag || l != r) puts("-1");
    else {
        for(int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define INF 1000000001
#define MAXN 1111111
#define MAXM 400005
using namespace std;
char s[111111];
vector<int>g, ans;
int main() {
    scanf("%s", s);
    int len = strlen(s);
    int pre = -1, l = 0, r = 0;
    int flag = 1;
    for(int i = 0; i < len; i++) {
        if(s[i] == '#') {
            g.push_back(i);
            continue;
        }
        if(s[i] == '(') {
            if(g.size() > 0) {
                int k = l - r;
                if(k < g.size()) {
                    flag = 0;
                    break;
                }
                for(int j = 0; j < g.size() - 1; j++) {
                    ans.push_back(1);
                }
                ans.push_back(k - (g.size() - 1));
                g.clear();
                r += k;
            }
            l++;
        } else {
            r++;
        }
        if(l < r) flag = 0;
    }
    if(g.size() > 0) {
        int k = l - r;
        if(k < g.size()) {
            flag = 0;
        }
        for(int j = 0; j < g.size() - 1; j++) {
            ans.push_back(1);
        }
        ans.push_back(k - (g.size() - 1));
        g.clear();
        r += k;
    }
    if(!flag) puts("-1");
    else {
        for(int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define INF 1000000001
#define MAXN 1111111
#define MAXM 400005
using namespace std;
char s[111111];
vector<int>g, ans;
int main() {
    scanf("%s", s);
    int len = strlen(s);
    int lst = 0, l = 0, r = 0;
    int flag = 1;
    int num = 0;
    for(int i = 0; i < len; i++)
        if(s[i] == '#') num++;
    int now = 0, tk = 0;
    for(int i = 0; i < len; i++) {
        if(l < r) {
            flag = 0;
            break;
        }

        if(s[i] == '#') {
            if(l == r) {
                flag = 0;
                break;
            }
            now++;
            if(now < num) {
                ans.push_back(1);
                r++;
            } else {
                lst = 1;
            }
            continue;
        }
        if(s[i] == '(') {
            if(lst == 1) {
                lst = -1;
                ans.push_back(l - r);
                if(l <= r) flag = 0;
                r = l;
            }
            l++;
        } else {
            r++;
        }
        if(l < r) flag = 0;
    }

    if(lst == 1) {
        lst = -1;
        ans.push_back(l - r);
        if(l <= r) flag = 0;
        r = l;
    }
    if(!flag || l != r) puts("-1");
    else {
        for(int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define INF 1000000001
#define MAXN 1111111
#define MAXM 400005
using namespace std;
char s[111111];
vector<int>g, ans;
int main() {
    scanf("%s", s);
    int len = strlen(s);
    int pre = -1, l = 0, r = 0;
    int flag = 1;
    int num = 0;
    for(int i = 0; i < len; i++)
        if(s[i] == '#') num++;
    int now = 0, tk = 0;
    for(int i = 0; i < len; i++) {
        if(l < r) {
            flag = 0;
            break;
        }
        if(s[i] == '#') {
            if(l == r) {
                flag = 0;
                break;
            }
            now++;
            if(now < num) {
                ans.push_back(1);
                tk += l - r - 1;
                r++;
            } else {
                ans.push_back(tk);
                r += tk;
            }
            continue;
        }
        if(s[i] == '(') {
            l++;
        } else {
            r++;
        }
        if(l < r) flag = 0;
    }

    if(!flag || l != r) puts("-1");
    else {
        for(int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define INF 1000000001
#define MAXN 1111111
#define MAXM 400005
using namespace std;
char s[111111];
vector<int>g, ans;
int main() {
    scanf("%s", s);
    int len = strlen(s);
    int pre = -1, l = 0, r = 0;
    int flag = 1;
    for(int i = 0; i < len; i++) {
        if(s[i] == '#') {
            g.push_back(i);
            continue;
        }
        if(s[i] == '(') {
            if(g.size() > 0) {
                int k = l - r;
                if(k < g.size()) {
                    flag = 0;
                    break;
                }
                for(int j = 0; j < g.size() - 1; j++) {
                    ans.push_back(1);
                }
                ans.push_back(k - (g.size() - 1));
                g.clear();
                r += k;
            }
            l++;
        } else {
            r++;
        }
    }
    if(g.size() > 0) {
        int k = l - r;
        if(k < g.size()) {
            flag = 0;
        }
        for(int j = 0; j < g.size() - 1; j++) {
            ans.push_back(1);
        }
        ans.push_back(k - (g.size() - 1));
        g.clear();
        r += k;
    }
    if(!flag) puts("-1");
    else {
        for(int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define INF 1000000001
#define MAXN 1111111
#define MAXM 400005
using namespace std;
char s[111111];
vector<int>g, ans;
int main() {
    scanf("%s", s);
    int len = strlen(s);
    int pre = -1, l = 0, r = 0;
    int flag = 1;
    for(int i = 0; i < len; i++) {
        if(l < r) flag = 0;
        if(s[i] == '#') {
            g.push_back(i);
            continue;
        }
        if(s[i] == '(') {
            if(g.size() > 0) {
                int k = l - r;
                if(k < g.size()) {
                    flag = 0;
                    break;
                }
                for(int j = 0; j < g.size() - 1; j++) {
                    ans.push_back(1);
                }
                ans.push_back(k - (g.size() - 1));
                g.clear();
                r += k;
            }
            l++;
        } else {
            r++;
        }
        if(l < r) flag = 0;
    }
    if(g.size() > 0) {
        int k = l - r;
        if(k < g.size()) {
            flag = 0;
        }
        for(int j = 0; j < g.size() - 1; j++) {
            ans.push_back(1);
        }
        ans.push_back(k - (g.size() - 1));
        g.clear();
        r += k;
    }
    if(!flag || l != r) puts("-1");
    else {
        for(int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define INF 1000000001
#define MAXN 1111111
#define MAXM 400005
using namespace std;
char s[111111];
vector<int>g, ans;
int main() {
    scanf("%s", s);
    int len = strlen(s);
    int pre = -1, l = 0, r = 0;
    int flag = 1;
    int num = 0;
    for(int i = 0; i < len; i++)
        if(s[i] == '#') num++;
    int now = 0, tk = 0;
    for(int i = 0; i < len; i++) {
        if(l < r) {
            flag = 0;
            break;
        }
        if(s[i] == '#') {
            if(l == r) {
                flag = 0;
                break;
            }
            now++;
            if(now < num) {
                ans.push_back(1);
                r++;
            } else {
                ans.push_back(l - r);
                r = l;
            }
            continue;
        }
        if(s[i] == '(') {
            l++;
        } else {
            r++;
        }
        if(l < r) flag = 0;
    }

    if(!flag || l != r) puts("-1");
    else {
        for(int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int n,say;
char A[100005];
int main()
{
    scanf("%s",A);
    n = strlen(A);
    for (int i = 0; i < n ; i++)
    {
        if(A[i] == '(')say++;
        else if(A[i] == ')')say--;
        else if(A[i] == '#')
        {
            for(int j=i+1 ; j<n ; j++)
            {
                if(A[j] == ')')say--;
                else
                {i=j-1; break;}
            }
            if(say == 0)printf("-1\n");
            else printf("%d\n",say);
            say = 0;
        }
    }

}


#include <stdio.h>
#include <string.h>
int n,say;
char A[100005];
int main()
{
    scanf("%s",A);
    n = strlen(A);
    for (int i = 0; i < n ; i++)
    {
        if(A[i] == '(')say++;
        else if(A[i] == ')')say--;
        else if(A[i] == '#')
        {
            for(int j=i+1 ; j<n ; j++)
            {
                if(A[j] == ')')say--;
                else
                {i=j-1; break;}
            }
            if(say <= 0)
            {
                printf("-1\n");
                say = 0;
            }
            else printf("%d\n",say);
            say = 0;
        }
    }

}


#include <stdio.h>                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
#include <string.h>                                      //asdasdasdasdasdasdasdasdasdasdssdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
int n,s,fl,a,b,c,d,e,f=1;                                //asdasdasdasdasdasdasdasdasdasdaasddsasdasdasdhjkasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
char A[100005];                                          //asdasdasdasdasdasdasdasdasdasdassaddsaassdasdasdasaty7uf55sasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
int main()                                               //asdasdasdasdasdasdasdasdasdasdasdasdasdadsdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
{                                                        //fhasdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    scanf("%s",A);                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    n = strlen(A);                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasdadasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    if(A[0] == '#' || A[n-1] == '(' || A[0] == ')')f=0;  //asdasdasdasdasdasdasdasdasdasdasdasdasasdasdassasasasasasasdasdasdsdadasdadasdadaadasdadasdshjkdasdadasdasdsdsadasdasd
    for (int i = 0; i < n ; i++)                        //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasacsasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    {                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasaaaasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '('){a++;s++;d++;}                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasssdasddasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == ')')                                  //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasassdaasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        {                                                //asdasdasdasdasdasdasdasdasdasdassdadasdasdasdasdasasasasasaasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            if(d<1)f=0;                                  //asdasdasdasdasdasdasdaasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            if(s)                                        //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdahjdasdsdasdadasdasdsdsadasdasd
            {                                            //asdasdasdasdasdasdasdasdasdasdasdasdasdasdajhsasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
                b++;s--;d--;                             //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdahdasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            }                                            //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadgkf7f865asdasd
            else f=0;                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        }                                                //asdasdasdasdasdasdasdasdasdasdasdasdasdasdaasdadsrasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '#')                                  //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        {                                                //asdasdasdasdasdasdasdasdasdasddaasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            if(s == 0)f=0;                               //asdasdasdasdasdasdasdasadsdasasdasdasdasdasdasdasasasasasasahsdasdasdsdadasdadkasdadaadasdadasdsdasdadasdasdsdsadasdasd
            c++;d--;s--;                                 //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        }                                                //asdasdasdasdasdasdasdasdasdasdasdasafassdasdasdasdagyuhktuyvsasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    }                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    for(int i=n-1 ; i>=0 ; i--)                         //asdasdasdasdasdasdasdasdaasdadsdasdasdasdasdasdasasasasassdfsasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    {                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasassasdaxdazsaddasdsasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '#')break;                           //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasassasdaxdazasdasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '(')fl++;                             //asdasdasdasdasdasdasdasdasdasdasdasdasdasasdadasasasasasasasdasdasdasdsdadasudadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        else fl--;                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasdsasasasasasdasdjnasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    }                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasgvyh6tasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    if(b+c > a || fl > 0 || f == 0)printf("-1");         //asdasdasdasdasdasdaadasasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    else                                                 //asdasdasdasdasdasdasdasdasdasdasdasdadasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    {                                                    //as1000111-989dasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        a = a-b;                                         //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        while(c > 1)                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        {                                                //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            printf("1\n");                               //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            a--;c--;                                     //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        }
        printf("%d\n",a);
    }
}


#include <stdio.h>                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
#include <string.h>                                      //asdasdasdasdasdasdasdasdasdasdssdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
int n,s,fl,a,b,c,d,e,f=1;                                //asdasdasdasdasdasdasdasdasdasdaasddsasdasdasdhjkasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
char A[100005];                                          //asdasdasdasdasdasdasdasdasdasdassaddsaassdasdasdasaty7uf55sasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
int main()                                               //asdasdasdasdasdasdasdasdasdasdasdasdasdadsdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
{                                                        //fhasdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    scanf("%s",A);                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    n = strlen(A);                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasdadasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    if(A[0] == '#' || A[n-1] == '(' || A[0] == ')')f=0;  //asdasdasdasdasdasdasdasdasdasdasdasdasasdasdassasasasasasasdasdasdsdadasdadasdadaadasdadasdshjkdasdadasdasdsdsadasdasd
    for (int i = 0; i < n ; i++)                        //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasacsasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    {                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasaaaasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '('){a++;s++;d++;}                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasssdasddasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == ')')                                  //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasassdaasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        {                                                //asdasdasdasdasdasdasdasdasdasdassdadasdasdasdasdasasasasasaasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            if(d<1)f=0;                                  //asdasdasdasdasdasdasdaasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            if(s)                                        //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdahjdasdsdasdadasdasdsdsadasdasd
            {                                            //asdasdasdasdasdasdasdasdasdasdasdasdasdasdajhsasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
                b++;s--;d--;                             //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdahdasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            }                                            //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadgkf7f865asdasd
            else f=0;                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        }                                                //asdasdasdasdasdasdasdasdasdasdasdasdasdasdaasdadsrasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '#')                                  //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        {                                                //asdasdasdasdasdasdasdasdasdasddaasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            if(s == 0)f=0;                               //asdasdasdasdasdasdasdasadsdasasdasdasdasdasdasdasasasasasasahsdasdasdsdadasdadkasdadaadasdadasdsdasdadasdasdsdsadasdasd
            c++;d--;s--;                                 //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        }                                                //asdasdasdasdasdasdasdasdasdasdasdasafassdasdasdasdagyuhktuyvsasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    }                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    for(int i=n-1 ; i>=0 ; i--)                         //asdasdasdasdasdasdasdasdaasdadsdasdasdasdasdasdasasasasassdfsasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    {                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasassasdaxdazsaddasdsasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '#')break;                           //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasassasdaxdazasdasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        if(A[i] == '(')fl++;                             //asdasdasdasdasdasdasdasdasdasdasdasdasdasasdadasasasasasasasdasdasdasdsdadasudadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        else fl--;                                       //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasdsasasasasasdasdjnasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    }                                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasgvyh6tasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    if(b+c > a || fl > 0 || f == 0)printf("-1");         //asdasdasdasdasdasdaadasasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    else                                                 //asdasdasdasdasdasdasdasdasdasdasdasdadasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
    {                                                    //as1000111-989dasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        a = a-b;                                         //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        while(c > 1)                                    //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        {                                                //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            printf("1\n");                               //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
            a--;c--;                                     //asdasdasdasdasdasdasdasdasdasdasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        }                                                //asdasdasdasdasdasdasdasdasasdasddasddasdsaasdasdasdasdasasasasasasasdasdasdsdadasdadasdadaadasdadasdsdasdadasdasdsdsadasdasd
        printf("%d\n",a);                               //asdasdasdadadsasdadadsadsdadadadadsadaasdaaaasdadadasdasdasdadadasdadsdasdasaasasasasasasjoldasdsadasdasdasdasdassddadasda
    }                                                   //asdasdas
Malek has recently foudadadsasdadadsadsdadadadadsadaadaaaasdadasdasdadadasdadsdasdasaasasasasasasdasdsadasdasdasdasdassddadasda
}                                                       //asdasdasdadadsasdadadsadsdadadadadsadaasdaaaasdadasdasdadadasdadsdasdasaasasasasasasdasdsadasdasdasdasdassddadasda
                                                        //asdasdasdadadsasdadadsadsdadadadadsadaaasssadsdsaasdadasdasdadadasdadsdasdasaasasasasasasdasdsadasdasdasdasdassddadasda
                                                        //asdasdasdadadsasdadadsadsdadadadadsadaasdsaasdaasdadasdasdadadasdadsdasdasaasasasasasasdasdsadasdasdasdasdassddadasda
                                                        //asdasdasdadadsasdadadsadsdadadadadsadadsadaaaaaasdadasdasdadadasdadsdasdasaasasasasasasdasdsadasdasdasdasdujassddadasda
                                                        //asdasdasdadadsasdadadsadsdadadadadsadaaaaaasdadasdasdadadasdadsdasdasaasasasasasasdasdsadasdasdasdasdassddadasda


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;
stack<char> s;
char v[100005];
int num = 0;
int ans[100005];
int main()
{
	cin >> v;
	if (v[0] == ')' || v[0] == '#')
	{
		cout << "-1" << endl;
		return 0;
	}
	int len = strlen(v);
	int n1 = 0,n2 = 0;
	for (int i = 0; i < len; i++)
	{
		if (v[i] == '(')
		{
			s.push(v[i]);
			n1++;
		}
		if (v[i] == ')')
		{
			s.pop();
			n1--;
		}
		if (v[i] == '#')
		{
			int j;
			for (j = i + 1; j < len; j++)
			{
				if (v[j] == '#')
				{
					ans[num++] = 1;
					n1--;
					break;
				}
			}
			if (j == len)
			{
				for (j = i + 1; j < len; j++)
				{
					if (v[j] == '(')
						n1++;
					else
						n1--;
				}
				ans[num++] = n1;
				break;
			}
		}
	}
	for (int i = len - 1; i >= 0; i--)
	{
		if (v[i] != '#')
		{
			if (v[i] == ')')
				n2++;
			else
				n2--;
		}
		else
			break;
	}
	if (n1 <= 0 || n2 < 0)
	{
		cout << "-1" << endl;
	}
	else
	{
		for (int i = 0; i < num; i++)
		{
			cout << ans[i] << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;
stack<char> s;
char v[100005];
int num = 0;
int ans[100005];
int main()
{
	cin >> v;
	if (v[0] == ')' || v[0] == '#' || v[len - 1] == '(')
	{
		cout << "-1" << endl;
		return 0;
	}
	int len = strlen(v);
	int n1 = 0,n2 = 0;
	for (int i = 0; i < len; i++)
	{
		if (v[i] == '(')
		{
			s.push(v[i]);
			n1++;
		}
		if (v[i] == ')')
		{
			s.pop();
			n1--;
		}
		if (v[i] == '#')
		{
			int j;
			for (j = i + 1; j < len; j++)
			{
				if (v[j] == '#')
				{
					ans[num++] = 1;
					n1--;
					break;
				}
			}
			if (j == len)
			{
				for (j = i + 1; j < len; j++)
				{
					if (v[j] == '(')
						n1++;
					else
						n1--;
				}
				ans[num++] = n1;
				break;
			}
		}
	}
	for (int i = len - 1; i >= 0; i--)
	{
		if (v[i] != '#')
		{
			if (v[i] == ')')
				n2++;
			else
				n2--;
		}
		else
			break;
	}
	if (n1 <= 0 || n2 < 0)
	{
		cout << "-1" << endl;
	}
	else
	{
		for (int i = 0; i < num; i++)
		{
			cout << ans[i] << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;
stack<char> s;
char v[100005];
int num = 0;
int ans[100005];
int main()
{
	cin >> v;
	if (v[0] == ')' || v[0] == '#')
	{
		cout << "-1" << endl;
		return 0;
	}
	int len = strlen(v);
	int n1 = 0,n2 = 0;
	for (int i = 0; i < len; i++)
	{
		if (v[i] == '(')
		{
			s.push(v[i]);
			n1++;
		}
		if (v[i] == ')')
		{
			s.pop();
			n1--;
		}
		if (v[i] == '#')
		{
			int j;
			for (j = i + 1; j < len; j++)
			{
				if (v[j] == '#')
				{
					ans[num++] = 1;
					n1--;
					break;
				}
			}
			if (j == len)
			{
				for (j = i + 1; j < len; j++)
				{
					if (v[j] == '(')
						n1++;
					else
						n1--;
				}
				ans[num++] = n1;
				break;
			}
		}
	}
	for (int i = len - 1; i >= 0; i--)
	{
		if (v[i] != '#')
		{
			if (v[i] == ')')
				n2++;
			else
				n2--;
		}
		else
			break;
	}
	if (n1 <= 0 || n2 <= 0)
	{
		cout << "-1" << endl;
	}
	else
	{
		for (int i = 0; i < num; i++)
		{
			cout << ans[i] << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;
stack<char> s;
char v[100005];
int num = 0;
int ans[100005];
int main()
{
	cin >> v;
	int len = strlen(v);
	if (v[0] == ')' || v[0] == '#' || v[len - 1] == '(')
	{
		cout << "-1" << endl;
		return 0;
	}
	int n1 = 0,n2 = 0;
	for (int i = 0; i < len; i++)
	{
		if (v[i] == '(')
		{
			s.push(v[i]);
			n1++;
		}
		if (v[i] == ')')
		{
			s.pop();
			n1--;
		}
		if (v[i] == '#')
		{
			int j;
			for (j = i + 1; j < len; j++)
			{
				if (v[j] == '#')
				{
					ans[num++] = 1;
					n1--;
					break;
				}
			}
			if (j == len)
			{
				for (j = i + 1; j < len; j++)
				{
					if (v[j] == '(')
						n1++;
					else
						n1--;
				}
				ans[num++] = n1;
				break;
			}
		}
		if (n1 < 0)
		{
			cout << "-1" << endl;
			return 0;
		}
	}
	for (int i = len - 1; i >= 0; i--)
	{
		if (v[i] != '#')
		{
			if (v[i] == ')')
				n2++;
			else
				n2--;
		}
		else
			break;
	}
	if (n1 <= 0 || n2 < 0)
	{
		cout << "-1" << endl;
	}
	else
	{
		for (int i = 0; i < num; i++)
		{
			cout << ans[i] << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;
stack<char> s;
char v[100005];
int num = 0;
int ans[100005];
int main()
{
	cin >> v;
	int len = strlen(v);
	if (v[0] == ')' || v[0] == '#' || v[len - 1] == '(')
	{
		cout << "-1" << endl;
		return 0;
	}
	int n1 = 0,n2 = 0;
	for (int i = 0; i < len; i++)
	{
		if (v[i] == '(')
		{
			s.push(v[i]);
			n1++;
		}
		if (v[i] == ')')
		{
			s.pop();
			n1--;
		}
		if (v[i] == '#')
		{
			int j;
			for (j = i + 1; j < len; j++)
			{
				if (v[j] == '#')
				{
					ans[num++] = 1;
					n1--;
					break;
				}
			}
			if (j == len)
			{
				for (j = i + 1; j < len; j++)
				{
					if (v[j] == '(')
						n1++;
					else
						n1--;
				}
				ans[num++] = n1;
				break;
			}
		}
	}
	for (int i = len - 1; i >= 0; i--)
	{
		if (v[i] != '#')
		{
			if (v[i] == ')')
				n2++;
			else
				n2--;
		}
		else
			break;
	}
	if (n1 <= 0 || n2 < 0)
	{
		cout << "-1" << endl;
	}
	else
	{
		for (int i = 0; i < num; i++)
		{
			cout << ans[i] << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;
stack<char> s;
char v[100005];
int num = 0;
int ans[100005];
int main()
{
	cin >> v;
	if (v[0] == ')' || v[0] == '#')
	{
		cout << "-1" << endl;
		return 0;
	}
	int len = strlen(v);
	int n1 = 0,n2 = 0;
	for (int i = 0; i < len; i++)
	{
		if (v[i] == '(')
		{
			s.push(v[i]);
			n1++;
		}
		if (v[i] == ')')
		{
			s.pop();
			n1--;
		}
		if (v[i] == '#')
		{
			int j;
			for (j = i + 1; j < len; j++)
			{
				if (v[j] == '#')
				{
					ans[num++] = 1;
					n1--;
					break;
				}
			}
			if (j == len)
			{
				for (j = i + 1; j < len; j++)
				{
					if (v[j] == '(')
						n1++;
					else
						n1--;
				}
				ans[num++] = n1;
				break;
			}
		}
	}
	if (n1 <= 0)
	{
		cout << "-1" << endl;
	}
	else
	{
		for (int i = 0; i < num; i++)
		{
			cout << ans[i] << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<string.h>
using namespace std;
stack<char> s;
char v[100005];
int num = 0;
int ans[100005];
int main()
{
	cin >> v;
	if (v[0] == ')' || v[0] == '#')
	{
		cout << "-1" << endl;
		return 0;
	}
	int len = strlen(v);
	int n1 = 0,n2 = 0;
	for (int i = 0; i < len; i++)
	{
		if (v[i] == '(')
		{
			s.push(v[i]);
			n1++;
		}
		if (v[i] == ')')
		{
			s.pop();
			n1--;
		}
		if (v[i] == '#')
		{
			int j;
			for (j = i + 1; j < len; j++)
			{
				if (v[j] == '#')
				{
					ans[num++] = 1;
					n1--;
					break;
				}
			}
			if (j == len)
			{
				for (int j = i + 1; j < len; j++)
				{
					if (v[j] == '(')
						n1++;
					else
						n1--;
				}
				ans[num++] = n1;
			}
		}
	}
	if (n1 <= 0)
	{
		cout << "-1" << endl;
	}
	else
	{
		for (int i = 0; i < num; i++)
		{
			cout << ans[i] << endl;
		}
	}
	return 0;
}


///....................SUBRATO MOLLICK....................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///........................BETCH-10.......................///
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define REP2(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define INF (1<<30)
#define PI 3.14159265358979323846264338327950
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ size()
#define eps 1e-9
#define VI vector<int>
#define VS vector<string>
#define LL long long
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define CLEAR(x) memset(x,0,sizeof(x));
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define all(x) x.begin(),x.end()

/*long long c[201]={0};
bool p[205]={0};
void sieve()
{
   long long i,j;
    j=4;
     while(j<=201)
     {
         p[j]=1;
         j+=2;
     }
     long k=1;
     for(i=3;i<=(201);i+=2)
     {
        if(p[i]==0)
        {
            j=i;
            while(j+i<=201)
            {
                p[j+i]=1;j+=i;
            }
            if(p[i+2]==0)
            c[k++]=i;
        }
    }
}*/
/*long long npr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   ret*=(n-i+1);
   return ret;
}*/
/*long long ncr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   {
       ret*=(n-i+1);
       ret/=i;
   }
   return ret;
}*/
/*long long fact(long n)
{
    long long ret=1,i;
    for(i=1;i<=n;i++)
    ret*=i;
    return ret;
}*/
/*long long gcd(long n,long m)
{
  while(m>0)
  {
    n=n%m;
    n=n^m;
    m=m^n;
    n=n^m;
  }
  return n;
}*/
/*long long lcm(long n,long m)
{
    long long x=(n*m)/gcd(n,m);
    return x;
}*/
/*long is_prime(long n)
{
	long long ii;
	if(n == 1)
	return 0;
	if(n == 2)
	return 1;
	if(n%2 == 0)
	return 0;
	for(ii=3;ii*ii<=n;ii=ii+2)
        if(n%ii == 0)
        return 0;
        return 1;
}*/
/*double area_triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double a;
    a=x1*(y2-y3)+y1*(x3-x2)+((x2*y3)-(y2*x3))+eps;
    a=a/2+eps;
    return a;
}*/
/*double dist_2point(double x1,double y1,double x2,double y2)
{
    double d;
    d=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
    return d;
}*/
/*int binary_search(int a[],int n,int l,int u)
{
	int mid;
	if(l>u)
    return 0;
    mid=floor(l+u)/2;
    if(a[mid]==n)
    return mid;
    else if(a[mid]>n)
    binary_search(a,n,l,mid-1);
    else
    binary_search(a,n,mid+1,u);
}*/
/*bool is_palindrome(const string &s, int start, int end)
{
    int siz=end-start+1;
    if(siz%2==0)
    {
        int middle=start+siz/2;
        int i;
        for(i =0;middle-1-i>=0&&middle+i<=end&&s[middle-1-i]==s[middle+i];i++);
        if(middle-i-1<0||middle+i>end)
        return true;
    }
    else
    {
        int middle = start + siz/2;
        int i;
        for (i=1;middle-i>=0&&middle+i<=end&&s[middle-i]==s[middle+i];i++);
        if (middle-i<0||middle+i>end)
        return true;
    }
    return false;
}*/
int main()
{
    string s,s1;
    while(cin>>s)
    {
        long l,cnt=0,p,flag=0,cnt1=0,cnt2=0,flag2=0,allok=0;
        stack<long>stk;
        l=s.size();
        s1=s;
        reverse(s1.begin(),s1.end());
        rep(i,l)
        {
            if(s1[i]=='#')allok=1;
            else if(allok==0)
            {
                if(s1[i]==')')cnt1++;
                else cnt2++;
                if(cnt2>cnt1)flag2=1;
            }
            if(s[i]=='#')
            {
                cnt++;
                p=i;
                flag=0;
            }
            else
            {
                if(s[i]=='(')
                {
                    stk.push(s[i]);
                    flag=1;
                }
                else
                {
                    flag=0;
                    if(stk.size()!=0)
                    {
                        stk.pop();
                    }
                }
            }
        }
        if(flag==0&&stk.size()!=0&&flag2==0)
        {
            if(stk.size()>cnt)
            {
                rep(i,l)
                {
                    if(s[i]=='#')
                    {
                        if(i==p)cout<<stk.size()-cnt+1<<endl;
                        else
                        cout<<1<<endl;
                    }
                }
            }
            else
            {
                p=cnt-stk.size();
                rep(i,l)
                {
                    if(s[i]=='#')
                    {
                        if(p>=0)cout<<1<<endl;
                        else
                        cout<<-1<<endl;
                        p++;
                    }
                }
            }
        }
        else
        {
            //cout<<"Fuck\n";
            rep(i,l)
            if(s[i]=='#')cout<<-1<<endl;
        }
    }
    return 0;
}


///....................SUBRATO MOLLICK....................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///........................BETCH-10.......................///
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define REP2(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define INF (1<<30)
#define PI 3.14159265358979323846264338327950
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ size()
#define eps 1e-9
#define VI vector<int>
#define VS vector<string>
#define LL long long
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define CLEAR(x) memset(x,0,sizeof(x));
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define all(x) x.begin(),x.end()

/*long long c[201]={0};
bool p[205]={0};
void sieve()
{
   long long i,j;
    j=4;
     while(j<=201)
     {
         p[j]=1;
         j+=2;
     }
     long k=1;
     for(i=3;i<=(201);i+=2)
     {
        if(p[i]==0)
        {
            j=i;
            while(j+i<=201)
            {
                p[j+i]=1;j+=i;
            }
            if(p[i+2]==0)
            c[k++]=i;
        }
    }
}*/
/*long long npr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   ret*=(n-i+1);
   return ret;
}*/
/*long long ncr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   {
       ret*=(n-i+1);
       ret/=i;
   }
   return ret;
}*/
/*long long fact(long n)
{
    long long ret=1,i;
    for(i=1;i<=n;i++)
    ret*=i;
    return ret;
}*/
/*long long gcd(long n,long m)
{
  while(m>0)
  {
    n=n%m;
    n=n^m;
    m=m^n;
    n=n^m;
  }
  return n;
}*/
/*long long lcm(long n,long m)
{
    long long x=(n*m)/gcd(n,m);
    return x;
}*/
/*long is_prime(long n)
{
	long long ii;
	if(n == 1)
	return 0;
	if(n == 2)
	return 1;
	if(n%2 == 0)
	return 0;
	for(ii=3;ii*ii<=n;ii=ii+2)
        if(n%ii == 0)
        return 0;
        return 1;
}*/
/*double area_triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double a;
    a=x1*(y2-y3)+y1*(x3-x2)+((x2*y3)-(y2*x3))+eps;
    a=a/2+eps;
    return a;
}*/
/*double dist_2point(double x1,double y1,double x2,double y2)
{
    double d;
    d=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
    return d;
}*/
/*int binary_search(int a[],int n,int l,int u)
{
	int mid;
	if(l>u)
    return 0;
    mid=floor(l+u)/2;
    if(a[mid]==n)
    return mid;
    else if(a[mid]>n)
    binary_search(a,n,l,mid-1);
    else
    binary_search(a,n,mid+1,u);
}*/
/*bool is_palindrome(const string &s, int start, int end)
{
    int siz=end-start+1;
    if(siz%2==0)
    {
        int middle=start+siz/2;
        int i;
        for(i =0;middle-1-i>=0&&middle+i<=end&&s[middle-1-i]==s[middle+i];i++);
        if(middle-i-1<0||middle+i>end)
        return true;
    }
    else
    {
        int middle = start + siz/2;
        int i;
        for (i=1;middle-i>=0&&middle+i<=end&&s[middle-i]==s[middle+i];i++);
        if (middle-i<0||middle+i>end)
        return true;
    }
    return false;
}*/
int main()
{
    string s;
    while(cin>>s)
    {
        long l,cnt=0,p,flag=0;
        stack<long>stk;
        l=s.size();
        rep(i,l)
        {
            if(s[i]=='#')
            {
                cnt++;
                p=i;
                flag=0;
            }
            else
            {
                if(s[i]=='(')
                {
                    stk.push(s[i]);
                    flag=1;
                }
                else
                {
                    flag=0;
                    if(stk.size()!=0)
                    {
                        stk.pop();
                    }
                }
            }
        }
        if(flag==0&&stk.size()!=0)
        {
            if(stk.size()>cnt)
            {
                rep(i,l)
                {
                    if(s[i]=='#')
                    {
                        if(i==p)cout<<stk.size()-cnt+1<<endl;
                        else
                        cout<<1<<endl;
                    }
                }
            }
            else
            {
                p=cnt-stk.size();
                rep(i,l)
                {
                    if(s[i]=='#')
                    {
                        if(p>=0)cout<<1<<endl;
                        else
                        cout<<-1<<endl;
                        p++;
                    }
                }
            }
        }
        else
        {
            rep(i,l)
            if(s[i]=='#')cout<<-1<<endl;
        }
    }
    return 0;
}