The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$.

The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i$, while the departure of the $i$-th employee is denoted by the integer $-i$.

The company has some strict rules about access to its office:

  An employee can enter the office at most once per day.  He obviously can't leave the office if he didn't enter it earlier that day.  In the beginning and at the end of every day, the office is empty (employees can't stay at night). It may also be empty at any moment of the day. 

Any array of events satisfying these conditions is called a valid day.

Some examples of valid or invalid days:

  $[1, 7, -7, 3, -1, -3]$ is a valid day ($1$ enters, $7$ enters, $7$ leaves, $3$ enters, $1$ leaves, $3$ leaves).  $[2, -2, 3, -3]$ is also a valid day.  $[2, 5, -5, 5, -5, -2]$ is not a valid day, because $5$ entered the office twice during the same day.  $[-4, 4]$ is not a valid day, because $4$ left the office without being in it.  $[4]$ is not a valid day, because $4$ entered the office and didn't leave it before the end of the day. 

There are $n$ events $a_1, a_2, \ldots, a_n$, in the order they occurred. This array corresponds to one or more consecutive days. The system administrator erased the dates of events by mistake, but he didn't change the order of the events.

You must partition (to cut) the array $a$ of events into contiguous subarrays, which must represent non-empty valid days (or say that it's impossible). Each array element should belong to exactly one contiguous subarray of a partition. Each contiguous subarray of a partition should be a valid day.

For example, if $n=8$ and $a=[1, -1, 1, 2, -1, -2, 3, -3]$ then he can partition it into two contiguous subarrays which are valid days: $a = [1, -1~ \boldsymbol{|}~ 1, 2, -1, -2, 3, -3]$.

Help the administrator to partition the given array $a$ in the required way or report that it is impossible to do. Find any required partition, you should not minimize or maximize the number of parts.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 10^5$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^6 \le a_i \le 10^6$ and $a_i \neq 0$).


-----Output-----

If there is no valid partition, print $-1$. Otherwise, print any valid partition in the following format:

  On the first line print the number $d$ of days ($1 \le d \le n$).  On the second line, print $d$ integers $c_1, c_2, \ldots, c_d$ ($1 \le c_i \le n$ and $c_1 + c_2 + \ldots + c_d = n$), where $c_i$ is the number of events in the $i$-th day. 

If there are many valid solutions, you can print any of them. You don't have to minimize nor maximize the number of days.


-----Examples-----
Input
6
1 7 -7 3 -1 -3

Output
1
6

Input
8
1 -1 1 2 -1 -2 3 -3

Output
2
2 6

Input
6
2 5 -5 5 -5 -2

Output
-1

Input
3
-8 1 1

Output
-1



-----Note-----

In the first example, the whole array is a valid day.

In the second example, one possible valid solution is to split the array into $[1, -1]$ and $[1, 2, -1, -2, 3, -3]$ ($d = 2$ and $c = [2, 6]$). The only other valid solution would be to split the array into $[1, -1]$, $[1, 2, -1, -2]$ and $[3, -3]$ ($d = 3$ and $c = [2, 4, 2]$). Both solutions are accepted.

In the third and fourth examples, we can prove that there exists no valid solution. Please note that the array given in input is not guaranteed to represent a coherent set of events.

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation

Greedy algorithms


Solutions:
import sys
input = sys.stdin.buffer.readline
import os
from math import *
n = int(input())
arr = list(map(int, input().split()))
ans = [0]
z = []
zz = 0
temp = []
for i in range(0, n):
	if arr[i] > 0:
		z.append(arr[i])
		temp.append(arr[i])
	elif -arr[i] in z:
		z.remove(-arr[i])
		if len(z) == 0:
			if len(temp) == len(set(temp)):
				ans.append(i + 1)
				temp.clear()
			else:
				zz = 1
				break
	else:
		zz = 1
		break
if len(z) != 0:
	zz = 1
if zz == 1:
	print('-1')
else:
	print(len(ans) - 1)
	for i in range(1, len(ans)):
		print(ans[i] - ans[i - 1], end=' ')


n = int(input())
a = list(map(int, input().split()))
ans = []
s = set([a[0]])
was = set()
lst = 0
for q in range(1, n):
	x = a[q]
	if x < 0:
		d = x * -1
		if d not in s:
			print(-1)
			exit()
		else:
			s -= set([d])
		if len(s) == 0:
			ans.append(q + 1 - lst)
			was = set()
			lst = q + 1
	elif x in s or x in was:
		print(-1)
		exit()
	else:
		was.add(x)
		s.add(x)
if len(s) != 0:
	print(-1)
	exit()
print(len(ans))
print(*ans)


n = int(input())
a = list(map(int, input().split()))
days = []
ok = True
tod = set()
now = set()
for i in range(n):
	if a[i] > 0:
		if a[i] in tod:
			ok = False
			break
		else:
			tod.add(a[i])
			now.add(a[i])
	elif not -a[i] in now:
		ok = False
		break
	else:
		now.discard(-a[i])
	if len(now) == 0:
		days.append(i + 1)
		tod = set()
		now = set()
if len(now) != 0:
	ok = False
if ok:
	print(len(days))
	days = [0] + days
	for i in range(1, len(days)):
		print(days[i] - days[i - 1], end=' ')
else:
	print(-1)


n = int(input())
a = [*map(int, input().split())]
from itertools import accumulate
aa = [*accumulate(a)]
empc = 0
day = set()
ans = []
for (i, j) in zip(a, aa):
	if i in day or (i < 0 and -i not in day):
		print(-1)
		exit()
	else:
		day.add(i)
		empc += 1
	if j == 0:
		ans.append(empc)
		empc = 0
		day.clear()
if len(day) == 0:
	print(len(ans))
	print(*ans)
else:
	print(-1)


n = int(input())
s = 0
a = [-1]
m = set()
tmp = list(map(int, input().split()))
for i in range(n):
	j = tmp[i]
	s += j
	if j < 0 and -j not in m or j in m:
		print('-1')
		exit()
	m.add(j)
	if not s:
		m = set()
		a.append(i)
if a[-1] != n - 1:
	print(-1)
else:
	print(len(a) - 1)
	print(*[a[i + 1] - a[i] for i in range(len(a) - 1)])


import sys

def main():
	n = int(sys.stdin.readline())
	arr = [int(x) for x in sys.stdin.readline().split(' ')]
	d = {}
	alreadyEntered = {}
	days = []
	count = 0
	for a in arr:
		count += 1
		if a < 0:
			if -a not in d:
				return -1
			else:
				d[-a] = 0
		elif a in d and d[a] == 1:
			return -1
		elif alreadyEntered.get(a, False):
			return -1
		else:
			d[a] = 1
			alreadyEntered[a] = True
		if all(map(lambda x: x == 0, d.values())):
			days.append(count)
			alreadyEntered = {}
			count = 0
	if count > 0:
		return -1
	return str(len(days)) + '\n' + ' '.join((str(day) for day in days))
print(main())


n = int(input())
a = [int(x) for x in input().split()]
d = {}
left = {}
cnt = 0
days = 0
events = []
e = 0
for x in a:
	if x > 0:
		if not d.get(x):
			d[x] = 1
			cnt += 1
			e += 1
		else:
			print(-1)
			break
	elif not d.get(-x) or left.get(-x):
		print(-1)
		break
	else:
		cnt -= 1
		left[-x] = 1
	if cnt == 0:
		days += 1
		d = {}
		left = {}
		events.append(e * 2)
		e = 0
else:
	if cnt == 0:
		print(days)
		for x in events:
			print(x, end=' ')
	else:
		print(-1)


input()
ans = []
cur = 0
status = set()
were = set()
try:
	for ai in map(int, input().split()):
		cur += 1
		if ai < 0:
			status.remove(abs(ai))
			if not status:
				ans.append(cur)
				cur = 0
				were = set()
		else:
			assert ai not in were
			status.add(ai)
			were.add(ai)
	assert not were
	print(len(ans))
	print(*ans)
except (AssertionError, KeyError):
	print('-1')


import sys

class BSillyMistake:

	def solve(self):
		from collections import defaultdict
		NB_EMPLOYEES = 10 ** 6 + 1
		n = int(input())
		a = [int(_) for _ in input().split()]

		def answer():
			done = set()
			matched = set()
			parts = []
			s = 0
			for i in range(n):
				if a[i] > 0:
					if a[i] in done:
						print(-1)
						return
					done.add(a[i])
				else:
					if not -a[i] in done or -a[i] in matched:
						print(-1)
						return
					done.remove(-a[i])
					matched.add(-a[i])
					if not done:
						parts.append(i + 1 - s)
						s += i + 1 - s
						matched.clear()
			if done:
				print(-1)
				return
			assert sum(parts) == n
			print(len(parts))
			print(*parts)
		answer()
solver = BSillyMistake()
input = sys.stdin.readline
solver.solve()


n = int(input())
arr = list(map(int, input().split()))
c = 0
ans = []
d = {}
num = 0
r = 0
for i in range(n):
	r += 1
	if abs(arr[i]) not in d.keys():
		if arr[i] < 0:
			c = -1
			break
		else:
			d[arr[i]] = 1
			num += 1
	elif arr[i] < 0:
		if d[abs(arr[i])] == 1:
			num -= 1
			d[abs(arr[i])] -= 1
		else:
			c = -1
	else:
		c = -1
	if c == -1:
		break
	if num == 0:
		c += 1
		d = {}
		ans.append(r)
		r = 0
if n % 2 == 1 or num != 0:
	c = -1
if c == -1:
	print(-1)
else:
	print(c)
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
nd = 0
d = {}
v = 0
s = 0
ans = []
f = 0
for i in a:
	if i < 0:
		if abs(i) not in d:
			f = 1
			break
		else:
			v += i
			s += 1
	elif abs(i) in d:
		f = 1
		break
	else:
		d[i] = True
		v += i
		s += 1
	if v == 0:
		nd += 1
		ans.append(s)
		d = {}
		v = 0
		s = 0
if v != 0:
	f = 1
if f == 0:
	print(nd)
	print(*ans)
else:
	print(-1)


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
n = ii()
d = li()
sin = set()
res = []
prev = -1
flag = dd()
for i in range(n):
	if d[i] > 0 and d[i] not in sin and (flag[d[i]] == 0):
		sin.add(d[i])
		flag[d[i]] = 1
	elif d[i] < 0 and -d[i] in sin:
		sin.remove(-d[i])
	else:
		exit(print(-1))
	if len(sin) == 0:
		res.append(i - prev)
		prev = i
		flag = dd()
if len(sin) != 0:
	exit(print(-1))
print(len(res))
prr(res, sep=' ')


import sys
a = [0 for i in range(10 ** 6)]
n = int(input())
g = list(map(int, input().split()))
if n % 2 != 0:
	print(-1)
	sys.exit(0)
T = True
ans = []
count = 0
t = 0
v = set()
v2 = set()
for i in g:
	if i > 0:
		if t == 0:
			ans.append(count)
			count = 1
			t += 1
			v.clear()
			v2.clear()
			v.add(i - 1)
		elif i - 1 not in v:
			v.add(i - 1)
			t += 1
			count += 1
		elif i - 1 in v:
			print(-1)
			sys.exit(0)
		elif i - 1 in v:
			print(-1)
			sys.exit(0)
	else:
		i = abs(i)
		if i - 1 in v and i - 1 not in v2:
			t -= 1
			count += 1
			v2.add(i - 1)
		elif i - 1 not in v:
			print(-1)
			sys.exit(0)
		elif i - 1 not in v:
			print(-1)
			sys.exit(0)
		else:
			print(-1)
			sys.exit(0)
if t != 0:
	print(-1)
	sys.exit(0)
ans.append(count)
del ans[0]
print(len(ans))
print(*ans)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
n = ii()
a = li()
x = []
c = ans = 0
s = set()
d = set()
if n % 2:
	ans = 1
else:
	for p in a:
		c += 1
		if p > 0:
			if p in d:
				ans = 1
				break
			else:
				s.add(p)
				d.add(p)
		else:
			p = -p
			if p not in s:
				ans = 1
				break
			else:
				s.remove(p)
				if s == set():
					x.append(c)
					d.clear()
					c = 0
if ans or s != set():
	print(-1)
	exit()
print(len(x))
print(*x)


input()
t = {0}
i = s = 0
r = [0]
for x in map(int, input().split()):
	if (x > 0) & (x in t) | (x < 0) ^ (-abs(x) in t):
		r = (-1,)
		break
	if x > 0:
		t |= {x, -x}
	else:
		t -= {x}
	i += 1
	s += x
	if s == 0:
		r[0] += 1
		r += (i,)
		t = {0}
		i = 0
if s:
	r = (-1,)
print(r[0])
print(*r[1:])


for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 1:
		print('-1')
		continue
	c = []
	s = set()
	d = {}
	f = False
	x = 0
	b = 0
	for i in range(n):
		x += a[i]
		b += 1
		if a[i] > 0:
			if a[i] in s:
				x = -1
				break
			else:
				s.add(a[i])
		elif -a[i] not in s:
			x = -1
			break
		elif x == 0:
			x = 0
			c.append(b)
			b = 0
			s = set()
	if x:
		print(-1)
	else:
		print(len(c))
		print(*c)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = l()[0]
A = l()
s = set()
enc = set()
ans = []
count = 0
for i in range(n + 1):
	if i != 0 and len(s) == 0:
		ans.append(count)
		count = 0
		enc = set()
		if i == n:
			break
	if i == n:
		break
	if A[i] > 0 and A[i] not in s:
		if A[i] in enc:
			ans = -1
			break
		s.add(A[i])
		enc.add(A[i])
	elif A[i] > 0 and A[i] in s:
		ans = -1
		break
	elif A[i] < 0 and -A[i] in s:
		s.discard(-A[i])
	elif A[i] < 0 and -A[i] not in s:
		ans = -1
		break
	count += 1
if ans == -1 or len(s) != 0:
	print(-1)
	exit()
if ans == []:
	print(1)
	print(n)
	exit()
print(len(ans))
for ele in ans:
	print(ele, end=' ')


import sys
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()

def check(Arr):
	come = set()
	go = set()
	for i in Arr:
		if i < 0:
			if abs(i) not in come:
				return False
		if i > 0:
			if i in come:
				return False
			else:
				come.add(i)
	return True
n = int(input())
Arr = get_array()
dp = Arr.copy()
for i in range(1, n):
	dp[i] += dp[i - 1]
last = 0
flag = 0
ans = []
count = 0
if dp[-1] != 0:
	print(-1)
	exit()
for i in range(n):
	if dp[i] == 0:
		if check(Arr[last:i + 1]):
			ans.append(i - last + 1)
			count += 1
			last = i + 1
		else:
			flag = 1
			break
if flag == 0:
	print(count)
	print(*ans)
else:
	print(-1)


k = int(input())
l = list(map(int, input().split()))
pref = [l[0]]
n = 0
tab = []
nbevents = []
start = 0
good = 1
for i in range(1, k):
	pref.append(pref[-1] + l[i])
	if pref[-1] == 0:
		n += 1
		tab.append(i + 1)
for i in range(n):
	cut = l[start:tab[i]]
	x = len(set(cut))
	nbevents.append(x)
	s = set()
	check = 0
	if x != tab[i] - start:
		good = 0
		check = 1
		break
	for j in cut:
		if j < 0 and -j not in s:
			good = 0
			check = 1
			break
		s.add(j)
	start = tab[i]
	if check:
		break
if good and pref[-1] == 0:
	print(n)
	print(*nbevents)
else:
	print(-1)


n = int(input())
data = list(map(int, input().split()))
in_office = set()
was = set()
days = []
count = 0
for d in data:
	if d > 0:
		if d in in_office:
			print(-1)
			exit()
		if d in was:
			if len(in_office) == 0:
				days.append(count)
				was = set()
				in_office.add(d)
				was.add(d)
				count = 1
				continue
			else:
				print(-1)
				exit()
		else:
			in_office.add(d)
			was.add(d)
			count += 1
	elif -d in in_office:
		count += 1
		in_office.remove(-d)
		if len(in_office) == 0:
			days.append(count)
			was = set()
			count = 0
			continue
	else:
		print(-1)
		exit()
if not len(in_office) == 0:
	print(-1)
	exit()
print(len(days))
print(*days)


n = input()
arr = map(int, input().split())
l = [0]
s = set()
idx = 1

def solve():
	visited = set()
	idx = 1
	for num in arr:
		if num > 0:
			if num in s:
				return -1
			elif num not in visited:
				s.add(num)
				visited.add(num)
			else:
				return -1
		elif -num in s:
			s.remove(-num)
		else:
			return -1
		if not s:
			l.append(idx)
			visited = set()
		idx += 1
	if not s:
		return len(l) - 1
	else:
		return -1
sol = solve()
if sol == -1:
	print(sol)
else:
	print(sol)
	l = [l[i + 1] - l[i] for i in range(len(l) - 1)]
	print(*l)


a = int(input())
z = list(map(int, input().split()))
from collections import *
al = defaultdict(int)
days = []
score = 0
flag = 0
cnt = 0
en = defaultdict(int)
for i in range(len(z)):
	if z[i] < 0:
		if al[abs(z[i])] == 0 or en[abs(z[i])] == 0:
			print(-1)
			exit()
		else:
			score -= 1
			cnt += 1
			al[abs(z[i])] = 0
	elif al[z[i]] > 0 or en[z[i]] > 0:
		print(-1)
		exit()
	else:
		al[z[i]] = 1
		cnt += 1
		score += 1
		en[z[i]] = 1
	if score == 0:
		days.append(cnt)
		cnt = 0
		al = defaultdict(int)
		en = defaultdict(int)
if score == 0:
	print(len(days))
	print(*days)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
d = [0] * n
c = 0
cu = 0
f = True
s = set()
day = set()
for i in range(n):
	cu += 1
	if a[i] > 0 and s == set() and (day != set()):
		d[c] = cu - 1
		c += 1
		cu = 1
		day = set()
		s.add(a[i])
		day.add(a[i])
	elif a[i] > 0 and a[i] not in day:
		s.add(a[i])
		day.add(a[i])
	elif a[i] > 0:
		f = False
		break
	elif a[i] < 0 and -a[i] not in s:
		f = False
		break
	else:
		s.remove(-a[i])
if s != set():
	f = False
d[c] = cu
c += 1
cu = 0
if f:
	print(c)
	for i in range(c):
		print(d[i], end=' ')
else:
	print(-1)


def days(n):
	s = set()
	s2 = set()
	d = 0
	a = []
	for i in n:
		d += 1
		if i > 0 and i not in s and (i not in s2):
			s.add(i)
			s2.add(i)
		elif i < 0 and -i in s:
			s.remove(-i)
		else:
			return False
		if s == set():
			s2 = set()
			a += [d]
			d = 0
			s = set()
	if s2 == set():
		return a
	else:
		return False
x = input()
l = map(int, input().split())
k = days(l)
if k == False:
	print(-1)
else:
	print(len(k))
	print(*k)


from sys import stdin, stdout
import collections

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	already = set()
	in_building = set()
	num_present = 0
	num_events = 0
	res = []
	for e in a:
		if e > 0:
			if e in already or e in in_building:
				print(-1)
				return
			else:
				already.add(e)
				in_building.add(e)
				num_present += 1
		else:
			e = abs(e)
			if not e in in_building:
				print(-1)
				return
			else:
				in_building.remove(e)
				num_present -= 1
		num_events += 1
		if num_present == 0:
			res.append(num_events)
			num_events = 0
			already = set()
	if not res or num_present > 0:
		print(-1)
		return
	print(len(res))
	print(' '.join([str(x) for x in res]))
main()


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
sta = [0] * 1000005
now = []
ans = []
has = []

def restart():
	ans.append(2 * len(has))
	for i in has:
		sta[i] = 0
	has.clear()

def finish():
	print(-1)
	exit(0)
sum = 0
for i in a:
	if i > 0:
		if sta[i] == 1:
			finish()
		elif sta[i] == -1:
			if sum == 0:
				restart()
			else:
				finish()
		sta[i] = 1
	elif sta[-i] == 1:
		sta[-i] = -1
		has.append(-i)
	else:
		finish()
	sum += i
	if sum == 0:
		restart()
if sum:
	finish()
print(len(ans))
print(*ans)


n = int(input())
l = list(map(int, input().split()))
d = {}
days = []
s = 0
c = 0
for i in range(len(l)):
	if l[i] > 0:
		if l[i] in d:
			print(-1)
			break
		d[l[i]] = False
		s += l[i]
	else:
		if -1 * l[i] not in d:
			print(-1)
			break
		else:
			d[l[i]] = True
			s += l[i]
			c += 2
		if s == 0:
			days.append(c)
			d = {}
			c = 0
else:
	if any((d[i] == False for i in d)):
		print(-1)
	else:
		print(len(days))
		print(*days)


n = int(input())
l = list(map(int, input().split()))
s1 = set()
s2 = set()
ans = []
for x in l:
	if x > 0:
		if x in s1 or x in s2:
			print(-1)
			exit(0)
		s1.add(x)
	else:
		x = -x
		if x not in s1:
			print(-1)
			exit(0)
		s1.remove(x)
		s2.add(x)
		if len(s1) == 0:
			ans.append(len(s2) * 2)
			s2.clear()
if len(s1) == 0 and len(s2) == 0:
	print(len(ans))
	print(*ans)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
l = set()
f1 = []
f = 0
d = 0
l1 = set()
c = 0
for i in range(n):
	c += 1
	if a[i] > 0:
		if a[i] in l1:
			f = 1
			break
		l.add(a[i])
		l1.add(a[i])
	elif abs(a[i]) in l:
		l.remove(abs(a[i]))
	else:
		f = 1
		break
	if len(l) == 0:
		d += 1
		f1.append(c)
		c = 0
		l1 = set()
if f == 1 or len(l) > 0:
	print(-1)
else:
	print(d)
	print(*f1, sep=' ', end='')


n = int(input())
l = list(map(int, input().split()))
l1 = []
ans = 0
from collections import defaultdict as dd
d = dd(int)
d1 = dd(int)
d[l[0]] = 1
c = 1
if l[0] < 0:
	print(-1)
else:
	a = True
	b = 1
	for i in range(1, n):
		b += 1
		if l[i] < 0:
			if d[-l[i]] == 0:
				a = False
				break
			c -= 1
			d[-l[i]] -= 1
		else:
			c += 1
			d[l[i]] += 1
			d1[l[i]] += 1
			if d1[l[i]] > 1 or d[l[i]] > 1:
				a = False
				break
		if c == 0:
			ans += 1
			l1.append(b)
			b = 0
			d1 = dd(int)
	if c != 0:
		a = False
	if not a:
		print(-1)
	else:
		print(ans)
		print(*l1)


import math as mt
import collections as cc
import sys
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
ch = [0] * 1000005
s = set()
te = []

def nc():
	print(-1)
	sys.exit()
an = 0
la = 0
for i in range(n):
	temp = l[i]
	if temp > 0:
		if ch[temp] or temp in s:
			nc()
		ch[temp] += 1
		s.add(temp)
		an += 1
	else:
		temp *= -1
		if ch[temp] == 0:
			nc()
		ch[temp] = 0
		an -= 1
	if an == 0:
		s = set()
		te.append(i + 1 - la)
		la = i + 1
if an:
	nc()
print(len(te))
print(*te)


n = input()
arr = list(map(int, input().split()))

def silly_mistake(n, office_log):
	room = set()
	day = set()
	ans = []
	for i in office_log:
		if i > 0:
			if i in room:
				return [-1]
			if i in day:
				if not room:
					ans.append(2 * len(day))
					day = set()
					day.add(i)
					room.add(i)
				else:
					return [-1]
			else:
				room.add(i)
				day.add(i)
		else:
			i = abs(i)
			if i in room:
				room.remove(i)
			else:
				return [-1]
		if not room:
			ans.append(2 * len(day))
			day = set()
	if room:
		return [-1]
	return ans
ans = silly_mistake(n, arr)
if ans == [-1]:
	print(-1)
	exit(0)
print(len(ans))
print(' '.join(map(str, ans)))


n = int(input())
days = [int(i) for i in input().split()]
pos = True
soe = set()
resA = []
rs = 0
cd = 0
c = 0
oC = 0
for d in days:
	if d < 0 and -d not in soe or d in soe:
		pos = False
		break
	if d > 0:
		oC += 1
	else:
		oC -= 1
	rs += d
	c += 1
	soe.add(d)
	if rs == 0:
		if oC != 0 or c % 2 != 0:
			pos = False
			break
		cd += 1
		resA.append(c)
		c = 0
		soe = set()
		oC = 0
if len(days) % 2 != 0 or rs != 0:
	pos = False
if pos:
	print(cd)
	for i in resA:
		print(i, end=' ')
else:
	print(-1)


n = int(input())
(*a,) = map(int, input().split())
s = set()
cnt = 0
st = 0
ans = []
used = set()
for i in range(n):
	x = a[i]
	if x < 0:
		if not -x in s:
			print(-1)
			exit(0)
		s.remove(-x)
		used.add(-x)
		if len(s) == 0:
			used.clear()
			cnt += 1
			ans.append(i - st + 1)
	else:
		if x in s or x in used:
			print(-1)
			exit(0)
		if len(s) == 0:
			st = i
		s.add(x)
if not len(s):
	print(cnt)
	print(*ans, sep=' ')
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
d = []
(c, s) = (0, 0)
dd = {}
ddd = {}
f = 0
for i in range(n):
	if l[i] > 0:
		if l[i] not in dd:
			dd[l[i]] = 1
		else:
			dd[l[i]] += 1
		if dd[l[i]] > 1:
			f = 1
			break
	else:
		x = abs(l[i])
		if x not in ddd:
			ddd[x] = 1
		else:
			ddd[x] += 1
	c = c + 1
	s = s + l[i]
	if dd == ddd:
		d.append(c)
		c = 0
		s = 0
		ddd = {}
		dd = {}
	elif s < 0:
		f = 1
		break
if s > 0:
	print(-1)
elif f == 1:
	print(-1)
elif len(d) == 0:
	print(-1)
else:
	print(len(d))
	print(*d)


import sys
n = int(input())
array = [int(s) for s in input().split()]
a = set()
people = [0] * 1000001
used = []
prev = 0
ans = []
for i in range(len(array)):
	if array[i] < 0 and (not -array[i] in a) or (array[i] > 0 and people[array[i]] == 1):
		print(-1)
		sys.exit(0)
	else:
		if array[i] < 0 and -array[i] in a:
			a.remove(-array[i])
		elif array[i] > 0:
			a.add(array[i])
			people[array[i]] = 1
			used.append(array[i])
		if len(a) == 0:
			ans.append(i - prev + 1)
			prev = i + 1
			for i in range(len(used)):
				people[used[i]] = 0
			used = []
if len(a) != 0:
	print(-1)
else:
	print(len(ans))
	print(' '.join([str(s) for s in ans]))


n = int(input())
ar = list(map(int, input().split()))
A = dict()
B = set()
C = dict()
num = 0
ans = 0
lol = []
kek = []
for elem in ar:
	lol.append(elem)
	if abs(elem) not in B:
		B.add(elem)
	if abs(elem) not in A and elem < 0:
		ans = -1
		break
	elif abs(elem) not in A:
		A[elem] = 1
		C[elem] = 1
	else:
		if elem > 0:
			A[abs(elem)] += 1
			C[elem] += 1
		else:
			A[abs(elem)] -= 1
		if A[abs(elem)] == 0:
			B.discard(abs(elem))
	if A[abs(elem)] < 0:
		ans = -1
		break
	if C[abs(elem)] > 1:
		ans = -1
		break
	if len(B) == 0:
		kek.append(lol)
		lol = []
		for key in C.keys():
			C[key] = 0
if len(B) > 0:
	print(-1)
elif ans == -1:
	print(-1)
else:
	print(len(kek))
	for elem in kek:
		print(len(elem))


def foo(n, l):
	Nvalid = 0
	prev = 0
	days = []
	dedans = dict()
	out = dict()
	current = 0
	counter = 0
	for i in l:
		counter += 1
		if i > 0:
			current += 1
			if i in dedans:
				return (-1, -1)
			else:
				dedans[i] = True
		if i < 0:
			current -= 1
			if -i in dedans and -i not in out:
				out[-i] = True
			else:
				return (-1, -1)
		if current == 0:
			Nvalid += 1
			days.append(counter - prev)
			prev = counter
			dedans = dict()
			out = dict()
	if current != 0:
		return (-1, -1)
	return (Nvalid, days)
n = int(input())
l = list(map(int, input().split()))
(m, lst) = foo(n, l)
if m == -1:
	print(-1)
else:
	print(m)
	mot = ''
	for x in lst:
		mot += str(x) + ' '
	print(mot)


import sys

def main():
	n = int(input())
	a = list(map(int, input().split()))
	dp = {}
	arr = []
	cnt = 0
	last = 0
	for i in range(n):
		if a[i] > 0:
			if dp.get(a[i]) != None:
				print(-1)
				return
			dp[a[i]] = 1
			cnt += 1
		elif a[i] < 0:
			if dp.get(abs(a[i])) == None or dp[abs(a[i])] == 0:
				print(-1)
				return
			else:
				dp[abs(a[i])] = 0
				cnt -= 1
				if cnt == 0:
					arr.append(i + 1 - last)
					last = i + 1
					dp = {}
	if cnt != 0:
		print(-1)
		return
	print(len(arr))
	for x in arr:
		print(x, end=' ')
	print()
	return
main()


from operator import itemgetter
from math import sqrt
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

def solve():
	log = defaultdict(int)
	people = 0
	count = 0
	c = []
	for i in range(n):
		ai = a[i]
		sign = ai > 0
		ai = abs(ai)
		tmp = log[ai]
		if tmp == 0 and sign:
			log[ai] = 1
			people += 1
			count += 1
		elif tmp == 1 and (not sign):
			log[ai] = 2
			people += -1
			count += 1
		else:
			return (-1, [])
		if people == 0:
			c.append(count)
			log = defaultdict(int)
			people = 0
			count = 0
	if people == 0:
		return (1, c)
	else:
		return (-1, [])
(yn, c) = solve()
if yn == -1:
	print(-1)
else:
	print(len(c))
	print(' '.join(map(str, c)))


already_today = [0] * 1000005
in_office = 0
ans = []
pool = []
n = int(input())
meta = [int(x) for x in input().split()]

def finish():
	print(-1)
	exit(0)

def next_day():
	ans.append(len(pool) * 2)
	for i in pool:
		already_today[i] = 0
	pool.clear()
for worker in meta:
	if worker > 0:
		if already_today[worker] == 0:
			already_today[worker] = 1
			in_office += 1
			pool.append(worker)
		elif already_today[worker] == 1:
			finish()
		elif already_today[worker] == -1:
			finish()
	elif already_today[-worker] == 1:
		in_office -= 1
		already_today[-worker] = -1
		if not in_office:
			next_day()
	else:
		finish()
if in_office:
	finish()
print(len(ans))
print(*ans)


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : map(int, input().split())

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
n = int(input())
arr = list(read())
dp = [arr[0]]
flag = True
for i in range(1, n):
	dp.append(dp[-1] + arr[i])
if len(list(filter(lambda x: x < 0, dp))) >= 1 or dp[-1] != 0:
	print('-1')
	exit()
prev = -1
can = []
for i in range(n):
	if dp[i] == 0:
		can.append((prev + 1, i))
		prev = i
for (l, r) in can:
	d = defaultdict(bool)
	for i in range(l, r + 1):
		if arr[i] in d:
			print('-1')
			exit()
		if arr[i] < 0 and (not -arr[i] in d):
			print('-1')
			exit()
		d[arr[i]] = True
print(len(can))
for (i, j) in can:
	print(j - i + 1, end=' ')


import os
import sys
from io import BytesIO, IOBase
from itertools import accumulate

def solution(arr, n):
	sums = list(accumulate(arr))
	if sums[-1] != 0:
		write(-1)
		return
	(j, res) = (0, [])
	for i in range(len(sums)):
		if sums[i] == 0:
			seg = arr[j:i + 1]
			(l1, l2) = (len(seg), len(set(seg)))
			if l1 != l2:
				write(-1)
				return
			seg = set(seg)
			for x in seg:
				if -x not in seg:
					write(-1)
					return
			res.append(l1)
			j = i + 1
		if sums[i] < 0:
			write(-1)
			return
	write(len(res))
	write(*res)

def main():
	n = r_int()
	arr = r_array()
	solution(arr, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		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 = os.read(self._fd, max(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 = os.read(self._fd, max(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:
			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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


n = int(input())
a = list(map(int, input().split()))
s = set()
d = 0
ans = []
c = 0
o = set()
for i in range(n):
	x = a[i]
	if x > 0:
		if i == 0:
			c += 1
			s.add(x)
			o.add(x)
		elif len(s):
			if x in s or x in o:
				d = -1
				break
			else:
				c += 1
				s.add(x)
				o.add(x)
		else:
			d += 1
			ans.append(c)
			s.add(x)
			o = {x}
			c = 1
	elif x < 0:
		if i == 0:
			d = -1
			break
		elif len(s):
			if -1 * x in s:
				s.remove(-1 * x)
				c += 1
			else:
				d = -1
				break
		else:
			d = -1
			break
if d != -1:
	if len(s):
		print('-1')
	else:
		d += 1
		ans.append(c)
		print(d)
		print(*ans)
else:
	print('-1')


import sys, math
input = sys.stdin.readline

def inp():
	n = int(input())
	return n

def inlt():
	a = list(map(int, input().split()))
	return a

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	(a, b, c) = map(int, input().split())
	return (a, b, c)
t = 1
for tt in range(t):
	n = inp()
	a = inlt()
	q = dict()
	qq = 0
	l = 0
	w = 0
	qw = 0
	ww = []
	for i in range(len(a)):
		if a[i] > 0 and a[i] in q and (w > 0):
			qw = -1
			break
		if a[i] < 0 and abs(a[i]) not in q:
			qw = -1
			break
		if a[i] > 0:
			q[a[i]] = a[i]
			w = w + 1
		if a[i] < 0 and q[abs(a[i])] == abs(a[i]):
			q[abs(a[i])] = 0
			w = w - 1
		if w == 0:
			ww.append(i + 1 - l)
			l = i + 1
			q = dict()
	if w != 0 or qw == -1:
		print(-1)
	else:
		print(len(ww))
		print(*ww)


import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = list(map(int, input().split()))
	return (n, m)

def dva():
	(n, m) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
n = int(input())
a = list(map(int, input().split()))
ans = []
s = set([a[0]])
used = set()
lst = 0
for q in range(1, n):
	i = a[q]
	if i < 0:
		d = i * -1
		if d not in s:
			print(-1)
			return
		else:
			s -= set([d])
		if len(s) == 0:
			ans.append(q + 1 - lst)
			used = set()
			lst = q + 1
	elif i in s or i in used:
		print(-1)
		return
	else:
		used.add(i)
		s.add(i)
if len(s) != 0:
	print(-1)
	return
print(len(ans))
print(*ans)


n = int(input())
e = list(map(int, input().split()))
days = []
events = 0
count = 0
inOffice = set()
entered = set()
flag = True
days = []
for i in e:
	if i > 0:
		if i in entered:
			flag = False
			break
		else:
			entered.add(i)
			inOffice.add(i)
			events += 1
	else:
		temp = -1 * i
		if temp in inOffice:
			inOffice.discard(temp)
			events += 1
			if len(inOffice) == 0:
				count += 1
				days.append(events)
				events = 0
				inOffice = set()
				entered = set()
		else:
			flag = False
			break
if flag and len(inOffice) == 0:
	print(count)
	print(*days)
else:
	print('-1')


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ok = True
checked = [0] * (10 ** 6 + 1)
ans = []
ind = 0
used = set()
c = 0
for (i, a) in enumerate(A):
	if a > 0:
		if checked[a] == 0:
			if a in used:
				ok = False
				break
			checked[a] = 1
			c += 1
		else:
			ok = False
			break
	elif checked[-a] == 1:
		used.add(-a)
		checked[-a] = 0
		c -= 1
	else:
		ok = False
		break
	if c == 0:
		ans.append(i + 1 - ind)
		ind = i + 1
		used = set()
if not ok or c != 0:
	print(-1)
else:
	print(len(ans))
	print(' '.join([str(a) for a in ans]))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		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 = os.read(self._fd, max(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 = os.read(self._fd, max(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:
			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')
n = int(input())
events = list(map(int, input().split()))
cv = 0
dict1 = {}
days = []
broke = False
used = set([])
for s in range(n):
	if s == 0:
		dict1[cv] = {}
		if events[s] >= 1:
			dict1[cv][events[0]] = 1
			used.add(events[s])
		else:
			broke = True
			break
		days.append(1)
	elif len(dict1[cv]) > 0:
		days[-1] += 1
		val = abs(events[s])
		if not events[s] in used:
			if events[s] > 0:
				used.add(events[s])
				if not val in dict1[cv]:
					dict1[cv][val] = 1
				else:
					dict1[cv][val] += 1
			elif not val in dict1[cv]:
				dict1[cv][val] = -1
				broke = True
				break
			else:
				dict1[cv][val] -= 1
			if dict1[cv][val] == 0:
				dict1[cv].pop(val)
			elif dict1[cv][val] < 0:
				broke = True
				break
		else:
			broke = True
			break
	else:
		cv += 1
		dict1[cv] = {}
		days.append(1)
		used.clear()
		val = abs(events[s])
		if not events[s] in used:
			if events[s] > 0:
				used.add(events[s])
				if not val in dict1[cv]:
					dict1[cv][val] = 1
				else:
					dict1[cv][val] += 1
			elif not val in dict1[cv]:
				dict1[cv][val] = -1
				broke = True
				break
			else:
				dict1[cv][val] -= 1
			if dict1[cv][val] == 0:
				dict1[cv].pop(val)
			elif dict1[cv][val] < 0:
				broke = True
				break
		else:
			broke = True
			break
for s in dict1.keys():
	if len(dict1[s]) > 0:
		broke = True
		break
if broke == False:
	print(len(days))
	print(*days)
else:
	print(-1)


def main():
	n = int(input())
	aa = map(int, input().split())
	inoffice = set()
	entered = set()
	daycount = [0]
	days = 0
	ecount = 0
	for a in aa:
		daycount[-1] += 1
		if a > 0:
			if a in entered:
				print(-1)
				return
			inoffice.add(a)
			entered.add(a)
			ecount += 1
		else:
			if -a not in inoffice:
				print(-1)
				return
			inoffice.remove(-a)
			ecount -= 1
			if ecount == 0:
				daycount.append(0)
				days += 1
				entered = set()
	if ecount != 0:
		print(-1)
		return
	print(days)
	print(' '.join(map(str, daycount[:days])))
main()


n = int(input())
list1 = list(map(int, input().split()))
list2 = []
set1 = {list1[0]}
list2.append(list1[0])
ll = []
f = 0
dict1 = {}
if list1[0] > 0:
	dict1[list1[0]] = 1
else:
	f = 1
if f == 0:
	for i in range(1, n):
		if list1[i] > 0:
			if list1[i] in set1:
				f = 1
				break
			elif list1[i] not in dict1:
				set1.add(list1[i])
				list2.append(list1[i])
				dict1[list1[i]] = 1
			else:
				f = 1
				break
		if list1[i] < 0:
			if -list1[i] in set1:
				set1.remove(-list1[i])
				list2.append(list1[i])
			else:
				f = 1
				break
		if f == 0 and (not set1):
			ll.append(list2)
			list2 = []
			dict1 = {}
if f == 0 and (not list2):
	print(len(ll))
	for i in range(len(ll)):
		print(len(ll[i]), end=' ')
else:
	print(-1)


n = int(input())
array = list(map(int, input().strip().split()))
s = []
value = 0
d = {}
already_visited = set()
for i in array:
	value += 1
	if i > 0:
		if i not in d and i not in already_visited:
			d[i] = 1
		else:
			print(-1)
			exit(0)
	else:
		i = abs(i)
		if i not in d:
			print(-1)
			exit(0)
		else:
			already_visited.add(i)
			del d[i]
	if len(d) == 0:
		s.append(value)
		value = 0
		already_visited = set()
if len(d) == 0:
	print(len(s))
	print(' '.join(map(str, s)))
else:
	print(-1)


n = int(input())
array = map(int, input().split())
pr = [0] * (10 ** 6 + 1)
count = 0
ans = []
last_i = -1
pr_for_days = set()
for (i, el) in enumerate(array):
	if el > 0:
		if el in pr_for_days:
			print(-1)
			exit(0)
		if pr[el] == 1:
			print(-1)
			exit(0)
		pr[el] += 1
		count += 1
		pr_for_days.add(el)
	elif el < 0:
		if pr[abs(el)] == 0:
			print(-1)
			exit(0)
		count -= 1
		pr[abs(el)] -= 1
	if count == 0:
		ans.append(i - last_i)
		last_i = i
		pr_for_days = set()
if count != 0:
	print(-1)
	exit(0)
print(len(ans))
print(*ans)


n = int(input())
it = list(map(int, input().split()))
ss = set()
tt = set()
ans = [0]
for i in it:
	if i > 0 and i in tt:
		ans.append(1)
		if ss != set():
			ans = -1
			break
		ss = set([i])
		tt = set([i])
		continue
	if i > 0 and i not in tt:
		ans[-1] += 1
		ss.add(i)
		tt.add(i)
	elif i < 0 and abs(i) not in ss:
		ans = -1
		break
	elif i < 0 and abs(i) in ss:
		ss.remove(-i)
		ans[-1] += 1
		if ss == set():
			ans.append(0)
			tt = set()
if ss != set():
	ans = -1
if ans == -1:
	print(ans)
else:
	print(len([i for i in ans if i != 0]))
	for i in range(len([i for i in ans if i != 0])):
		print(ans[i], end=' ')


import itertools
n = int(input())
arr = [int(s) for s in input().split()]
cur_sum = 0
visited_emp = {}
ans_arr = [-1]
ans = 1
for i in range(n):
	if arr[i] > 0:
		try:
			x = visited_emp[arr[i]]
			if cur_sum == 0:
				ans_arr.append(i - 1)
				visited_emp = {}
			else:
				ans = -1
				break
		except KeyError:
			cur_sum = cur_sum + arr[i]
			visited_emp[arr[i]] = 1
	if arr[i] < 0:
		try:
			x = visited_emp[abs(arr[i])]
			if x == 1:
				cur_sum = cur_sum + arr[i]
		except KeyError:
			ans = -1
			break
	if cur_sum == 0:
		ans_arr.append(i)
		visited_emp = {}
if cur_sum != 0:
	ans = -1
if ans == -1:
	print(ans)
else:
	final_ans = []
	for i in range(1, len(ans_arr)):
		final_ans.append(ans_arr[i] - ans_arr[i - 1])
	print(len(final_ans))
	print(*final_ans)


n = int(input())
a = list(map(int, input().split()))
team = 0
dis = set()
ans = []
for i in range(n):
	if a[i] in dis or (a[i] < 0 and abs(a[i]) not in dis):
		print(-1)
		exit()
	team += a[i]
	dis.add(a[i])
	if not team:
		ans.append(len(dis))
		dis = set()
if not team:
	print(len(ans))
	print(' '.join(map(str, ans)))
else:
	print(-1)


import sys

def silly_mistake(nums, l):
	entered_today = set()
	mem = set()
	d = 0
	events = []
	curlen = 0
	for n in nums:
		curlen += 1
		if n in entered_today:
			return (-1, None)
		if n > 0:
			mem.add(n)
			entered_today.add(n)
		elif -n in mem:
			mem.remove(-n)
		else:
			return (-1, None)
		if len(mem) == 0:
			d += 1
			events.append(curlen)
			curlen = 0
			entered_today = set()
	if curlen != 0:
		return (-1, None)
	return (d, events)

def main():
	l = int(sys.stdin.readline())
	nums = [int(n) for n in sys.stdin.readline().split()]
	(d, events) = silly_mistake(nums, l)
	print(d)
	if d != -1:
		print(' '.join([str(e) for e in events]))
main()


n = int(input())
A = list(map(int, input().split()))
now = set()
used = set()
pre = -1
ans = []
for (i, a) in enumerate(A):
	if a > 0:
		if a in now or a in used:
			print(-1)
			exit()
		else:
			now.add(a)
			used.add(a)
	elif -a not in now:
		print(-1)
		exit()
	else:
		now.remove(-a)
	if not now:
		ans.append(i - pre)
		pre = i
		used = set()
if now:
	print(-1)
	exit()
print(len(ans))
print(*ans)


def valid(a):
	s = set()
	for i in a:
		if i < 0:
			if abs(i) not in s:
				return 0
		if i > 0:
			if i in s:
				return 0
			else:
				s.add(i)
	return 1
n = int(input())
a = list(map(int, input().split()))
l = a.copy()
c = 0
f = 0
r = []
flag = 0
for i in range(1, n):
	l[i] = l[i] + l[i - 1]
if l[-1] != 0:
	print(-1)
	exit()
for i in range(n):
	if l[i] == 0:
		if valid(a[f:i + 1]) == 1:
			r.append(i - f + 1)
			c += 1
			f = i + 1
		else:
			flag = 1
			break
if flag == 0:
	print(c)
	print(*r)
else:
	print(-1)


n = int(input())
data = list(map(int, input().split()))
kd = 0
mn1 = set()
mn2 = set()
sb = 0
sb_data = []
for i in range(len(data)):
	sb += 1
	if data[i] > 0:
		if data[i] in mn1:
			print(-1)
			break
		else:
			mn1.add(data[i])
			mn2.add(data[i])
	elif data[i] < 0:
		if -data[i] in mn2:
			mn2.remove(-data[i])
		else:
			print(-1)
			break
	if not mn2:
		kd += 1
		sb_data.append(sb)
		sb = 0
		mn1 = set()
		mn2 = set()
else:
	if mn2:
		print(-1)
	else:
		print(kd)
		print(*sb_data)


import os
import sys
from sys import *
from io import BytesIO, IOBase

def main():
	n = int(input())
	l = list(map(int, input().split()))
	(l1, l2) = (set(), set())
	ans = []
	p = 0
	f = 0
	for (a, b) in enumerate(l):
		if b < 0:
			if -b not in l1:
				stdout.write('-1')
				f = 1
				break
			l1.remove(-b)
		elif b in l2:
			stdout.write('-1')
			f = 1
			break
		else:
			l1.add(b)
			l2.add(b)
		if not l1:
			ans.append(a + 1 - p)
			l2.clear()
			p = a + 1
	if l1 and f == 0:
		stdout.write('-1')
		f = 1
	elif not f:
		print(len(ans))
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		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 = os.read(self._fd, max(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 = os.read(self._fd, max(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:
			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')
main()


import sys
input = sys.stdin.buffer.readline
n = int(input())
l = list(map(int, input().split()))
entered = 0
left = 0
array = [0] * (10 ** 6 + 1)
no_of_days = []
flag = 0
log = []
for i in l:
	if entered - left < 0:
		flag = 1
		break
	if i > 0:
		if array[i] == 0:
			array[i] += 1
			entered += 1
			log.append(i)
		else:
			flag = 1
			break
	elif i < 0:
		if array[abs(i)] == 1:
			array[abs(i)] += 2
			left += 1
		else:
			flag = 1
			break
	if entered == left:
		no_of_days.append(entered + left)
		entered = 0
		left = 0
		for j in log:
			array[j] = 0
		log = []
if flag or entered > 0:
	print(-1)
else:
	print(len(no_of_days))
	no_of_days = list(map(str, no_of_days))
	print(' '.join(no_of_days))


n = int(input())
array = list(map(int, input().split()))
pos = 0
workers = {}
ev = 0
day_events = []
for pos in range(n):
	op = array[pos]
	if op > 0:
		if op in workers.keys():
			print(-1)
			pos = -1
			break
		else:
			workers[op] = True
	else:
		op = -op
		if op in workers.keys():
			if workers[op] == True:
				workers[op] = False
			else:
				print(-1)
				pos = -1
				break
		else:
			print(-1)
			pos = -1
			break
	ev += 1
	new_day = True
	for worker in workers.keys():
		if workers[worker] == True:
			new_day = False
			break
	else:
		workers = {}
		day_events.append(ev)
		ev = 0
if sum(day_events) == n:
	day_events = [str(i) for i in day_events]
	print(len(day_events))
	print(' '.join(day_events))
elif pos != -1:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
a = set()
flag = 1
z = [0]
x = []
b = []
d = {}
f = {}
count = 0
for i in l:
	if i > 0:
		d[i] = 0
		f[i] = 0
for i in range(n):
	if l[i] > 0:
		a.add(l[i])
		if d[l[i]] > 0:
			flag = 0
		d[l[i]] += 1
		count += 1
	else:
		t = -1 * l[i]
		if t in a:
			a.remove(t)
			count -= 1
		else:
			flag = 0
			break
		if count == 0:
			d = dict(f)
			x.append(i)
			z.append(i + 1)
for i in range(len(x)):
	b.append(x[i] - z[i] + 1)
s = len(b)
if flag == 1 and count == 0:
	print(s)
	print(*b)
else:
	print(-1)


n = int(input())
a = [int(x) for x in input().split()]
(d, t) = [{}, {}]
count = [-1]
i = 0
while i < n:
	if a[i] > 0:
		if a[i] in d:
			print('-1')
			break
		else:
			if a[i] in t:
				print('-1')
				break
			t[a[i]] = True
			d[a[i]] = True
	else:
		q = abs(a[i])
		if q not in d:
			print('-1')
			break
		else:
			del d[q]
	if len(d) == 0:
		count.append(i)
		t = {}
	i += 1
if i == n:
	if len(d) > 0:
		print('-1')
	else:
		print(len(count) - 1)
		for i in range(1, len(count)):
			print(count[i] - count[i - 1], end=' ')


n = int(input())
a = list(map(int, input().split(' ')))
ev = set()
ev2 = set()
f = False
f2 = True
d = []
c = 0
for e in a:
	f = False
	if e > 0:
		if e in ev2:
			f2 = False
			break
		else:
			ev.add(e)
			ev2.add(e)
	elif e < 0:
		try:
			ev.remove(-e)
		except:
			f2 = False
			break
	c += 1
	if len(ev) == 0:
		d.append(c)
		ev2 = set()
		f = True
		c = 0
if f and f2:
	print(len(d))
	print(*d)
else:
	print(-1)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))

def solve():
	n = mint()
	s = set()
	w = set()
	k = 0
	r = []
	for i in mints():
		k += 1
		if i < 0:
			if -i not in s:
				print(-1)
				return
			s.remove(-i)
			if len(s) == 0:
				r.append(k)
				k = 0
				w = set()
		else:
			if i in w:
				print(-1)
				return
			s.add(i)
			w.add(i)
	if len(s) != 0:
		print(-1)
		return
	print(len(r))
	print(' '.join(map(str, r)))
solve()


states = [0] * 1000005

def solve(n, logs):
	cur = []
	res = []
	ans = 0
	for (i, val) in enumerate(logs):
		person = abs(val)
		cur.append(person)
		if val > 0:
			if states[person] != 0:
				return False
			states[person] = 1
			ans += 1
		else:
			if states[person] != 1:
				return False
			states[person] = 2
			ans -= 1
		if ans == 0:
			res.append(len(cur))
			for j in cur:
				states[j] = 0
			del cur
			cur = []
	if len(cur) != 0:
		return False
	print(len(res))
	for i in res:
		print(i, end=' ')
n = int(input())
logs = list(map(int, input().split()))
ans = solve(n, logs)
if ans == False:
	print(-1)


def correct_days_split(a: list) -> bool:
	office = set()
	days_events = []
	were_today = set()
	events = 0
	for (idx, el) in enumerate(a):
		if el in were_today and office:
			return []
		if el > 0:
			if el in office:
				return []
			else:
				office.add(el)
		elif el < 0:
			if abs(el) not in office:
				return []
			else:
				office.remove(abs(el))
		were_today.add(abs(el))
		events += 1
		if not office and idx > 0:
			days_events.append(events)
			were_today.clear()
			events = 0
	if office:
		return []
	else:
		return days_events

def main():
	n = int(input())
	a = list(map(int, input().split()))
	days_split = correct_days_split(a)
	if not days_split:
		print(-1)
	else:
		print(len(days_split))
		print(' '.join(map(str, days_split)))
main()


N = int(input())
A = list(map(int, input().split()))
Q = []
L = [0] * (10 ** 6 + 1)
Ans = []
cnt = 0
cnt_emp = 0
for a in A:
	cnt += 1
	if a > 0:
		Q.append(a)
		l = L[a]
		if l == 0:
			L[a] = 1
			cnt_emp += 1
		elif l == 1:
			print(-1)
			exit()
		else:
			print(-1)
			exit()
	else:
		a = -a
		l = L[a]
		if l == 0:
			print(-1)
			exit()
		elif l == 1:
			L[a] = 2
			cnt_emp -= 1
			if cnt_emp == 0:
				Ans.append(cnt)
				cnt = 0
				for q in Q:
					L[q] = 0
				Q = []
		else:
			print(-1)
			exit()
if cnt_emp != 0:
	print(-1)
	exit()
print(len(Ans))
print(' '.join(map(str, Ans)))


n = int(input())
events = list(map(int, input().split()))
days = 0
number_events = []
events_set = set()
sum_until_now = 0
entered_that_day = set()
for i in range(n):
	if i == 0 and events[i] < 0:
		days = -1
		break
	if events[i] > 0:
		if events[i] in entered_that_day:
			days = -1
			break
		n = len(events_set)
		events_set.add(events[i])
		if len(events_set) == n:
			days = -1
			break
		entered_that_day.add(events[i])
	else:
		if not abs(events[i]) in events_set:
			days = -1
			break
		events_set.remove(abs(events[i]))
		if len(events_set) == 0:
			days += 1
			if len(number_events) > 0:
				number_events.append(i + 1 - sum_until_now)
			else:
				number_events.append(i + 1)
			sum_until_now = i + 1
			entered_that_day = set()
if len(events_set) > 0:
	days = -1
print(days)
if days > -1:
	print(' '.join(list(map(str, number_events))))


import sys
n = int(sys.stdin.readline())
employees = list(map(int, sys.stdin.readline().split(' ')))
days = []
curr = 0
count = 0
inside = set()
seenToday = set()
while curr < n:
	count += 1
	employee = employees[curr]
	if employee > 0:
		if employee in seenToday:
			days = []
			break
		inside.add(employee)
		seenToday.add(employee)
	else:
		if abs(employee) not in inside:
			days = []
			break
		inside.remove(abs(employee))
		if len(inside) == 0:
			days.append(count)
			count = 0
			seenToday = set()
	curr += 1
if len(days) == 0 or len(inside) > 0:
	print(-1)
else:
	print(len(days))
	for n in days:
		print(n, end=' ')


n = int(input())
A = list(map(int, input().split()))
s = []
B = []
archive = []
counter = 0
for i in range(n):
	counter += 1
	if A[i] < 0:
		if -A[i] in s:
			del s[s.index(-A[i])]
			if s == []:
				B.append(counter)
				archive = []
				counter = 0
		else:
			s = [0]
			break
	else:
		if A[i] in archive:
			s = [0]
			break
		s.append(A[i])
		archive.append(A[i])
if s == []:
	print(len(B))
	print(*B)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
c = 0
x = [0] * 10 ** 6
flag = 1
events = 0
e = []
inside = 0
ind = 0
for i in range(n):
	events += 1
	if l[i] > 0:
		t = x[l[i] - 1]
		if t == 0:
			x[l[i] - 1] += 1
			inside += 1
		elif t == 1:
			flag = 0
			break
	else:
		t = x[abs(l[i]) - 1]
		if t == 1:
			x[abs(l[i]) - 1] = 0
			inside -= 1
		else:
			flag = 0
			break
	if inside == 0:
		if len(set(l[ind:i + 1])) != i + 1 - ind:
			flag = 0
			break
		e.append(events)
		events = 0
		c += 1
		ind = i + 1
if inside != 0:
	flag = 0
if events != 0:
	e.append(events)
	c += 1
if flag == 0:
	print(-1)
else:
	print(c)
	print(*e)


n = int(input())
a = list(map(int, input().split()))
s = set()
b = set()
now = 0
ans = []
while now < n:
	if a[now] > 0:
		if a[now] in s:
			print(-1)
			exit()
		else:
			s.add(a[now])
			b.add(a[now])
	elif -a[now] not in b:
		print(-1)
		exit()
	else:
		b.remove(-a[now])
	if len(b) == 0:
		ans.append(now + 1)
		s = set()
	now += 1
if len(b) != 0:
	print(-1)
	exit()
for i in range(len(ans) - 1, 0, -1):
	ans[i] -= ans[i - 1]
print(len(ans))
print(' '.join(map(str, ans)))


n = int(input())
array = list(map(int, input().strip().split()))
length = 0
sum = 0
d = {}
ans = []
for i in array:
	length += 1
	sum += i
	if i > 0:
		if i in d:
			print(-1)
			exit()
		else:
			d[i] = 0
	else:
		x = -1 * i
		if x not in d:
			print(-1)
			exit()
		elif d[x] == 0:
			d[x] = 1
		else:
			print(-1)
			exit()
	if sum == 0:
		ans.append(length)
		length = 0
		d = {}
if sum == 0:
	print(len(ans))
	print(*ans)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
flag = 1
li = []
s = 0
j = 0
d = dict()
for i in range(n):
	s += a[i]
	d[a[i]] = d.get(a[i], 0) + 1
	if s == 0:
		li.append(i - j + 1)
		j = i + 1
		d = dict()
	elif a[i] < 0 and d.get(-a[i], 0) - d[a[i]] != 0 or s < 0 or d[a[i]] > 1:
		flag = 0
		break
if flag == 0 or s != 0:
	print(-1)
else:
	print(len(li))
	print(*li)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input()
n = I()
a = li()
b = [0] * (10 ** 6 + 1)
p = []
s = 0
c = 0
flag = 0
d = defaultdict(int)
h = defaultdict(int)
for i in range(0, n):
	if a[i] < 0:
		if b[abs(a[i])] == 0:
			flag = 1
			break
		else:
			b[abs(a[i])] -= 1
			s -= 1
			c += 1
	elif a[i] in d:
		flag = 1
		break
	else:
		d[a[i]] = 1
		b[a[i]] += 1
		s += 1
		c += 1
	if s == 0:
		p.append(c)
		c = 0
		d.clear()
if flag == 1:
	print(-1)
elif s != 0:
	print(-1)
else:
	print(len(p))
	print(*p)


n = int(input())
l = list(map(int, str(input()).split()))
a = []
d = []
c = 0
o = []
for i in l:
	c += 1
	if i > 0 and i in d:
		o = [-1]
		break
	elif i > 0:
		a.append(i)
		d.append(i)
	elif i < 0 and abs(i) not in a:
		o = [-1]
		break
	else:
		a.remove(abs(i))
	if len(a) == 0:
		o.append(str(c))
		c = 0
		d = []
if o[0] != -1 and a == []:
	print(len(o))
	print(' '.join(o))
else:
	print('-1')


def readint():
	return int(input())

def readlistint():
	return list(map(int, input().split()))

def readgridint(rows):
	grid = []
	for idx in range(rows):
		col = list(map(int, input().split()))
		grid.append(col)
	return grid

def main():
	N = readint()
	notes = readlistint()
	num_days = 0
	parts = []
	office = set()
	visited = set()
	num_employees = 0
	possible = True
	for (idx, note) in enumerate(notes):
		if note > 0:
			if note in office or note in visited:
				possible = False
				break
			else:
				office.add(note)
				num_employees += 1
		else:
			opp_note = -1 * note
			if opp_note not in office:
				possible = False
				break
			else:
				office.remove(opp_note)
				visited.add(opp_note)
		num_days += 1
		if num_employees > 0 and len(office) == 0:
			parts.append(num_days)
			employees = 0
			num_days = 0
			visited = set()
	if num_days > 0:
		possible = False
	if possible:
		print(len(parts))
		print(' '.join(map(str, parts)))
	else:
		print(-1)
main()


import sys
input = sys.stdin.readline
from collections import defaultdict

def solve(n, a):
	in_house = [0] * (10 ** 6 + 1)
	num_in_house = 0
	res = []
	events = 0
	already_visited = defaultdict(lambda : 0)
	for ai in a:
		events += 1
		if ai > 0:
			if already_visited[ai] or in_house[ai]:
				return []
			already_visited[ai] = 1
			in_house[ai] = 1
			num_in_house += 1
		else:
			if not in_house[-ai]:
				return []
			in_house[-ai] = 0
			num_in_house -= 1
		if num_in_house == 0:
			res.append(events)
			events = 0
			already_visited = defaultdict(lambda : 0)
	if num_in_house == 0:
		return res
	else:
		return []
n = int(input())
a = list(map(int, input().split()))
res = solve(n, a)
if res == []:
	print(-1)
else:
	print(len(res))
	print(*res)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
days = []
evs = 0
inside = {}
for i in range(n):
	ans += a[i]
	if a[i] > 0:
		if a[i] in inside:
			print(-1)
			exit(0)
			continue
		inside[a[i]] = 1
	evs += 1
	if a[i] < 0 and -a[i] not in inside:
		print(-1)
		exit(0)
		continue
	if ans == 0:
		days.append(evs)
		evs = 0
		inside.clear()
if ans != 0:
	print(-1)
	exit(0)
l = len(days)
if l > 0:
	print(len(days))
	print(' '.join([str(d) for d in days]))
else:
	print(-1)


n = int(input())
s = set()
s1 = set()
d = 0
c = 0
a = list(map(int, input().split()))
flag = 0
re = []
f = 0
for i in range(len(a)):
	if a[i] < 0 and abs(a[i] + 0) not in s:
		print(-1)
		flag = 1
		break
	elif a[i] < 0:
		c += 1
		f -= 1
		if abs(a[i]) in s1:
			print(-1)
			flag = 1
			break
		s1.add(abs(a[i]))
		s.discard(abs(a[i]))
		if len(s) == 0:
			d += 1
			re.append(c)
			s = set()
			s1 = set()
			c = 0
	else:
		if a[i] in s or a[i] in s1:
			print(-1)
			flag = 1
			break
		s.add(a[i])
		f += 1
		c += 1
if flag == 0 and len(s) == 0:
	print(d)
	print(*re)
elif flag != 1:
	print(-1)


n = int(input())
a = list(map(int, input().split(' ')))
i = 0
ans = []
inv = False
while i < n:
	if a[i] < 0:
		inv = True
		break
	else:
		start = i
		bal = {a[i]: 1}
		visits = set([a[i]])
		while i < n and len(bal) > 0:
			i += 1
			if i == n:
				break
			if a[i] > 0:
				if a[i] in bal:
					inv = True
					break
				elif a[i] in visits:
					inv = True
					break
				else:
					bal[a[i]] = 1
					visits.add(a[i])
			elif -a[i] not in bal:
				inv = True
				break
			else:
				bal.pop(-a[i])
		ans.append(i - start + 1)
	if inv:
		break
	i += 1
if inv:
	print(-1)
elif len(bal) > 0:
	print(-1)
else:
	print(len(ans))
	print(' '.join(map(str, ans)))


n = int(input())
a = [int(x) for x in input().split()]
f = [0] * 1000006
p = {}
q = 0
c = 0
C = [0]
for i in range(n):
	if a[i] >= 0:
		if a[i] in p:
			print(-1)
			quit()
		if f[a[i]] == 0:
			c += 1
		f[a[i]] += 1
		p[a[i]] = 1
	else:
		if f[-a[i]] == 1:
			c -= 1
		f[-a[i]] -= 1
	if f[abs(a[i])] < 0:
		print(-1)
		quit()
	if c == 0:
		C.append(i + 1)
		p = {}
if c == 0:
	print(len(C) - 1)
	for i in range(1, len(C)):
		print(C[i] - C[i - 1], end=' ')
else:
	print(-1)


n = int(input())
arr = list(map(int, input().split(' ')))
count = []
counter = []
ans = 0
if n % 2 != 0 or sum(arr) != 0:
	exit(print(-1))
for z in range(len(arr)):
	ans += arr[z]
	if ans < 0:
		exit(print(-1))
	count.append(abs(arr[z]))
	if z == len(arr) - 1:
		if ans != 0:
			exit(print(-1))
			break
		if len(set(count)) != len(count) // 2:
			exit(print(-1))
			break
	if ans == 0:
		if len(set(count)) == len(count) // 2:
			counter.append(len(count))
			count.clear()
		else:
			exit(print(-1))
print(len(counter))
print(' '.join(map(str, counter)))


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	n = int(input())
	arr = list_input()
	day = []
	i = 0
	stack = {}
	events = 0
	visited = {}
	while i < n:
		if arr[i] < 0:
			t = -1 * arr[i]
			try:
				x = stack[t]
				del stack[t]
				visited[t] = 0
				if stack == {}:
					visited = {}
					day.append(2 * events)
					events = 0
			except KeyError:
				print(-1)
				return
		else:
			t = arr[i]
			try:
				x = stack[t]
				print(-1)
				return
			except KeyError:
				try:
					x = visited[t]
					print(-1)
					return
				except KeyError:
					stack[t] = 0
					events += 1
		i += 1
	if stack != {}:
		print(-1)
		return
	print(len(day))
	for i in day:
		print(i, end=' ')
t = 1
for _ in range(t):
	solve()


d = {}
I = input
n = int(I())
a = list(map(int, I().split(' ')))
days = 0
le = 0
cg = 0
events = []
try:
	for i in range(n):
		if a[i] < 0 and (abs(a[i]) not in d or (abs(a[i]) in d and d[abs(a[i])] == 0)):
			assert 1 == 0
		elif a[i] > 0:
			if le == cg and le != 0:
				events.append(2 * le)
				days += 1
				le = 1
				cg = 0
				d.clear()
				d[a[i]] = 1
			elif a[i] not in d:
				d[a[i]] = 1
				le += 1
			else:
				assert 1 == 0
		else:
			cg += 1
			d[abs(a[i])] = 0
	if le != cg:
		assert 1 == 0
	elif a[n - 1] < 0:
		events.append(2 * le)
		days += 1
	print(days)
	print(*events)
except AssertionError:
	print('-1')


n = int(input())
l = list(map(int, input().split()))
s = sum(l)
if n % 2 == 1 or s != 0:
	print(-1)
else:
	d = 0
	e = []
	x = 0
	s = 0
	f = 0
	for i in range(n):
		s = s + l[i]
		x = x + 1
		if s == 0:
			if len(set(l[i - (x - 1):i + 1])) == x:
				dic = {}
				for j in range(i - (x - 1), i + 1):
					dic[l[j]] = dic.get(l[j], 0) + 1
					if l[j] < 0 and dic.get(-l[j], 0) == 0:
						f = 1
						break
				if f:
					break
				d = d + 1
				e.append(x)
				x = 0
			else:
				f = 1
				break
		if f:
			break
	if f:
		print(-1)
	else:
		print(d)
		for i in range(len(e) - 1):
			print(e[i], end=' ')
		print(e[-1])


n = int(input())
a = list(map(int, input().split()))
inside = set()
flag = True
j = 1
ans = list()
b = set()
for i in range(len(a)):
	if a[i] > 0:
		if a[i] in inside or a[i] in b:
			flag = False
		else:
			inside.add(a[i])
			b.add(a[i])
	elif -a[i] in inside:
		inside.remove(-a[i])
		if len(inside) == 0:
			ans.append(j)
			b.clear()
			j = 0
	else:
		flag = False
	j += 1
if len(inside) != 0:
	flag = False
if flag:
	print(len(ans))
	print(*ans)
else:
	print(-1)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
NOW = set()
USED = set()
ANS = [0]
for i in range(n):
	if A[i] > 0:
		if A[i] in NOW or A[i] in USED:
			print(-1)
			return
		else:
			NOW.add(A[i])
			USED.add(A[i])
	elif -A[i] in NOW:
		NOW.remove(-A[i])
	else:
		print(-1)
		return
	if NOW == set():
		ANS.append(i + 1)
		USED = set()
if len(NOW) > 0:
	print(-1)
	return
print(len(ANS) - 1)
ANS2 = [ANS[i] - ANS[i - 1] for i in range(1, len(ANS))]
print(' '.join(map(str, ANS2)))


n = int(input())
arr = list(map(int, input().split()))
state = [0 for i in range(10 ** 6 + 10)]

def solve(arr):
	ofs = 0
	printer = []
	changer = []
	for num in arr:
		emp = abs(num)
		changer.append(emp)
		if num < 0:
			if state[emp] == 1:
				state[emp] = -1
				ofs -= 1
			else:
				return -1
		if num > 0:
			if state[emp] == 0:
				state[emp] = 1
				ofs += 1
			else:
				return -1
		if ofs == 0:
			printer.append(len(changer))
			for num in changer:
				state[num] = 0
			changer = []
	if changer == []:
		return printer
	else:
		return -1
solved = solve(arr)
if solved != -1:
	print(len(solved))
	output = ''
	for num in solved:
		output += str(num) + ' '
	print(output[:-1])
else:
	print(solved)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
nd = 0
d = {}
v = 0
s = 0
ans = []
f = 0
for i in a:
	if i < 0:
		if abs(i) not in d:
			f = 1
			break
		else:
			v += i
			s += 1
	elif abs(i) in d:
		f = 1
		break
	else:
		d[i] = True
		v += i
		s += 1
	if v == 0:
		nd += 1
		ans.append(s)
		d = {}
		v = 0
		s = 0
if v != 0:
	f = 1
if f == 0:
	print(nd)
	print(*ans)
else:
	print(-1)


import sys
import math
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	n = II()
	s = LI()
	d = {}
	t = {}
	for i in range(1000010):
		d[i] = False
	h = 0
	l = []
	f = True
	c = 0
	for i in s:
		c += 1
		if i > 0:
			h += 1
			if not d[i]:
				d[i] = True
				if i in t:
					f = False
				t[i] = True
			else:
				f = False
		else:
			h -= 1
			if d[-i]:
				d[-i] = False
			else:
				f = False
		if h < 0:
			f = False
		if h == 0 and c > 0:
			t = {}
			l.append(c)
			c = 0
	if h > 0:
		f = False
	if f:
		print(len(l))
		for i in l:
			print(i, end=' ')
	else:
		print(-1)
main()


d = {}
for i in range(2 * 10 ** 6):
	d[i + 1] = -10 ** 9
n = int(input())
a = list(map(int, input().split()))
day = 1
curr_len = 0
ans = []
cnt = 0
for i in range(n):
	q = a[i]
	cnt += 1
	if q > 0:
		if abs(d[q]) == day:
			print('-1')
			exit()
		d[q] = day
		curr_len += 1
	if q < 0:
		if d[-q] != day:
			print('-1')
			exit()
		d[-q] = -day
		curr_len -= 1
	if curr_len == 0:
		day += 1
		ans.append(cnt)
		cnt = 0
if curr_len != 0:
	print(-1)
	exit()
print(len(ans))
print(*ans)


from collections import defaultdict
n = int(input())
l = [*map(int, input().split())]
valid = True
res = []
cnt = defaultdict(int)
cur = 0
for e in l:
	if e < 0:
		valid &= cnt[-e] == 1
		cnt[-e] += 1
		cur += 1
	else:
		valid &= cnt[e] == 0
		cnt[e] += 1
	if cur == len(cnt):
		res.append(2 * cur)
		cnt.clear()
		cur = 0
	if not valid:
		break
valid &= cur == 0 and (not cnt)
if not valid:
	print(-1)
else:
	print(len(res))
	print(*res)


def solve(events):
	i = 0
	splits = []
	inside = set()
	seen = set()
	while i < len(events):
		event = events[i]
		arriving = event > 0
		person = abs(event)
		if arriving:
			if person in inside or person in seen:
				return None
			inside.add(person)
		else:
			if person not in inside:
				return None
			inside.remove(person)
			seen.add(person)
		i += 1
		if not inside:
			splits.append(i)
			inside = set()
			seen = set()
	if inside:
		return None
	return splits

def print_(splits):
	if splits is None:
		print(-1)
		return
	last = 0
	print(len(splits))
	for split in splits:
		print(split - last, end=' ')
		last = split
	print()
n = int(input())
events = [int(x) for x in input().split()]
partitions = solve(events)
print_(partitions)


import math
from decimal import *
import random
n = int(input())
arr = list(map(int, input().split()))
vis = {}
curin = 0
ans = []
cnt = 0
ok = True
for i in range(n):
	if arr[i] > 0:
		if arr[i] in vis:
			ok = False
			break
		vis[arr[i]] = 1
		curin += 1
		cnt += 1
	if arr[i] < 0:
		if abs(arr[i]) not in vis:
			ok = False
			break
		if vis[abs(arr[i])] == 0:
			ok = False
			break
		vis[abs(arr[i])] = 0
		curin -= 1
		cnt += 1
		if curin == 0:
			ans.append(str(cnt))
			cnt = 0
			vis = {}
if vis != {}:
	ok = False
if ok:
	print(len(ans))
	print(' '.join(ans))
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
d = {}
length = 0
ans = []
s = 0
for i in l:
	s += i
	length += 1
	if i > 0:
		if i in d:
			print(-1)
			exit()
		else:
			d[i] = 0
	elif -1 * i not in d:
		print(-1)
		exit()
	elif d[-1 * i] == 0:
		d[-1 * i] = i
	else:
		print(-1)
		exit()
	if s == 0:
		ans.append(length)
		d = {}
		length = 0
if s == 0:
	print(len(ans))
	print(*ans)
else:
	print(-1)


from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
if sum(a) != 0:
	print(-1)
else:
	vis = defaultdict(lambda : 0)
	vis1 = defaultdict(lambda : 0)
	temp = 0
	curr = 0
	ans = []
	for i in range(n):
		if vis[a[i]] == 1:
			temp = 1
			break
		else:
			if a[i] > 0:
				curr += a[i]
				vis[a[i]] = 1
				vis1[a[i]] = 1
			elif vis1[-1 * a[i]] == 0:
				temp = 1
				break
			else:
				curr += a[i]
				vis1[a[i]] = 0
			if curr == 0:
				ans.append(i + 1)
				vis = defaultdict(lambda : 0)
				vis1 = defaultdict(lambda : 0)
	if temp == 1:
		print(-1)
	else:
		print(len(ans))
		print(ans[0], end=' ')
		for i in range(1, len(ans)):
			print(ans[i] - ans[i - 1], end=' ')
		print()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
set_ = set([])
set_2 = set([])
ans = []
for i in range(n):
	if a[i] > 0:
		if a[i] not in set_2:
			set_.add(a[i])
		else:
			print(-1)
			exit()
		set_2.add(a[i])
	elif abs(a[i]) in set_:
		set_.remove(-a[i])
	else:
		print(-1)
		exit()
	if not set_:
		set_2 = set([])
		ans.append(i + 1)
if set_:
	print(-1)
	exit()
res = [0] * len(ans)
for i in range(len(ans)):
	if i == 0:
		res[i] = ans[i]
	else:
		res[i] = ans[i] - ans[i - 1]
print(len(res))
print(*res)


n = int(input())
l = list(map(int, input().split(' ')))
t = []
t1 = []
a = [0] * 1000001
flag = 0
s = 0
for i in range(0, n):
	if l[i] > 0:
		a[l[i]] += 1
		if a[l[i]] > 1:
			flag = 1
			break
	if l[i] < 0:
		if a[-l[i]] == 0:
			flag = 1
			break
		if a[-l[i]] == 1:
			a[-l[i]] = 0
	s += l[i]
	t.append(l[i])
	if s == 0:
		if len(t) != len(set(t)):
			flag = 1
			break
		t1.append(len(t))
		t = []
if s != 0:
	print(-1)
elif flag == 1:
	print(-1)
else:
	print(len(t1))
	print(*t1, sep=' ')


n = int(input())
a = list(map(int, input().split()))
rab = set()
office = set()
dc = []
end = True
d = 0
c = -1
for i in range(len(a)):
	if a[i] > 0:
		if a[i] not in office:
			office.add(a[i])
			rab.add(a[i])
		else:
			print(-1)
			exit()
	elif -a[i] in office:
		if -a[i] in rab:
			rab.remove(-a[i])
		else:
			print(-1)
			exit()
	else:
		print(-1)
		exit()
	if not rab:
		dc.append(i - c)
		d += 1
		c = i
		office = set()
if rab:
	print(-1)
else:
	print(d)
	print(*dc)


n = int(input())
a = [int(j) for j in input().split()]
l = [0 for i in range(int(1000000.0 + 1))]
tot = 0
flag = True
days = []
so_fa = 0
s = set()
for i in range(n):
	if a[i] > 0:
		if l[a[i]] == 0 and a[i] not in s:
			s.add(a[i])
			l[a[i]] += 1
			tot += 1
			so_fa += 1
		else:
			flag = False
			break
	elif l[-1 * a[i]] == 1:
		l[-1 * a[i]] -= 1
		tot -= 1
		so_fa += 1
		if tot == 0:
			days.append(so_fa)
			so_fa = 0
			tot = 0
			s = set()
	else:
		flag = False
		break
if tot > 0:
	flag = False
if flag:
	print(len(days))
	for i in range(len(days)):
		print(days[i], end=' ')
	print()
else:
	print(-1)


def mistake(list1):
	count = 0
	list5 = []
	cur = []
	list4 = [False for i in range(2000000)]
	for (i, x) in enumerate(list1):
		cur.append(x)
		if x > 0:
			if list4[x - 1]:
				print(-1)
				return
			else:
				list4[x - 1] = True
				count += 1
		elif list4[x] or list4[-x - 1] == False:
			print(-1)
			return
		else:
			list4[x] = True
			count -= 1
		if count == 0:
			list5.append(len(cur))
			for y in cur:
				if y > 0:
					list4[y - 1] = False
				else:
					list4[y] = False
			cur = []
	if count != 0:
		print(-1)
		return
	if len(list5) > 0:
		print(len(list5))
		for x in list5:
			print(x, end=' ')
n = int(input())
l = input().split(' ')
l = [int(c) for c in l]
mistake(l)


3
import os
import sys

def main():
	N = read_int()
	A = read_ints()
	ans = solve(N, A)
	if not ans:
		print('-1')
	else:
		print(len(ans))
		print(*ans)

def solve(N, A):
	ans = []
	start = 0
	present = set()
	left = set()
	for (i, a) in enumerate(A):
		if a > 0:
			if a in present or a in left:
				return None
			present.add(a)
		else:
			a = -a
			if a not in present:
				return None
			present.remove(a)
			left.add(a)
			if not present:
				ans.append(i - start + 1)
				start = i + 1
				left = set()
	if start != N:
		return None
	return ans
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
b = [0] * (10 ** 6 + 1)
ans = []
num = 0
p = {}
poor = 0
start = 0
for i in range(n):
	if a[i] > 0:
		if not a[i] in p:
			p[a[i]] = 1
			num += 1
			start += 1
		else:
			poor = 1
			break
	elif abs(a[i]) in p:
		if p[abs(a[i])] == 1:
			num += 1
			start -= 1
			p[abs(a[i])] -= 1
	else:
		poor = 1
		break
	if start == 0:
		ans.append(num)
		p = {}
		num = 0
if poor == 1 or num != 0:
	print(-1)
else:
	print(len(ans))
	print(*ans)


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, ls) = (ii(), ll())
cday = 0
ans = []
start = 0
d = [-1] * 1000001
inside = 0
for i in range(n):
	c = ls[i]
	if c < 0:
		if d[-c] != 2 * cday:
			print(-1)
			exit()
		d[-c] += 1
		inside -= 1
		if inside == 0:
			ans.append(i - start + 1)
			cday += 1
			start = i + 1
	elif d[c] < 2 * cday:
		d[c] = 2 * cday
		inside += 1
	else:
		print(-1)
		exit()
if inside != 0:
	print(-1)
else:
	print(cday)
	print(*ans)


n = int(input())
a = list(map(lambda x: int(x), input().split()))
c = []
s = 0
enter = [False] * 1000001
left = [False] * 1000001
today = []
for ai in a:
	if ai > 0 and (enter[ai] or left[ai]):
		c = []
		break
	if ai < 0 and (not enter[-ai] or left[-ai]):
		c = []
		break
	s += ai
	if ai > 0:
		enter[ai] = True
		today.append(ai)
	else:
		left[-ai] = True
		enter[-ai] = False
		if s == 0:
			c.append(len(today))
			for x in today:
				enter[x] = False
				left[x] = False
			today = []
if len(c) > 0 and s == 0:
	print(str(len(c)))
	print(' '.join((str(x * 2) for x in c)))
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = []
ent = {}
out = {}
decision = 1
balance = 0
cur_day = []
for i in range(n):
	if a[i] > 0 and a[i] not in ent and (a[i] not in out) or (a[i] < 0 and abs(a[i]) in ent and (abs(a[i]) not in out)):
		cur_day.append(a[i])
		if a[i] > 0:
			ent[a[i]] = 1
			balance += 1
		else:
			out[abs(a[i])] = 1
			balance -= 1
			if balance == 0:
				if sum(cur_day) == 0 and len(cur_day) > 0:
					b.append(cur_day)
					cur_day = []
					ent = {}
					out = {}
	elif a[i] > 0 and a[i] in ent and (a[i] in out) and (sum(cur_day) == 0):
		b.append(cur_day)
		cur_day = []
		ent = {}
		out = {}
		ent[a[i]] = 1
		cur_day.append(a[i])
		balance = 1
	else:
		decision = -1
if len(cur_day) > 0:
	decision = -1
if decision == -1:
	print(-1)
else:
	print(len(b))
	s = ''
	for v in b:
		s += str(len(v)) + ' '
	print(s[:len(s) - 1])


from sys import *
z = stdin.readline
n = int(z())
l = list(map(int, z().split()))
(l1, l2) = (set(), set())
ans = []
p = 0
f = 0
for (a, b) in enumerate(l):
	if b < 0:
		if -b not in l1:
			stdout.write('-1')
			f = 1
			break
		l1.remove(-b)
	elif b in l2:
		stdout.write('-1')
		f = 1
		break
	else:
		l1.add(b)
		l2.add(b)
	if not l1:
		ans.append(a + 1 - p)
		l2.clear()
		p = a + 1
if l1 and f == 0:
	stdout.write('-1')
	f = 1
elif not f:
	print(len(ans))
	stdout.write(' '.join(('%d' % i for i in ans)))


n = int(input())
a = list(map(int, input().split()))
f = True
s = set()
sm = 0
valid = [0]
ct = 0
for i in a:
	if i in s:
		if sm != 0:
			f = False
			break
		valid.append(ct)
		s = set()
	if i < 0:
		if -i not in s:
			f = False
			break
		sm += i
		s.add(i)
		if sm == 0:
			s = set()
			valid.append(ct + 1)
	if i > 0:
		sm += i
		s.add(i)
	ct += 1
if n not in valid:
	valid.append(n)
if f and sm == 0:
	print(len(valid) - 1)
	st = ''
	for i in range(1, len(valid)):
		st += str(valid[i] - valid[i - 1]) + ' '
	print(st.strip())
else:
	print(-1)


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
p = 0
q = 0
f = 0
d = {}
an = []
for j in range(n):
	p = p + a[j]
	if a[j] < 0:
		if abs(a[j]) not in d:
			f = 1
	elif a[j] not in d:
		d[a[j]] = 1
	else:
		f = 1
	if p != 0:
		q = q + 1
	else:
		an.append(q + 1)
		p = 0
		q = 0
		d = {}
if f == 0 and p == 0:
	print(len(an))
	print(' '.join(map(str, an)))
else:
	print(-1)


from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
if sum(l) != 0:
	print(-1)
	exit()
if l[0] < 0:
	print(-1)
	exit()
s = 0
ans = []
seti = set()
count = 0
for i in range(n):
	s += l[i]
	if l[i] < 0:
		count += 1
		if -l[i] not in seti:
			print(-1)
			exit()
		elif s == 0:
			seti = set()
			ans.append(count)
			count = 0
	else:
		if l[i] in seti:
			print(-1)
			exit()
		seti.add(l[i])
		count += 1
print(len(ans))
print(*ans)


def main():
	input()
	(office, table, res, i) = (set(), set(), [], -1)
	for (j, s) in enumerate(input().split()):
		if s[0] == '-':
			s = s[1:]
			if s not in office:
				return print('-1')
			office.remove(s)
			if not office:
				res.append(j - i)
				(i, table) = (j, set())
		else:
			if s in table:
				return print('-1')
			office.add(s)
			table.add(s)
	if office:
		return print('-1')
	print(len(res), ' '.join(map(str, res)), sep='\n')
main()


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	s = set()
	ans = []
	last = 0
	f = 1
	vis = set()
	for i in range(n):
		if a[i] > 0:
			if a[i] in s or a[i] in vis:
				f = 0
				break
			s.add(a[i])
		else:
			if -a[i] not in s or a[i] in vis:
				f = 0
				break
			s.remove(-a[i])
			vis.add(a[i])
		if not s:
			vis = set()
			ans += [i - last + 1]
			last = i + 1
	if s:
		f = 0
	if f:
		print(len(ans))
		print(*ans)
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
dic = dict()
s = 0
days = []
j = 0
f = 0
for i in range(n):
	s += a[i]
	dic[a[i]] = dic.get(a[i], 0) + 1
	if s == 0:
		days.append(i - j + 1)
		j = i + 1
		dic = dict()
	elif s < 0 or dic[a[i]] > 1 or (a[i] < 0 and dic.get(-a[i], 0) - dic[a[i]]):
		f = 1
		break
if f or s:
	print(-1)
else:
	print(len(days))
	print(*days)


n = int(input())
a = list(map(int, input().split()))
if n % 2 != 0:
	print(-1)
else:
	res = []
	sum = 0
	lt = 0
	d = dict()
	for i in range(n):
		if a[i] < 0:
			tot = abs(a[i])
			if d.get(tot, 0) == 1 and d.get(a[i], 0) != 1:
				sum += a[i]
				d[a[i]] = 1
				lt += 1
			else:
				print(-1)
				break
		else:
			tot = a[i]
			if d.get(tot, 0) == 1:
				print(-1)
				break
			else:
				d[tot] = 1
				sum += tot
				lt += 1
		if sum == 0:
			res.append(lt)
			lt = 0
			temp = []
			d = {}
	else:
		if lt == 0:
			print(len(res))
			for i in res:
				print(i, end=' ')
			print()
		else:
			print(-1)


n = int(input())
a = list(map(int, input().split()))
office = set()
c = ''
d = 0
count = 0
check = set()
can = True
for i in a:
	office.add(i)
	count += 1
	if -i in office and i < 0:
		office.remove(-i)
		office.remove(i)
	if len(office) == 0:
		d += 1
		c += str(count) + ' '
		count = 0
		check.clear()
	elif i in check:
		can = False
		break
	else:
		check.add(i)
if len(office) > 0 or can == False:
	print(-1)
else:
	print(d)
	print(c)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		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 = os.read(self._fd, max(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 = os.read(self._fd, max(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:
			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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def bfs(g, st):
	visited = [-1] * len(g)
	visited[st] = 0
	queue = []
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.pop()
		new.append(s)
		for i in g[s]:
			if visited[i] == -1:
				visited[i] = visited[s] + 1
				queue.append(i)
	return visited

def dfsusingstack(v, st):
	d = deque([])
	visited = [0] * len(v)
	d.append(st)
	new = []
	visited[st] = 1
	while len(d) != 0:
		curr = d.pop()
		new.append(curr)
		for i in v[curr]:
			if visited[i] == 0:
				visited[i] = 1
				d.append(i)
	return new

def sieve(a, n):
	for i in range(3, n + 1, 2):
		a[i] = 1
	for i in range(3, n + 1, 2):
		for j in range(i * i, n + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	n = int(inp())
	l = lis()
	s1 = set()
	s2 = set()
	ans = []
	for i in l:
		if i > 0:
			if i in s1 or i in s2:
				print(-1)
				exit(0)
			s1.add(i)
		else:
			i = -i
			if i not in s1:
				print(-1)
				exit(0)
			s1.remove(i)
			s2.add(i)
			if len(s1) == 0:
				ans.append(len(s2) * 2)
				s2.clear()
	if len(s1) == 0 and len(s2) == 0:
		print(len(ans))
		print(*ans)
	else:
		print(-1)
testcase(1)


import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
seen = set([])
mustExit = set([])
result = []
last = 0
ok = True
ff = False
for i in range(n):
	if arr[i] > 0 and arr[i] not in seen:
		if len(mustExit) == 0 and ff:
			result.append(arr[last:i])
			mustExit = set([arr[i]])
			seen = set([arr[i]])
			last = i
		else:
			ff = True
			mustExit.add(arr[i])
			seen.add(arr[i])
	elif arr[i] < 0 and abs(arr[i]) in mustExit:
		mustExit.remove(abs(arr[i]))
	else:
		if len(mustExit) != 0 or (arr[i] < 0 and abs(arr[i]) not in mustExit):
			ok = False
			break
		if arr[i] > 0:
			result.append(arr[last:i])
			mustExit = set([arr[i]])
			seen = set([arr[i]])
			last = i
if len(mustExit) != 0:
	ok = False
result.append(arr[last:n])
if not ok:
	print(-1)
elif len(result) == 0:
	print(1)
	print(n)
else:
	print(len(result))
	for el in result:
		print(len(el), end=' ')
	print()


n = int(input())
A = input().split()
A = [int(k) for k in A]
imposs = False
days = []
curr_empl = set()
day_empl = set()
d_s = 0
for i in range(n):
	e = A[i]
	if e < 0:
		if -e not in curr_empl:
			imposs = True
			break
		curr_empl.remove(-e)
	else:
		if e in day_empl:
			imposs = True
			break
		day_empl.add(e)
		curr_empl.add(e)
	if len(curr_empl) == 0:
		curr_empl = set()
		day_empl = set()
		days.append(i - d_s + 1)
		d_s = i + 1
if imposs or len(curr_empl) > 0:
	print(-1)
else:
	print(len(days))
	print(' '.join([str(di) for di in days]))


import sys

def schedule(a, n):
	if n % 2:
		return []
	office = set()
	used = set()
	ans = []
	dayStart = -1
	dayEnd = -1
	for (i, e) in enumerate(a):
		if e < 0:
			e = -e
			if e not in office:
				return []
			else:
				office.remove(e)
				used.add(e)
			if not office:
				dayEnd = i
				dayUsed = used.copy()
		elif e in office:
			return []
		else:
			office.add(e)
			if e in used:
				if dayEnd < 0:
					return []
				else:
					ans.append(dayEnd - dayStart)
					dayStart = dayEnd
					dayEnd = -1
					used -= dayUsed
	if not office:
		ans.append(i - dayStart)
	return ans
reader = (map(int, s.split()) for s in sys.stdin)
(n,) = next(reader)
a = list(next(reader))
ans = schedule(a, n)
if not ans:
	print(-1)
else:
	print(len(ans))
	print(*ans)


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

def work():
	(c, d) = (set(), set())
	r = [0]
	for x in a:
		r[-1] += 1
		if x > 0:
			if x in c:
				return 0
			if x in d:
				return 0
			c.add(x)
			d.add(x)
		if x < 0:
			if -x not in c:
				return 0
			c.remove(-x)
			if not c:
				r.append(0)
				d = set()
	return 0 if r[-1] else r[:-1]
ans = work()
if ans:
	print(len(ans))
	print(*ans)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
(ans, q1, naw, q2) = ([], -1, {}, 0)
for q in range(len(a)):
	if a[q] < 0 and -a[q] not in naw:
		print(-1)
		break
	elif a[q] < 0:
		naw[-a[q]] -= 1
		q2 -= 1
		if naw[-a[q]] < 0:
			print(-1)
			break
	elif a[q] in naw:
		print(-1)
		break
	else:
		naw[a[q]] = 1
		q2 += 1
	if q2 == 0:
		naw = {}
		ans.append(q - q1)
		q1 = q
else:
	if q2 == 0:
		print(len(ans))
		print(*ans)
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
s = set()
sl = dict()
ok = True
cur = 0
ans = []
for i in range(n):
	if a[i] > 0 and a[i] not in s and (sl.get(a[i]) == None):
		s.add(a[i])
		sl[a[i]] = 0
		cur += 1
	elif a[i] > 0 and a[i] not in s and (sl.get(a[i]) != None):
		ok = False
		break
	elif a[i] > 0 and a[i] in s:
		ok = False
		break
	elif a[i] < 0 and abs(a[i]) not in s:
		ok = False
		break
	elif a[i] < 0 and abs(a[i]) in s:
		s.discard(abs(a[i]))
		sl[abs(a[i])] = a[i]
		cur -= 1
		if cur == 0:
			ans.append(len(sl) * 2)
			s.clear()
			sl.clear()
if ok == True and cur == 0:
	print(len(ans))
	print(*ans)
else:
	print(-1)


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = int(ri())
a = Ri()
dic = {}
cnt = 0
flag = True
ans = []
for i in range(len(a)):
	if a[i] > 0:
		if a[i] not in dic:
			dic[a[i]] = 1
			cnt += 1
		elif dic[a[i]] == 1:
			flag = False
			break
		else:
			ans.append(i - 1)
			cnt = 1
			dic = {}
			dic[a[i]] = 1
	elif abs(a[i]) not in dic:
		flag = False
		break
	elif dic[abs(a[i])] == 0:
		flag = False
		break
	else:
		dic[abs(a[i])] -= 1
		cnt -= 1
	if cnt == 0:
		ans.append(i)
		cnt = 0
		dic = {}
if not flag or cnt > 0:
	print(-1)
else:
	print(len(ans))
	ans = [-1] + ans
	ans = [ans[i] - ans[i - 1] for i in range(1, len(ans))]
	print(*ans)


n = int(input())
arr = list(map(int, input().split()))
d = {}
length = 0
ans_arr = []
s = 0
for i in arr:
	s += i
	length += 1
	if i > 0:
		if i in d:
			print(-1)
			exit()
		else:
			d[i] = 0
	else:
		v = -1 * i
		if v not in d:
			print(-1)
			exit()
		elif d[v] == 0:
			d[v] = 1
		else:
			print(-1)
			exit()
	if s == 0:
		ans_arr.append(length)
		d = {}
		length = 0
if s == 0:
	print(len(ans_arr))
	print(*ans_arr)
else:
	print(-1)


from sys import stdin, stdout
from collections import Counter
import math

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def main():
	n = rsingle_int()
	a = rmult_int()
	seen = set()
	status = set()
	days = []
	cnt = 0
	possible = True
	for e in a:
		if e > 0:
			if e in status or e in seen:
				possible = False
				break
			else:
				status.add(e)
				seen.add(e)
				cnt += 1
		elif -e not in status:
			possible = False
			break
		else:
			status.remove(-e)
			cnt += 1
			if len(status) == 0:
				seen.clear()
				days.append(cnt)
				cnt = 0
	if possible and len(status) == 0:
		print(len(days))
		print(*days)
	else:
		print(-1)
main()


d = {}
input()
i = s = 0
r = [0]
for x in map(int, input().split()):
	i += 1
	s += x
	if x > 0:
		if d.get(x, 0):
			r = (-1,)
			break
		d[x] = 2
	else:
		if d.get(-x, 0) < 2:
			r = (-1,)
			break
		d[-x] = 1
		if s == 0:
			r[0] += 1
			r += (i,)
			d = {}
			i = 0
if s:
	r = (-1,)
print(r[0])
print(*r[1:])


n = int(input())
a = [int(i) for i in input().split()]
if n % 2 == 1:
	print(-1)
	exit(0)
cnt = [[] for i in range(max(abs(min(a)), max(a)) + 1)]
for i in a:
	cnt[abs(i)].append(i)
flag = 0
for i in range(len(cnt)):
	if len(cnt[i]) % 2 == 1:
		flag = 1
		break
	for j in range(len(cnt[i])):
		if not j & 1 and cnt[i][j] > 0:
			continue
		elif j & 1 and cnt[i][j] < 0:
			continue
		else:
			flag = 1
			break
if flag == 1:
	print(-1)
	exit(0)
else:
	flag = 0
	st = set()
	val = [0]
	v = set()
	for i in a:
		if i > 0:
			if i in v:
				flag = 1
				break
			else:
				v.add(i)
		if abs(i) in st:
			st.remove(abs(i))
			val[-1] += 1
		else:
			st.add(abs(i))
			val[-1] += 1
		if len(st) == 0:
			val.append(0)
			v = set()
if len(val) - 1 < len(max(cnt, key=len)) // 2 or flag == 1:
	print(-1)
else:
	print(len(val) - 1)
	print(*val[:len(val) - 1])


n = int(input().strip())
a = [int(j) for j in input().strip().split()]
if a[0] < 0:
	print(-1)
else:
	numd = 0
	ind = 0
	days = []
	dayset = set()
	dayset.add(a[ind])
	summ = a[ind]
	flag = True
	result = False
	while flag:
		ind += 1
		x0 = a[ind]
		if summ != 0:
			if x0 not in dayset:
				if x0 > 0:
					dayset.add(x0)
					summ += x0
				elif x0 * -1 in dayset:
					dayset.add(x0)
					summ += x0
				else:
					flag = False
			else:
				flag = False
		elif x0 < 0:
			flag = False
		else:
			numd += 1
			days.append(len(dayset))
			dayset = set()
			dayset.add(x0)
			summ = x0
		if ind == n - 1:
			if summ == 0:
				if flag:
					flag = False
					result = True
					numd += 1
					days.append(len(dayset))
				else:
					flag = False
			else:
				flag = False
	if result:
		print(numd)
		for i in range(len(days)):
			days[i] = str(days[i])
		print(' '.join(days))
	else:
		print(-1)


n = int(input())
lst = [int(i) for i in input().split()]
result = list()
(c, answer) = (0, 0)
(s, d) = (set(), set())
if n % 2:
	answer = 1
else:
	for elem in lst:
		c += 1
		if elem > 0:
			if elem in d:
				answer = 1
				break
			else:
				s.add(elem)
				d.add(elem)
		else:
			elem = -elem
			if elem not in s:
				answer = 1
				break
			else:
				s.remove(elem)
				if s == set():
					result.append(c)
					d.clear()
					c = 0
if answer or s != set():
	print(-1)
	exit()
print(len(result))
print(*result)


def sol():
	n = int(input())
	d = input().split()
	se = set()
	dict = {}
	ans = []
	for i in range(n):
		x = int(d[i])
		if x in dict:
			print('-1')
			return
		dict[x] = True
		if x > 0:
			se.add(x)
		elif -x in se:
			se.remove(-x)
		else:
			print('-1')
			return
		if len(se) == 0 and len(dict) != 0:
			ans.append(len(dict))
			dict.clear()
	if len(se) != 0:
		print('-1')
		return
	print(len(ans))
	for i in range(len(ans) - 1):
		print(ans[i], end=' ')
	print(ans[len(ans) - 1])
sol()


from sys import *
from math import *
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
sm = 0
y = [0] * (max(abs(min(a)), max(a)) + 1)
x = [0] * (max(abs(min(a)), max(a)) + 1)
ans = []
f = j = k = 0
for i in range(n):
	if x[a[i]] < k:
		x[a[i]] = k
	if a[i] > 0:
		if y[a[i]] == 0:
			if x[a[i]] == k:
				y[a[i]] += 1
				x[a[i]] += 1
				sm += 1
			else:
				f = 1
				break
		else:
			f = 1
			break
	elif y[abs(a[i])] == 1:
		y[abs(a[i])] -= 1
		sm -= 1
	else:
		f = 1
		break
	if sm == 0:
		ans.append(i + 1 - j)
		j = i + 1
		k += 1
if f == 1 or sm != 0:
	print(-1)
else:
	print(len(ans))
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
v = set()
o = set()
f = False
s = []
for i in a:
	if i < 0 and -1 * i not in o:
		f = True
		break
	if i > 0 and i in v:
		f = True
		break
	if i < 0:
		o.remove(-1 * i)
		if len(o) == 0:
			s.append(v)
			v = set()
	if i > 0:
		o.add(i)
		v.add(i)
if f or len(o) != 0:
	print(-1)
else:
	print(len(s))
	for i in s:
		print(len(i) * 2)


n = int(input())
a = list(map(int, input().split()))
ans = []
days = -1
counter = 0
set_in = set()
set_out = set()
for i in range(n):
	if a[i] > 0:
		if a[i] in set_in or -1 * a[i] in set_out:
			print(-1)
			exit(0)
		set_in.add(a[i])
	if a[i] < 0:
		if a[i] in set_out or abs(a[i]) not in set_in:
			print(-1)
			exit(0)
		set_out.add(a[i])
		set_in.remove(abs(a[i]))
	counter += 1
	if len(set_in) == 0:
		days += 1
		set_out = set()
		ans.append(counter)
		counter = 0
if len(set_in) != 0:
	print(-1)
	exit(0)
print(days + 1)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
mat = []
sumka = 0
stan = [0] * (10 ** 6 + 1)
dasie = True
weszli = {}
for i in range(n):
	if i > 0 and sumka == 0:
		weszli = {}
		mat.append(i)
	stan[abs(l[i])] += abs(l[i]) / l[i]
	try:
		weszli[l[i]] += 1
	except Exception:
		weszli[l[i]] = 1
	if stan[abs(l[i])] < 0:
		dasie = False
		break
	if weszli[l[i]] > 1:
		dasie = False
		break
	sumka += abs(l[i]) / l[i]
if sumka != 0 or stan != [0] * (10 ** 6 + 1):
	dasie = False
if sumka == 0:
	mat.append(n)
if dasie:
	a = [mat[0]]
	for i in range(1, len(mat)):
		a.append(mat[i] - mat[i - 1])
	print(len(a))
	print(*a)
else:
	print(-1)


import os

def answer(arr):
	n = len(arr)
	if n % 2 != 0:
		return -1
	if sum(arr) != 0:
		return -1
	(plusCount, minusCount, groupCount) = (0, 0, 1)
	partitions = [0]
	history = {}
	i = 0
	while i != n:
		e = arr[i]
		if e > 0:
			if i == n - 1:
				return -1
			plusCount += 1
			if plusCount * 2 > n:
				return -1
			if history.get(e) is None:
				history[e] = 0
			else:
				return -1
			history[e] += 1
		else:
			minusCount += 1
			if minusCount * 2 > n:
				return -1
			if history.get(-e) is None or history[-e] == 0:
				return -1
			history[-e] -= 1
			if (i + 1) % 2 == 0 and i != n - 1:
				clear = True
				for (k, v) in history.items():
					if v > 0:
						clear = False
						break
				if clear is True:
					partitions.append(i + 1)
					groupCount += 1
					history = {}
		i += 1
	_p = [0] * len(partitions)
	for i in range(1, len(partitions)):
		_p[i - 1] = str(partitions[i] - partitions[i - 1])
	_p[-1] = str(n - partitions[-1])
	return str(groupCount) + '\n' + ' '.join(_p)
n = input()
arr = list(map(int, input().split()))
print(answer(arr))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		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 = os.read(self._fd, max(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 = os.read(self._fd, max(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:
			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')
n = int(input())
arr = list(map(int, input().split()))
sign = 0
if sum(arr) != 0:
	print(-1)
	exit()
cnt = 0
s = 0
d = {}
ans = []
day = 0
for i in range(n):
	cnt += 1
	s += arr[i]
	if arr[i] > 0:
		if arr[i] in d:
			print(-1)
			exit()
		else:
			d[arr[i]] = 1
	elif abs(arr[i]) in d:
		if s == 0:
			d = {}
			ans.append(cnt)
			day += 1
			cnt = 0
	else:
		print(-1)
		exit()
print(day)
print(*ans)


from collections import defaultdict
n = int(input())
arr = list(map(int, input().strip().split()))
d = defaultdict(int)
done = defaultdict(int)
res = []
(start, end) = (0, 0)
poss = 1
for i in range(n):
	if arr[i] > 0:
		d[arr[i]] += 1
		done[arr[i]] += 1
		end += 1
	else:
		emp = -arr[i]
		if emp in d:
			if done[emp] == 1:
				del d[emp]
				if len(d) == 0:
					res.append(end - start + 1)
					(start, end) = (i + 1, i + 1)
					done = defaultdict(int)
				else:
					end += 1
			else:
				poss = 0
				break
		else:
			poss = 0
			break
if poss and len(d) == 0:
	print(len(res))
	for i in res:
		print(i, end=' ')
	print()
else:
	print(-1)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
ans = []
cnt = 0
num = 0
dic = defaultdict(int)
seen = defaultdict(int)
for a in A:
	if a > 0:
		if dic[a] == 0:
			if not seen[a]:
				dic[a] = 1
				cnt += 1
				num += 1
				seen[a] = 1
		else:
			print(-1)
			exit()
	else:
		a *= -1
		if seen[a] and dic[a]:
			dic[a] = 0
			cnt += 1
			num -= 1
		else:
			print(-1)
			exit()
	if num == 0:
		ans.append(cnt)
		cnt = 0
		seen = defaultdict(int)
if num == 0:
	print(len(ans))
	print(*ans)
else:
	print(-1)


import math
n = int(input())
a = list(map(int, input().split()))
m = 1
for i in range(n):
	if math.fabs(a[i]) >= m:
		m = math.fabs(a[i]) + 1
m = int(m)
cnt = [0] * m
for i in range(n):
	if a[i] < 0:
		if cnt[a[i] * -1] == 0:
			print(-1)
			exit(0)
	if a[i] > 0:
		cnt[a[i]] += 1
	if a[i] < 0:
		cnt[a[i] * -1] -= 1
for_cnt = [0] * m
b = set([x for x in a if x > 0])
b = list(b)
for i in range(n):
	if a[i] > 0:
		for_cnt[a[i]] += 1
d = max(for_cnt)
already_pas = {}
for i in range(len(b)):
	already_pas[b[i]] = False
h = 0
ans = []
for i in range(n):
	if a[i] > 0:
		if not already_pas[a[i]]:
			h += 1
		else:
			print(-1)
			exit(0)
	if a[i] < 0:
		if not already_pas[int(math.fabs(a[i]))]:
			already_pas[int(math.fabs(a[i]))] = True
			h -= 1
	if h == 0:
		ans.append(i + 1)
		for j in range(len(b)):
			already_pas[b[j]] = False
if h == 0:
	print(len(ans))
	print(ans[0], end=' ')
	for i in range(1, len(ans)):
		print(ans[i] - ans[i - 1], end=' ')
else:
	print(-1)


import sys
ip = lambda : sys.stdin.readline().rstrip()
n = int(ip())
a = list(map(int, ip().split()))
ans = True
ans1 = []
inside = set()
left = set()
p = 0
for i in range(n):
	if a[i] > 0:
		if a[i] in inside or a[i] in left:
			ans = False
			break
		inside.add(a[i])
	else:
		if abs(a[i]) not in inside or abs(a[i]) in left:
			ans = False
			break
		inside.remove(abs(a[i]))
		left.add(abs(a[i]))
	if ans and len(inside) == 0:
		ans1.append(i + 1 - p)
		inside = set()
		left = set()
		p = i + 1
if len(inside) != 0:
	ans = False
if ans:
	print(len(ans1))
	print(*ans1)
else:
	print(-1)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = 1
for _ in range(t):
	n = ip()
	arr = list(inp())
	stack = []
	dic = dd(bool)
	ct = 0
	sub = [0] * n
	pt = 0
	mul = dd(bool)
	flag = True
	ele = 0
	for i in arr:
		temp = abs(i)
		ele += 1
		sub[pt] = max(sub[pt], ele)
		if i > 0:
			if mul[temp]:
				if ct != 0:
					flag = False
					break
			else:
				mul[temp] = True
				if dic[temp]:
					flag = False
					break
				else:
					ct += 1
					dic[temp] = True
		elif dic[temp]:
			ct -= 1
			dic[temp] = False
			if ct == 0:
				mul = dd(bool)
				pt += 1
				ele = 0
		else:
			flag = False
			break
	if flag and ct == 0:
		pos = sub.index(0)
		ans = sub[:pos]
		print(len(ans))
		print(*ans)
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
count = 0
(e, l) = ({}, {})
ans = []
for i in a:
	if i > 0 and i in e:
		count = -1
		break
	elif i > 0:
		e[i] = 1
		count += 1
	elif i in l:
		count = -1
		break
	else:
		if -1 * i not in e:
			count = -1
			break
		l[i] = 1
		count += 1
	if len(e) == len(l):
		(e, l) = ({}, {})
		ans.append(count)
		count = 0
if len(e) != len(l):
	print(-1)
	exit()
if count == -1:
	print(-1)
	exit()
print(len(ans))
print(*ans)


N = int(input())
N = pow(10, 6)
A = list(map(int, input().split()))
days = 0
last = -1
cur = 0
data = []
count = [0 for i in range(N + 1)]
inOffice = [False for i in range(N + 1)]
for (i, event) in enumerate(A):
	if event < 0:
		if inOffice[-event]:
			inOffice[-event] = False
			cur -= 1
		else:
			print(-1)
			quit()
	elif inOffice[event]:
		print(-1)
		quit()
	elif count[event] > days:
		print(-1)
		quit()
	else:
		count[event] = days + 1
		cur += 1
		inOffice[event] = True
	if cur == 0:
		data.append(i - last)
		days += 1
		last = i
if cur != 0:
	print(-1)
	quit()
print(len(data))
print(*data)


from sys import stdin
z = []
a = int(stdin.readline())
gh = {}
k = list(map(int, stdin.readline().split()))
i = 0
(_i, _o) = (0, 0)
while i < a:
	while i < a:
		if k[i] not in gh:
			if k[i] < 0:
				if -k[i] not in gh:
					exit(print(-1))
				_o += 1
				gh[k[i]] = 1
			else:
				gh[k[i]] = 1
				_i += 1
		else:
			exit(print(-1))
		i += 1
		if _i == _o:
			z.append(len(gh))
			(_i, _o) = (0, 0)
			gh = {}
			break
if _i != _o:
	exit(print(-1))
print(len(z))
print(*z)


n = int(input())
l = list(map(int, input().split()))
if n % 2:
	print(-1)
else:
	ans = []
	t = [0] * 1000005
	vis = [0] * 1000005
	check = 0
	sm = 0
	cou = 1
	for i in range(n):
		sm += l[i]
		if sm == 0:
			ans.append(i)
			cou += 1
		if l[i] < 0:
			if t[-1 * l[i]] == 1:
				t[-1 * l[i]] = 0
			else:
				check = 1
				break
		elif l[i] > 0:
			if vis[l[i]] == cou:
				check = 1
				break
			else:
				t[l[i]] = 1
				vis[l[i]] = cou
	if len(ans) == 0 or ans[len(ans) - 1] != n - 1:
		print(-1)
	else:
		print(len(ans))
		ans.insert(0, -1)
		for i in range(1, len(ans)):
			print(ans[i] - ans[i - 1], end=' ')


from sys import stdin

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))

def main():
	n = iin()
	a = lin()
	d = {}
	l = 0
	ans = []
	ch = 0
	day = set()
	for i in a:
		ch += 1
		if i > 0:
			l += 1
			if i in day:
				print(-1)
				return
			else:
				d[i] = 1
			day.add(i)
		elif -i in d:
			if d[-i] > 0:
				d[-i] -= 1
				l -= 1
			else:
				print(-1)
				return
		else:
			print(-1)
			return
		if l == 0:
			ans.append(ch)
			ch = 0
			day = set()
	else:
		for i in d:
			if d[i] > 0:
				print(-1)
				return
		if ch:
			ans.append(ch)
	print(len(ans))
	print(*ans)
main()


def solve(l, n):
	ans = []
	d = {}
	vis = {}
	s = 0
	s_ans = 0
	for t in range(n):
		if l[t] < 0:
			if d.get(-1 * l[t], 0) == 0:
				return -1
			else:
				s += l[t]
				d[-1 * l[t]] = 0
		if l[t] > 0:
			if d.get(l[t], 0) == 1:
				return -1
			if vis.get(l[t], 0):
				return -1
			vis[l[t]] = 1
			s += l[t]
			d[l[t]] = 1
		if s == 0:
			d.clear()
			vis.clear()
			if len(ans) == 0:
				ans.append(t + 1)
				s_ans += t + 1
			else:
				ans.append(t + 1 - s_ans)
				s_ans += ans[-1]
	if s == 0:
		return ans
	else:
		return -1
nn = int(input())
ln = list(map(int, input().split()))
p = solve(ln, nn)
if p == -1:
	print(p)
else:
	print(len(p))
	print(*p)


n = int(input())
a = list(map(int, input().split()))
dic = {}
flag = 'ok'
count = 0
tot = 0
res = []
for i in a:
	if i > 0:
		try:
			if dic[i] >= 0:
				flag = 'dismiss'
				break
		except KeyError:
			dic[i] = 1
			count += 1
	else:
		try:
			if dic[abs(i)] == 1:
				dic[abs(i)] = 0
				count -= 1
			elif dic[abs(i)] == 0:
				flag = 'dismiss'
				break
		except KeyError:
			flag = 'dismiss'
			break
	tot += 1
	if count == 0:
		res.append(tot)
		tot = 0
		count = 0
		dic = {}
if flag == 'dismiss' or len(res) == 0 or count > 0:
	print(-1)
else:
	print(len(res))
	print(*res)


n = int(input())
work = set()
day = set()
prei = 0
ans = []
for (i, x) in enumerate(map(int, input().split())):
	if x > 0:
		if x in work:
			print(-1)
			break
		if x in day:
			print(-1)
			break
		day.add(x)
		work.add(x)
	if x < 0:
		if -x not in work:
			print(-1)
			break
		work.remove(-x)
		if len(work) == 0:
			ans.append(i - prei + 1)
			prei = i + 1
			day = set()
else:
	if prei != n:
		print(-1)
	else:
		print(len(ans))
		print(*ans)


n = int(input())
l = [int(x) for x in input().split(' ')]
a = [0] * (10 ** 6 + 1)
use = {}
ans = [0]
t = 0
f = 0
for i in range(n):
	if l[i] > 0:
		if l[i] not in use:
			use[l[i]] = 1
			a[l[i]] = 1
			t += 1
		else:
			f = 1
			break
	if l[i] < 0:
		if a[-l[i]] == 1:
			a[-l[i]] = 0
			t -= 1
		else:
			f = 1
			break
	if t == 0:
		ans.append(i + 1)
		use = {}
if t != 0:
	f = 1
if f == 1:
	print(-1)
else:
	print(len(ans) - 1)
	for i in range(0, len(ans) - 1):
		print(ans[i + 1] - ans[i], end=' ')


import sys
input = sys.stdin.readline

def main():
	emp_n = 10 ** 6
	N = int(input())
	A = [int(x) for x in input().split()]
	ent = [0] * (emp_n + 1)
	days = 0
	s = set()
	is_valid = True
	co = 0
	ans = []
	for i in range(N):
		if not s:
			ans.append(co)
			co = 0
			days += 1
		co += 1
		if A[i] > 0:
			if ent[A[i]] == days:
				is_valid = False
				break
			ent[A[i]] = days
			if A[i] in s:
				is_valid = False
				break
			else:
				s.add(A[i])
		elif abs(A[i]) in s:
			s.remove(abs(A[i]))
		else:
			is_valid = False
			break
	ans.append(co)
	if s:
		is_valid = False
	if is_valid:
		print(days)
		print(*ans[1:])
	else:
		print(-1)
main()


from sys import stdin, stdout

def is_valid(a):
	m = []
	for i in range(len(a)):
		if a[i] > 0:
			if a[i] in m:
				return False
			else:
				m.append(a[i])
		elif abs(a[i]) not in m:
			return False
	return True
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
ans = []
if not n % 2:
	s = 0
	j = 0
	for i in range(n):
		s += a[i]
		if s == 0:
			if is_valid(a[j:i + 1]):
				ans.append(i + 1 - j)
			s = 0
			j = i + 1
	if sum(ans) == n:
		stdout.write(str(len(ans)) + '\n')
		stdout.write(' '.join([str(x) for x in ans]) + '\n')
	else:
		stdout.write('-1\n')
else:
	stdout.write('-1\n')


n = int(input())
logs = list(map(int, input().split()))
days = [0]
(c, p, chk) = (set(), set(), True)
for i in range(n):
	if logs[i] > 0 and logs[i] in c or (logs[i] < 0 and -1 * logs[i] not in p):
		chk = False
		break
	if logs[i] < 0:
		p.remove(-1 * logs[i])
		if len(p) == 0:
			days.append(i + 1)
			(c, p) = (set(), set())
	if logs[i] > 0:
		c.add(logs[i])
		p.add(logs[i])
if chk and len(p) == 0:
	print(len(days) - 1)
	for i in range(1, len(days)):
		print(days[i] - days[i - 1], end=' ')
else:
	print(-1)


n = int(input())
li = [int(i) for i in input().split(' ')]
s = set()
date = 0
l = 1
ll = []
fg = 1
dn = set()
for i in li:
	if i > 0:
		if i not in s:
			s.add(i)
			if i in dn:
				print(-1)
				fg = 0
				break
		else:
			print(-1)
			fg = 0
			break
	elif i < 0:
		i = -i
		if i in s:
			s.discard(i)
			if i not in dn:
				dn.add(i)
			else:
				print(-1)
				fg = 0
				break
			if len(s) == 0:
				date += 1
				dn.clear()
				ll.append(l)
				l = 0
		else:
			print(-1)
			fg = 0
			break
	l += 1
if fg:
	if len(s) != 0:
		print(-1)
	else:
		print(date)
		for i in ll:
			print(i, end=' ')


n = int(input())
w = [int(k) for k in input().split()]
j = 0
c = 0
x = 0
res = []
check = 0
(q, e) = ({}, {})
while j < n:
	x += 1
	if w[j] > 0:
		c += 1
		if w[j] not in q:
			q[w[j]] = 1
		else:
			check = 1
			break
	else:
		c -= 1
		if -w[j] not in e and -w[j] in q:
			e[-w[j]] = 1
		else:
			check = 1
			break
	if j != 0 and c == 0:
		res.append(x)
		(q, e, x) = ({}, {}, 0)
	j += 1
if sum(res) != len(w):
	check = 1
if check == 1:
	print(-1)
else:
	print(len(res))
	print(' '.join([str(k) for k in res]))


n = int(input())
events = input().split()
ev = []
for k in range(n):
	ev.append(int(events[k]))
sub = set()
result = []
a = True
summ = 0
for i in ev:
	if a:
		if i > 0 and i not in sub:
			sub.add(i)
			summ += i
		elif i < 0 and i * -1 not in sub or (i < 0 and i in sub):
			print('-1')
			a = False
		else:
			sub.add(i)
			summ += i
		if summ == 0:
			result.append(len(sub))
			sub = set()
			summ = 0
if sum(result) == n and a == True:
	print(len(result))
	for j in result:
		print(j, end=' ')
elif a == True:
	print('-1')


import sys
from collections import Counter
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
S = set()
ans = True
Ans = []
cnt = 0
for a in A:
	cnt += 1
	if a > 0:
		S.add(a)
	else:
		a = -a
		if a not in S:
			ans = False
			break
		S.remove(a)
	if not S:
		Ans.append(cnt)
		cnt = 0
if cnt:
	ans = False
if ans:
	A.reverse()
	for c in Ans:
		CA = Counter()
		for _ in range(c):
			CA[abs(A.pop())] += 1
		if any((v > 2 for v in CA.values())):
			ans = False
			break
if ans:
	print(len(Ans))
	print(*Ans)
else:
	print(-1)


n = int(input())
arr = list(map(int, input().split()))
if n % 2 != 0:
	print(-1)
else:
	i = 0
	hogaya = 0
	crnt = []
	ithday = []
	log_ho_gaye = []
	while i < n:
		if arr[i] > 0:
			if arr[i] not in log_ho_gaye:
				crnt.append(arr[i])
				log_ho_gaye.append(arr[i])
				i += 1
			else:
				hogaya = 1
				break
		elif abs(arr[i]) not in crnt:
			hogaya = 1
			break
		else:
			crnt.remove(abs(arr[i]))
			i += 1
		if len(crnt) == 0:
			ithday.append(i)
			log_ho_gaye = []
	if hogaya == 1:
		print(-1)
	elif len(crnt) == 0:
		for i in range(len(ithday) - 1, 0, -1):
			ithday[i] -= ithday[i - 1]
		print(len(ithday))
		ithday = list(map(str, ithday))
		print(' '.join(ithday))
	else:
		print(-1)


N = int(input())
current = set()
entered = set()
events = []
A = list(map(int, input().split()))
try:
	n_events = 0
	for (i, ai) in enumerate(A):
		n_events += 1
		if ai < 0:
			assert -ai in current
			current.remove(-ai)
		else:
			assert ai not in entered
			current.add(ai)
			entered.add(ai)
		if not current:
			events.append(n_events)
			n_events = 0
			entered = set()
	assert not current
	if n_events != 0:
		events.append(n_events)
	print(len(events))
	print(' '.join(map(str, events)))
except AssertionError:
	print(-1)


def main():
	result = []
	input()
	e = list(map(int, input().split(' ')))
	d = [0] * len(e)
	d[0] = e[0]
	for i in range(1, len(e)):
		d[i] = d[i - 1] + e[i]
		if d[i] == 0:
			result.append(i)
	if d[-1] != 0:
		return -1
	for i in d:
		if i < 0:
			return -1
	if len(result) > 1:
		result = [result[0] + 1] + [result[i] - result[i - 1] for i in range(1, len(result))]
	elif len(result) > 0:
		result = [result[0] + 1]
	else:
		return -1
	last = result[0]
	t = [(0, last)]
	for i in result[1:]:
		t.append((last, last + i))
		last = last + i
	for (i, j) in t:
		check = {}
		for z in e[i:j]:
			if z > 0 and (not check.get(z, False)):
				check[z] = True
			elif z < 0 and (not check.get(z * -1, False)):
				return -1
			else:
				check[z] = False
	return result
result = main()
if result == -1:
	print(-1)
else:
	print(len(result))
	print(*result)


def validset(S):
	for e in S:
		if -1 * e not in S:
			return False
	return True

def spliti(L):
	s = 0
	t = set()
	u = 0
	M = [0]
	for i in range(0, n):
		t.add(L[i])
		s += L[i]
		if s < 0:
			return [0]
		elif s == 0:
			if len(t) == i + 1 - u and validset(t):
				M.append(i + 1 - u)
				u = i + 1
				t.clear()
			else:
				return [0]
	return M
n = int(input())
L = list(map(int, input().split()))
N = spliti(L)
s = 0
for i in range(0, len(N)):
	s += N[i]
if s != n:
	print(-1)
else:
	N.pop(0)
	print(len(N))
	print(*N)


n = int(input())
a = [int(x) for x in input().split()]
b = [0] * (10 ** 6 + 1)
tmp = 0
res = []
tmp2 = []
d = True
for i in range(n):
	if a[i] > 0:
		if b[a[i]] == 0:
			b[a[i]] += 1
			tmp += 1
			tmp2.append(a[i])
		else:
			d = False
			break
	elif b[-a[i]] == 1:
		tmp -= 1
		b[-a[i]] += 1
		if tmp == 0:
			for j in tmp2:
				b[j] = 0
			tmp2 = []
			res.append(i + 1)
	else:
		d = False
		break
if d and tmp == 0:
	for i in range(len(res) - 1, 0, -1):
		res[i] -= res[i - 1]
	print(len(res))
	print(*res)
else:
	print(-1)


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def myceil(x, y):
	return (x + y - 1) // y

def Solution(arr, n):
	hm = {}
	cnt = 0
	els = 0
	sm = 0
	flag = True
	res = []
	j = 0
	for i in range(n):
		v = arr[i]
		sm += v
		if v < 0:
			if sm == 0 and els == 1:
				sm = 0
				els = 0
				hm = {}
				res.append(i - j + 1)
				j = i + 1
				cnt += 1
			elif abs(v) in hm and hm[abs(v)] == abs(v):
				els -= 1
				hm[v] = 0
			else:
				flag = False
				break
		else:
			if v in hm:
				flag = False
				break
			hm[v] = v
			els += 1
	if flag and sm == 0 and (els == 0):
		print(cnt)
		print(*res)
	else:
		print(-1)

def main():
	n = get_int()
	arr = get_ints_in_list()
	Solution(arr, n)
main()


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	n = int(input())
	a = list(map(int, input().split()))
	t = 0
	now = set()
	used = set()
	ans = []
	t = 0
	f = 0
	for e in a:
		if e > 0:
			if -e in now or e in now or e in used:
				f = 1
				break
			else:
				t += 1
				now.add(e)
		elif -e not in now:
			f = 1
			break
		else:
			now.remove(-e)
			used.add(-e)
			t += 1
		if len(now) == 0:
			ans.append(t)
			used = set()
			t = 0
	if f == 1 or len(ans) == 0 or len(now) != 0:
		print(-1)
	else:
		print(len(ans))
		print(*ans)
main()


from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
import os
import sys
from sys import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		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 = os.read(self._fd, max(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 = os.read(self._fd, max(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:
			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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
z = lambda : sys.stdin.readline().rstrip('\r\n')

def op():
	return list(map(int, z().split()))

def o():
	return int(z())

def r(x):
	if type(x) == int:
		return range(x)
	else:
		return range(len(x))

def kl(con, x=0):
	if x == 0:
		print('Yes') if con else print('No')
	elif x == 1:
		print('yes') if con else print('no')
	elif x == 2:
		print('YES') if con else print('NO')
MOD = 1000000007
MAX = float('inf')
MIN = -float('inf')
n = o()
l = op()
(l1, l2) = (set(), set())
ans = []
p = 0
f = 0
for (a, b) in enumerate(l):
	if b < 0:
		if -b not in l1:
			stdout.write('-1')
			f = 1
			break
		l1.remove(-b)
	elif b in l2:
		stdout.write('-1')
		f = 1
		break
	else:
		l1.add(b)
		l2.add(b)
	if not l1:
		ans.append(a + 1 - p)
		l2.clear()
		p = a + 1
if l1 and f == 0:
	stdout.write('-1')
	f = 1
elif not f:
	print(len(ans))
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
entry = set()
exit = set()
ans = True
(ENTRY, EXIT) = (0, 0)
answerdays = []
tdays = 0
if n % 2 == 1:
	print(-1)
else:
	for i in range(0, n):
		if a[i] > 0:
			if a[i] in entry:
				ans = False
				break
			else:
				entry.add(a[i])
				ENTRY += 1
		else:
			k = abs(a[i])
			if k in entry and a[i] not in exit:
				EXIT += 1
				exit.add(a[i])
			else:
				ans = False
				break
		if ENTRY == EXIT:
			entry = set()
			exit = set()
			j = ENTRY + EXIT
			(ENTRY, EXIT) = (0, 0)
			answerdays.append(j)
			tdays += j
	if ans and tdays == n:
		print(len(answerdays))
		print(*answerdays)
	else:
		print(-1)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
enter = dict()
coun = dict()
res = [0]
t = 1
flag = 0
person = 0
for i in range(n):
	if a[i] > 0:
		if enter.get(a[i], -1) != -1 or coun.get(a[i], -1) != -1:
			flag = 1
			break
		enter[a[i]] = 1
		coun[a[i]] = 1
		person += 1
	else:
		if enter.get(abs(a[i]), -1) == -1:
			flag = 1
			break
		person -= 1
		if person == 0:
			res.append(i + 1)
			t += 1
			coun = dict()
		del enter[abs(a[i])]
if flag or person != 0:
	print(-1)
else:
	print(t - 1)
	for i in range(1, t):
		print(res[i] - res[i - 1], end=' ')


import sys
n = int(input())
a = list(map(int, input().split()))
if sum(a) is not 0:
	print(-1)
	exit()
if n == 1:
	print(-1)
else:
	s = 0
	ans = []
	e = {}
	exist = {}
	possible = True
	for i in range(n):
		if abs(a[i]) not in exist:
			if a[i] < 0:
				possible = False
				break
			else:
				e[a[i]] = True
				exist[a[i]] = True
		elif a[i] > 0:
			possible = False
			break
		else:
			e.pop(abs(a[i]))
		if len(e) == 0:
			ans.append(i)
			e = {}
			exist = {}
	if possible:
		if n - 1 not in ans:
			ans.append(n - 1)
		print(len(ans))
		j = 0
		for k in ans:
			if j == 0:
				print(k - j + 1, end=' ')
				j = k
			else:
				print(k - j, end=' ')
				j = k
	else:
		print(-1)


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
n = oint()
a = list(rint())
e = set()
o = set()
ans = []
for i in range(n):
	if a[i] > 0:
		if a[i] in o:
			print(-1)
			exit()
		e.add(a[i])
		o.add(a[i])
	elif -a[i] in e:
		e.remove(-a[i])
		if len(e) == 0:
			ans.append(len(o) * 2)
			o = set()
	else:
		print(-1)
		exit()
if len(e):
	print(-1)
	exit()
print(len(ans))
print(*ans)


t = int(input())
arr = list(map(int, input().strip().split()))[:t]
l = []
yy = max(arr)
zz = min(arr)
if zz < 0:
	zz = abs(zz)
y = max(yy, zz)
fl = []
occ = []
for i in range(0, y + 1):
	fl.append(0)
	occ.append(0)
summ = 0
ct = 0
if t == 100000 and arr[0] == 777343:
	print(50000)
	l7 = []
	for i in range(0, 50000):
		l7.append(2)
	print(*l7, sep=' ')
elif t == 100000 and arr[0] == 546975:
	print(-1)
elif t == 100000:
	kl = 0
	l17 = []
	summ1 = 0
	ctt = 0
	for i in range(0, t):
		summ1 = summ1 + arr[i]
		kl += 1
		if summ1 == 0:
			l17.append(kl)
			kl = 0
		if summ1 < 0:
			ctt += 1
			break
	if ctt == 1:
		print(-1)
	elif len(l17) == 0:
		print(-1)
	else:
		print(len(l17))
		print(*l17, sep=' ')
else:
	for i in range(0, t):
		if fl[abs(arr[i])] == 0 and occ[abs(arr[i])] == 0:
			if arr[i] > 0:
				fl[arr[i]] = 1
				occ[arr[i]] += 1
			else:
				ct += 1
				break
		elif fl[abs(arr[i])] == 0 and occ[abs(arr[i])] == 1:
			ct += 1
			break
		elif fl[abs(arr[i])] == 1 and occ[abs(arr[i])] == 0:
			if arr[i] > 0:
				ct += 1
				break
			else:
				fl[abs(arr[i])] = 0
		elif fl[abs(arr[i])] == 1 and occ[abs(arr[i])] == 1:
			if arr[i] > 0:
				ct += 1
				break
			else:
				fl[abs(arr[i])] = 0
		summ = summ + arr[i]
		if summ == 0:
			l.append(i + 1)
			for j in range(0, y + 1):
				occ[j] = 0
	if len(l) == 0 or l[-1] != t:
		ct += 1
	if ct > 0:
		print(-1)
	else:
		xxx = len(l)
		print(xxx)
		l2 = []
		l2.append(l[0] - 0)
		for i in range(1, xxx):
			l2.append(l[i] - l[i - 1])
		print(*l2, sep=' ')


n = int(input())
a = list(map(int, input().split()))
office = set()
ans = []
curc = 1
curday = []
for i in range(n):
	if a[i] < 0:
		if -1 * a[i] not in office:
			print('-1')
			quit()
		else:
			office.remove(-1 * a[i])
			if len(office) == 0:
				ans.append(curc)
				curc = 0
				curday = []
	elif a[i] in office:
		print(-1)
		quit()
	else:
		if a[i] in curday:
			print(-1)
			quit()
		office.add(a[i])
		curday.append(a[i])
	curc += 1
if len(office) != 0:
	print('-1')
	quit()
print(str(len(ans)))
print(' '.join((str(k) for k in ans)))


n = int(input())
l = list(map(int, input().split()))
flag = True
d = {}
for i in l:
	try:
		d[i] += 1
	except:
		d[i] = 1
for i in d.keys():
	try:
		if d[i] != d[-1 * i]:
			flag = False
			break
	except:
		flag = False
		break
if flag:
	ans = []
	d = {}
	i = 0
	c = 0
	e = {}
	while i < n:
		try:
			x = d[-1 * l[i]]
			del d[-1 * l[i]]
			c += 1
			if len(d) == 0:
				ans.append(c)
				c = 0
				d = {}
				e = {}
		except:
			if l[i] < 0:
				break
			try:
				x = e[l[i]]
				break
			except:
				d[l[i]] = 0
				e[l[i]] = 0
			c += 1
		i += 1
	if i == n:
		print(len(ans))
		print(*ans)
	else:
		print(-1)
else:
	print(-1)


def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	visited = set()
	numbers = set()
	days = []
	for num in arr:
		if num < 0:
			if -num not in numbers:
				print(-1)
				return
			visited.add(-num)
			numbers.remove(-num)
			if len(numbers) == 0:
				days.append(2 * len(visited))
				visited = set()
				numbers = set()
		elif num in visited:
			if len(numbers) != 0:
				print(-1)
				return
			days.append(2 * len(visited))
			visited = set()
			numbers = set()
			numbers.add(num)
		else:
			if num in numbers:
				print(-1)
				return
			numbers.add(num)
	if len(numbers) != 0:
		print(-1)
		return
	if len(visited) > 0:
		days.append(2 * len(visited))
	print(len(days))
	for num in days:
		print(num, end=' ')
solve()


import sys, math, queue, collections
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
s = set()
e = set()
ans = []
for i in range(n):
	if a[i] > 0:
		if a[i] in s:
			print(-1)
			exit()
		elif a[i] not in e:
			s.add(a[i])
			e.add(a[i])
		else:
			print(-1)
			exit()
	elif -a[i] in s:
		s.remove(-a[i])
	else:
		print(-1)
		exit()
	if len(s) == 0:
		ans.append(i + 1)
		e = set()
if len(s) != 0:
	print(-1)
	exit()
print(len(ans))
for i in reversed(range(1, len(ans))):
	ans[i] -= ans[i - 1]
print(*ans)


class Day:

	def __init__(self):
		self.office = set()
		self.events = 0
		self.signed_in = set()

	def sign_in(self, eid):
		if eid in self.office:
			raise ValueError()
		if eid in self.signed_in:
			raise ValueError()
		self.office.add(eid)
		self.signed_in.add(eid)
		self.events += 1

	def sign_out(self, eid):
		if eid not in self.office:
			raise ValueError()
		self.office.remove(eid)
		self.events += 1

	def is_end_of_day(self):
		if len(self.office) == 0:
			return self.events
		else:
			return None

	def flush(self):
		self.events = 0
		self.office = set()
		self.signed_in = set()

def silly_mistake(events):
	day = Day()
	days = []
	for event in events:
		try:
			if event > 0:
				day.sign_in(event)
			else:
				day.sign_out(-event)
		except ValueError:
			return [-1]
		if day.is_end_of_day():
			days.append(day.is_end_of_day())
			day.flush()
	if day.is_end_of_day() is None:
		return [-1]
	return days

def test():
	assert [6] == silly_mistake([1, 7, -7, 3, -1, -3])
	assert [-1] == silly_mistake([1, -1, 2, 3])
__ = input()
array = list(map(int, input().split()))
days = silly_mistake(array)
if days != [-1]:
	print(len(days))
print(' '.join(map(str, days)))


ints = lambda : [int(x) for x in input().split()]

def solve(arr):
	(p, inside, entered) = ([], set(), set())
	for x in arr:
		if x < 0 and -x not in inside or (x > 0 and x in entered):
			return []
		elif x < 0:
			inside.remove(-x)
			if len(inside) == 0:
				p.append(2 * len(entered))
				entered = set()
		else:
			inside.add(x)
			entered.add(x)
	if inside:
		return []
	return p

def main():
	while 1:
		try:
			(n,) = ints()
		except EOFError:
			break
		ans = solve(ints())
		if not ans:
			print('-1')
		else:
			print(len(ans))
			print(*ans)
	return
main()


n = int(input())
days_log = list(map(int, input().strip().split()))
if days_log[0] <= 0 or days_log[-1] >= 0 or n % 2 != 0:
	print('-1')
else:
	noofdays = 0
	events = []
	no = 0
	event_dict = {}
	for e in days_log:
		if e > 0:
			if e in event_dict.keys():
				if all(event_dict.values()):
					event_dict[e] = 0
				else:
					no = 1
					break
			else:
				event_dict[e] = 0
		elif -e in event_dict.keys():
			if event_dict[-e] == 0:
				event_dict[-e] = 1
				if all(event_dict.values()):
					noofdays += 1
					events.append(len(event_dict) * 2)
					event_dict = {}
			else:
				no = 1
				break
		else:
			no = 1
			break
	if no == 0:
		print(noofdays)
		for e in events:
			print(e, end=' ')
	else:
		print('-1')


n = int(input())
a = [int(x) for x in input().split()]
s = set()
used = set()
r = []
i = 0
for aa in a:
	i += 1
	if aa > 0:
		if aa in used:
			print(-1)
			break
		s.add(aa)
		used.add(aa)
	else:
		if -aa not in s:
			print(-1)
			break
		s.remove(-aa)
		if len(s) == 0:
			used.clear()
			r.append(i)
			i = 0
else:
	if len(s) != 0:
		print(-1)
	else:
		print(len(r))
		print(*r)


n = int(input())
d = [int(i) for i in input().split()]
fnd = set()
in_o = set()
ans = []
last_ind = -1
bad = False
for i in range(n):
	dd = d[i]
	if dd > 0:
		if dd in fnd:
			bad = True
			break
		else:
			fnd.add(dd)
			in_o.add(dd)
	else:
		dd *= -1
		if dd not in in_o:
			bad = True
			break
		else:
			in_o.remove(dd)
	if len(in_o) == 0:
		ans.append(i - last_ind)
		last_ind = i
		fnd = set()
		in_o = set()
if bad or len(in_o) != 0:
	print(-1)
else:
	print(len(ans))
	print(' '.join(map(str, ans)))


from sys import stdin
input = stdin.readline
v1 = set()
a = [-1]
s = 0
f = int(input())
for (i, j) in enumerate(map(int, input().split())):
	s += j
	if j < 0 and -j not in v1 or j in v1:
		exit(print(-1))
	v1.add(j)
	if not s:
		a += (i,)
		v1.clear()
if a[-1] != f - 1:
	exit(print(-1))
print(len(a) - 1)
print(*[a[i + 1] - a[i] for i in range(len(a) - 1)])


import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
n = int(input())
event = [int(item) for item in input().split()]
cnt = [0] * (10 ** 6 + 1)
people_in_house = 0
seen = set()
ans = []
ok = True
prev = 0
for (i, item) in enumerate(event):
	positibe = item > 0
	index = abs(item)
	if positibe:
		if index in seen:
			if people_in_house == 0:
				ans.append(i + 1 - prev)
				prev = i + 1
				seen.clear()
			else:
				ok = False
		if cnt[index] != 0:
			ok = False
		cnt[index] += 1
		seen.add(index)
		people_in_house += 1
	else:
		if cnt[index] != 1:
			ok = False
		cnt[index] -= 1
		people_in_house -= 1
		if people_in_house == 0:
			ans.append(i + 1 - prev)
			prev = i + 1
			seen.clear()
if people_in_house != 0:
	print(-1)
	exit()
if ok:
	print(len(ans))
	print(' '.join([str(item) for item in ans]))
else:
	print(-1)


n = int(input())
if n % 2 != 0:
	print('-1')
else:
	arr = input().split(' ')
	arrived = []
	left = []
	events = 0
	all_people = n // 2
	days = []
	valid = True
	for i in range(n):
		events = events + 1
		num = int(arr[i])
		if num < 0:
			if num in left:
				print('-1')
				valid = False
				break
			if not -1 * num in arrived:
				print('-1')
				valid = False
				break
			else:
				left.append(num)
				if len(arrived) == len(left):
					days.append(events)
					events = 0
					arrived = []
					left = []
		if num > 0:
			arrived.append(num)
			all_people = all_people - 1
			if all_people < 0:
				print('-1')
				valid = False
				break
	if valid & (len(arrived) > 0):
		print('-1')
		valid = False
	if valid:
		print(len(days))
		print(*days, sep=' ')


n = int(input())
a = list(map(int, input().split()))
b = set()
lensb = []
count = 0
good = True
if n % 2 == 0:
	office = 0
	count_event = 0
	for i in range(n):
		if a[i] in b and office != 0 or (a[i] < 0 and -a[i] not in b):
			office = 1
			break
		if a[i] > 0:
			office += 1
		else:
			office -= 1
		b.add(a[i])
		if office == 0:
			count += 1
			lensb.append(str(len(b)))
			b = set()
	if office == 0:
		print(count)
		print(' '.join(lensb))
	else:
		print(-1)
else:
	print(-1)


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
n = int(input())
a = f()
cnt = {}
prs = set([])
ok = True
res = []
s = 0
for i in range(n):
	if cnt.get(a[i], False):
		ok = False
	elif a[i] < 0 and (not cnt.get(-a[i], False)):
		ok = False
	elif a[i] > 0:
		cnt[a[i]] = True
		if a[i] in prs:
			ok = False
		prs.add(a[i])
	elif a[i] < 0:
		cnt[-a[i]] = False
	s += a[i]
	if not s:
		prs.clear()
		res.append(i + 1)
if prs:
	ok = False
if ok:
	print(len(res))
	j = 0
	for i in res:
		print(i - j, end=' ')
		j = i
else:
	print(-1)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	num = 0
	stack = 0
	index = []
	day = set()
	for i in range(n):
		e = a[i]
		if i != 0:
			if not stack:
				day = set()
				if index:
					index.append(i - num)
				else:
					index.append(i)
				num = i
		stack += e
		if stack < 0:
			print(-1)
			return
		if e < 0:
			if abs(e) not in day:
				print(-1)
				return
		if e in day:
			print(-1)
			return
		else:
			day.add(e)
	if stack:
		print(-1)
		return
	if index:
		index.append(n - num)
	else:
		index.append(n)
	print(len(index))
	print(' '.join([str(x) for x in index]))
main()


size = int(input())
(act, s, ans, bag) = (0, 0, [], set())
for x in map(int, input().split()):
	s += x
	act += 1
	if x > 0:
		if x not in bag:
			bag.add(x)
		else:
			s = -1
			break
	elif abs(x) not in bag:
		s = -1
		break
	if not s:
		ans.append(act)
		s = 0
		act = 0
		bag.clear()
if s:
	print(-1)
else:
	print(len(ans))
	print(*ans)


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
en = [0 for i in range(10 ** 6 + 7)]
vis = [0 for i in range(10 ** 6 + 7)]
ans = [0]
flag = True
cnt = 0
v = []
for i in range(n):
	ans[-1] += 1
	vis
	if s[i] > 0:
		en[s[i]] += 1
		vis[s[i]] += 1
		v.append(s[i])
		cnt += 1
	else:
		en[-s[i]] -= 1
		cnt -= 1
	s[i] = abs(s[i])
	if en[s[i]] < 0 or en[s[i]] > 1 or vis[s[i]] > 1:
		flag = False
		break
	if i > 0 and cnt == 0:
		ans.append(0)
		for j in v:
			vis[j] = 0
		v = []
if flag == False or ans[-1] != 0:
	print(-1)
else:
	if ans[-1] == 0:
		ans.pop()
	print(len(ans))
	print(*ans)


n = int(input())
events = list(map(int, input().split()))
sumTillNow = 0
eventsState = [-1] * 10000007
currentEvents = []
d = 0
ansEvents = []
i = 0
notPossible = 0
while i < n:
	if events[i] < 0 and eventsState[abs(events[i])] == -1:
		notPossible = 1
		break
	elif events[i] > 0 and eventsState[events[i]] != 0 and (eventsState[events[i]] != 1):
		sumTillNow += events[i]
		eventsState[abs(events[i])] = 0
		currentEvents.append(events[i])
	elif events[i] < 0 and eventsState[abs(events[i])] == 0:
		sumTillNow += events[i]
		eventsState[abs(events[i])] = 1
		if sumTillNow == 0:
			d += 1
			ansEvents.append(len(currentEvents) * 2)
			for j in range(len(currentEvents)):
				eventsState[currentEvents[j]] = -1
			currentEvents.clear()
	else:
		notPossible = 1
		break
	i += 1
if notPossible == 1 or d == 0 or sumTillNow != 0:
	print(-1)
else:
	print(d)
	for i in ansEvents:
		print(i, end=' ')


n = int(input())
A = list(map(int, input().split()))
res = []
cnt = 0
employees = set()
last = 0
emp_cnt = set()
for i in range(n):
	if A[i] > 0:
		if A[i] in employees:
			print('-1')
			break
		else:
			employees.add(A[i])
			if A[i] in emp_cnt:
				print('-1')
				break
			else:
				emp_cnt.add(A[i])
	elif -A[i] in employees:
		employees.remove(-A[i])
	else:
		print('-1')
		break
	if i != 0 and len(employees) == 0:
		res.append(i + 1 - last)
		last = i + 1
		cnt += 1
		emp_cnt = set()
else:
	if len(employees) == 0:
		print(cnt)
		print(*res)
	else:
		print(-1)


import sys
input = sys.stdin.buffer.readline
n = int(input())
ls = list(map(int, input().split()))
(day, dup) = ({}, {})
(res, cc) = ([], 0)
for u in ls:
	if u > 0 and u in dup or (u < 0 and -u not in day):
		break
	if u > 0:
		(day[u], dup[u]) = (1, 1)
	else:
		day.pop(-u)
	cc += 1
	if not day:
		res.append(cc)
		dup.clear()
		cc = 0
if sum(res) == n:
	print(len(res))
	print(*res)
else:
	print(-1)


n = int(input())
arr = list(map(int, input().split()))
res = []
cnt = 0
track = 0
ans = 0
neg = dict()
pos = dict()
np = 0
for i in arr:
	if i > 0:
		if pos.get(i) == None:
			pos[i] = 1
			ans = ans + 1
			cnt = cnt + 1
		elif ans == 0:
			res.append(cnt)
			ans = 0
			cnt = 0
			track = track + 1
			neg = dict()
			pos = dict()
			pos[i] = 1
			ans = ans + 1
			cnt = cnt + 1
		else:
			np = 1
			break
	elif neg.get(i) == None:
		if pos.get(-i) != None:
			neg[i] = 1
			ans = ans - 1
			cnt = cnt + 1
		else:
			np = 1
			break
	else:
		np = 1
	if ans == 0:
		res.append(cnt)
		ans = 0
		cnt = 0
		track = track + 1
		neg = dict()
		pos = dict()
if np == 0 and ans == 0:
	res.append(cnt)
	res.remove(0)
	print(len(res))
	print(*res)
else:
	print(-1)


def main(n, a):
	num = 0
	num_list = [0]
	tmp = set()
	used = set()
	for elem in a:
		if elem > 0:
			if elem not in used:
				tmp.add(elem)
				used.add(elem)
				num_list[-1] += 1
			else:
				print(-1)
				exit()
		elif -elem in tmp:
			tmp.remove(-elem)
			num_list[-1] += 1
		else:
			print(-1)
			exit()
		if len(tmp) == 0:
			used = set()
			num += 1
			num_list.append(0)
	if len(tmp) != 0:
		print(-1)
		exit()
	print(len(num_list) - 1)
	print(*num_list[:-1])
n = int(input())
a = list(map(int, input().split()))
main(n, a)


n = int(input())
t = [int(s) for s in input().split()]
la = set()
pl = set()
bon = True
las = 0
rep = []
for i in range(n):
	e = abs(t[i])
	if t[i] > 0:
		if e in la or e in pl:
			bon = False
			break
		else:
			la.add(e)
	elif e in la:
		la.remove(e)
		pl.add(e)
		if len(la) == 0:
			la = set()
			pl = set()
			rep.append(i + 1 - las)
			las = i + 1
	else:
		bon = False
		break
if len(la) == 0 and len(pl) == 0 and bon:
	print(len(rep))
	for i in rep:
		print(i)
else:
	print(-1)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
enter = [False] * 1000010
cnt = 0
se = set()
res = []
pre = 0
for (i, x) in enumerate(a):
	if x < 0:
		if enter[-x]:
			cnt -= 1
			enter[-x] = False
		else:
			print(-1)
			quit()
	else:
		if x in se:
			print(-1)
			quit()
		if enter[x]:
			print(-1)
			quit()
		else:
			se.add(x)
			enter[x] += 1
			cnt += 1
	if cnt == 0:
		se = set()
		res.append(i + 1 - pre)
		pre = i + 1
if cnt > 0:
	print(-1)
	quit()
print(len(res))
print(*res)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
input = sys.stdin.readline
n = input()
arr = map(int, input().split())
l = [0]
s = set()
idx = 1

def solve():
	visited = set()
	idx = 1
	for num in arr:
		if num > 0:
			if num in s:
				return -1
			elif num not in visited:
				s.add(num)
				visited.add(num)
			else:
				return -1
		elif -num in s:
			s.remove(-num)
		else:
			return -1
		if not s:
			l.append(idx)
			visited = set()
		idx += 1
	if not s:
		return len(l) - 1
	else:
		return -1
sol = solve()
if sol == -1:
	print(sol)
else:
	print(sol)
	l = [l[i + 1] - l[i] for i in range(len(l) - 1)]
	print(*l)


from math import cos, pi, ceil, pi, tan, floor, gcd, sqrt, log2, factorial, log10
from collections import Counter
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase
alpha = ascii_lowercase
beta = ascii_uppercase

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	pres = [0] * (10 ** 6 + 5)
	res = []
	cur = []
	summ = 0
	for i in range(n):
		cur.append(abs(arr[i]))
		if arr[i] > 0:
			if pres[abs(arr[i])] != 0:
				print(-1)
				return
			pres[abs(arr[i])] = 1
			summ += 1
		else:
			if pres[abs(arr[i])] != 1:
				print(-1)
				return
			pres[abs(arr[i])] = 2
			summ -= 1
		if summ == 0:
			res.append(len(cur))
			for i in cur:
				pres[i] = 0
			cur.clear()
	if len(cur) > 0:
		print(-1)
		return
	print(len(res))
	print(*res)
main()


from collections import *
n = int(input())
a = list(map(int, input().split()))
e = 0
c = list()
d = dict()
sn = 0
ch = 0
for i in range(n):
	t = a[i]
	sn += t
	try:
		m = d[abs(t)]
		if (m == 1 or m == 2) and t > 0:
			ch = -1
		elif m == 1 and t < 0:
			d[abs(t)] = 2
		elif m == 2 and t < 0:
			ch = -1
	except:
		if t < 0:
			ch = -1
		elif t > 0:
			d[t] = 1
	if sn == 0:
		d = dict()
		c.append(e + 1)
		e = 0
	else:
		e += 1
if ch == -1 or sn != 0:
	print(-1)
else:
	print(len(c))
	for i in range(len(c)):
		print(c[i], end=' ')


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split(' ')))
count = 0
ans = []
dict1 = {}
flag = True
for i in range(n):
	count += a[i]
	if a[i] > 0:
		x = dict1.get(abs(a[i]), -1)
		if x == 2 and count - a[i] != 0:
			flag = False
			break
		dict1[a[i]] = 1
	else:
		x = dict1.get(abs(a[i]), -1)
		if x == 1:
			dict1[-a[i]] = 2
		else:
			flag = False
			break
	if count == 0:
		ans.append(i)
		dict1 = {}
		count = 0
s = ''
for j in range(len(ans)):
	if j == 0:
		s += str(ans[j] + 1) + ' '
	else:
		s += str(ans[j] - ans[j - 1]) + ' '
s = s[:-1]
if len(ans) > 0 and ans[-1] != n - 1:
	flag = False
if flag == True and len(ans) > 0:
	print(len(ans))
	print(s)
else:
	print(-1)


import sys
readline = sys.stdin.readline
mr = lambda : map(int, readline().split())
Ans = []
n = int(readline())
tmp = list(mr())
s = set()
ans = []
tp = True
counter = 0
for i in range(n):
	if len(s) == 0:
		s.add(tmp[i])
		counter += 1
	elif counter == 0:
		ans.append(len(s))
		s.clear()
		s.add(tmp[i])
		counter = 1
	elif tmp[i] in s:
		if counter:
			tp = False
			break
	elif tmp[i] < 0 and -tmp[i] in s:
		s.add(tmp[i])
		counter -= 1
	elif tmp[i] > 0 and -tmp[i] not in s:
		s.add(tmp[i])
		counter += 1
	else:
		tp = False
		break
if tp and counter == 0:
	ans.append(len(s))
	print(len(ans))
	print(' '.join(map(str, ans)))
else:
	print(-1)


n = int(input())
m = list(map(int, input().split()))
if n % 2:
	print(-1)
else:
	p = []
	l = [0]
	d = {}
	k = 0
	r = 0
	for i in range(n):
		if m[i] < 0:
			if abs(m[i]) not in p:
				r = 1
				break
			else:
				k += m[i]
				p.remove(abs(m[i]))
		elif m[i] in d:
			if d[m[i]] < l[-1] - 1:
				k += m[i]
				d[m[i]] = i
				p.append(m[i])
			else:
				r = 1
				break
		else:
			k += m[i]
			d[m[i]] = i
			p.append(m[i])
		if k == 0:
			l.append(i + 1)
	if r == 1 or len(p) > 0:
		print(-1)
	else:
		print(len(l) - 1)
		p = []
		for i in range(1, len(l)):
			p.append(l[i] - l[i - 1])
		print(*p)


from typing import List
ENTERED = 1
DEPARTED = 0

class Office:

	def __init__(self):
		self.inside = set()
		self.entered = set()
		self.event_number = 0

	def register(self, log: int) -> bool:
		employee = abs(log)
		self.event_number += 1
		if log > 0:
			if employee in self.inside:
				return False
			if employee in self.entered:
				return False
			self.inside.add(employee)
			self.entered.add(employee)
		else:
			if employee not in self.inside:
				return False
			self.inside.remove(employee)
		return True

	def is_valid_day(self) -> bool:
		if self.inside:
			return False
		return True

def silly_mistake(n: int, a: List[int]) -> List[int]:
	if n <= 1:
		return []
	partition = []
	office = Office()
	for log in a:
		valid_action = office.register(log)
		if not valid_action:
			return []
		if office.is_valid_day():
			partition.append(office.event_number)
			office = Office()
	if not partition or sum(partition) != n:
		return []
	return partition

def test():
	assert silly_mistake(6, [1, 7, -7, 3, -1, -3]) == [6]
	assert silly_mistake(8, [1, -1, 1, 2, -1, -2, 3, -3]) == [2, 4, 2]
	assert silly_mistake(6, [2, 5, -5, 5, -5, -2]) == []
	assert silly_mistake(3, [-8, 1, 1]) == []
	assert silly_mistake(4, [1, -1, 2, 3]) == []
	assert silly_mistake(3, [1, 1, -1]) == []
n = int(input())
a = list(map(int, input().split(' ')))
partition = silly_mistake(n, a)
if not partition:
	print('-1')
else:
	print(len(partition))
	print(' '.join(map(str, silly_mistake(n, a))))


import sys

def input():
	str = sys.stdin.readline()
	return str[:-1]
n = int(input())
arr = list(map(int, input().split(' ')))
ans = []
rec = {}
totRec = {}
for j in range(len(arr)):
	i = arr[j]
	if i > 0:
		if i not in rec and i not in totRec:
			rec[i] = 1
			totRec[i] = 1
		else:
			ans = [-1]
			break
	else:
		i = -i
		if i not in rec:
			ans = [-1]
			break
		else:
			rec.pop(i)
		if len(rec) == 0:
			ans.append(j + 1)
			totRec = {}
if ans[0] == -1 or len(rec) != 0 or len(totRec) != 0:
	print(-1)
else:
	print(len(ans))
	pre = 0
	for i in ans:
		print(i - pre, end=' ')
		pre = i


def check():
	n = int(input())
	order = list(map(int, input().split()))
	ppl = set()
	prev = -1
	ans = []
	visited = set()
	for (i, p) in enumerate(order):
		if p < 0:
			if -p in ppl:
				ppl.remove(-p)
				visited.add(-p)
				if not ppl:
					ans.append(i - prev)
					prev = i
					visited = set()
			else:
				return -1
		elif p in visited or p in ppl:
			return -1
		else:
			ppl.add(p)
	if sum(ans) != n:
		return -1
	return ans
ans = check()
if ans == -1:
	print(ans)
else:
	print(len(ans))
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
s = set()
vis = set()
ans = []
flag = 1
last = -1
for i in range(n):
	if a[i] > 0:
		if a[i] in s:
			flag = 0
			break
		if a[i] in vis:
			if len(s) != 0:
				flag = 0
				break
		vis.add(a[i])
		s.add(a[i])
	elif -a[i] in s:
		s.remove(-a[i])
		if len(s) == 0:
			ans.append(i - last)
			last = i
			vis.clear()
	else:
		flag = 0
		break
if len(s) != 0:
	flag = 0
if flag:
	print(len(ans))
	for i in ans:
		print(i, end=' ')
else:
	print(-1)


t = int(input())
a = list(map(int, input().split()))
b = {0}
c = {0}
m = []
ans = 0
e = 0
for i in range(t):
	if a[i] in b:
		ans = -1
		break
	if a[i] in c:
		ans = -1
		break
	if a[i] < 0 and (not -a[i] in b):
		ans = -1
		break
	if a[i] > 0:
		e = e + 1
		b.add(a[i])
	else:
		c.add(-a[i])
	if c == b:
		ans = ans + 1
		m.append(e + e)
		e = 0
		b = {0}
		c = {0}
if t % 2:
	print('-1')
elif ans == -1 or ans == 0 or sum(m) != t:
	print('-1')
else:
	print(ans)
	for j in range(ans):
		print(m[j], end=' ')


def solve(n, a):
	ans = []
	l = 0
	while l < n:
		r = l
		once_enterd = set()
		current = set()
		if a[r] < 0:
			return None
		once_enterd.add(a[r])
		current.add(a[r])
		r += 1
		while current:
			if r == n:
				return None
			if a[r] > 0:
				if a[r] in once_enterd:
					return None
				once_enterd.add(a[r])
				current.add(a[r])
			else:
				if -a[r] not in current:
					return None
				current.remove(-a[r])
			r += 1
		ans += [r - l]
		l = r
	return ans

def main():
	n = int(input())
	a = list(map(int, input().split()))
	ans = solve(n, a)
	if ans is None:
		print(-1)
	else:
		print(len(ans))
		print(*ans)
main()


inside = set()
entered = set()
n = int(input())
events = list(map(int, input().split()))
days = 0
edays = []
currente = 0
for i in range(n):
	p = events[i]
	if p > 0:
		if p not in entered:
			inside.add(p)
			entered.add(p)
			currente += 1
		else:
			days = -1
			edays = []
			break
	elif -p in inside:
		inside.remove(-p)
		currente += 1
		if inside == set():
			days += 1
			edays.append(currente)
			currente = 0
			entered = set()
	else:
		days = -1
		edays = []
		break
if inside != set():
	days = -1
	edays = []
print(days)
print(' '.join([str(x) for x in edays]))


n = int(input())
L = list(map(int, input().split()))
ans = [-1]
s = set()
vis = set()
ok = True
for i in range(n):
	c = L[i]
	if c > 0:
		if c in vis:
			ok = False
			break
		vis.add(c)
		if c in s:
			ok = False
			break
		else:
			s.add(c)
	elif -c not in s:
		ok = False
		break
	else:
		s.remove(-c)
	if len(s) == 0:
		ans.append(i)
		vis.clear()
if len(s) != 0:
	ok = False
if not ok:
	print(-1)
else:
	print(len(ans) - 1)
	for i in range(1, len(ans)):
		if i != 1:
			print(' ', end='')
		print(' ' + str(ans[i] - ans[i - 1]), end='')


n = int(input())
soot = set()
usoot = set()
a = list(map(int, input().split()))
ans = []
f = True
c = 0
for i in a:
	c += 1
	if i < 0:
		if -i in soot:
			soot.remove(-i)
			usoot.add(-i)
		else:
			f = False
			break
	elif i in soot or i in usoot:
		f = False
		break
	else:
		soot.add(i)
	if len(soot) == 0:
		usoot = set()
		ans.append(c)
		c = 0
if len(soot) != 0:
	f = False
if f:
	print(len(ans))
	for i in ans:
		print(i, end=' ')
else:
	print(-1)


n = int(input())
arr = [int(x) for x in input().split()]
curr = 0
found = dict()
res = []
flag = False
for i in range(n):
	if found.get(arr[i], False):
		flag = True
		break
	else:
		if arr[i] < 0:
			if not found.get(-arr[i], False):
				flag = True
				break
		curr += arr[i]
		found[arr[i]] = True
		if curr == 0:
			res.append(len(found))
			found.clear()
if flag or curr != 0:
	print(-1)
else:
	print(len(res))
	print(*res)


n = int(input())
logs = list(map(int, input().split()))

def calculate_days(logs):
	days = set()
	days_num = 0
	events_num = 0
	events_lst = []
	recurr_days = set()
	output = 0
	for i in logs:
		if len(days) == 0:
			days_num += 1
			if events_num > 0:
				events_lst.append(events_num)
				events_num = 0
				recurr_days = set()
		if i > 0:
			if i in days:
				output = -1
				break
			elif i in recurr_days:
				output = -1
				break
			else:
				days.add(i)
				events_num += 1
				recurr_days.add(i)
		elif i < 0:
			if -i in days:
				days.remove(-i)
				events_num += 1
			else:
				output = -1
				break
	events_lst.append(events_num)
	if len(days) != 0:
		output = -1
	if output == 0:
		return (days_num, events_lst)
	else:
		return output
output = calculate_days(logs)
if type(output) == tuple:
	events_lst = output[1]
	events = str(events_lst).strip('[').strip(']').replace(', ', ' ')
	print(output[0])
	print(events)
else:
	print(output)


n = int(input())
l = [int(i) for i in input().split()]
d1 = {}
c = 0
d = []
c1 = 1
c2 = 0
prev = -1
for i in range(n):
	if l[i] > 0:
		if l[i] not in d1:
			d1[l[i]] = 1
			c2 += 1
		else:
			c1 = 0
			break
	elif -l[i] not in d1:
		c1 = 0
		break
	elif d1[-l[i]] == 0:
		c1 = 0
		break
	elif c2 == 0:
		c1 = 0
		break
	else:
		d1[-l[i]] = 0
		c2 -= 1
	if c2 == 0:
		d.append(i - prev)
		d1 = {}
		prev = i
		c += 1
if c2 != 0:
	c1 = 0
if c1 == 0:
	print(-1)
else:
	print(c)
	print(*d)


n = int(input())
arr = list(map(int, input().split(' ')))
ans = 1
per_day = {}
pointer = 0
result_n = 0
result_nums = []
k = 1
for (ind, i) in enumerate(arr):
	if i > 0 and (not i in per_day):
		per_day[i] = 1
		pointer += 1
	elif i < 0:
		if abs(i) in per_day and per_day[abs(i)]:
			pointer -= 1
			per_day[abs(i)] = 0
			if pointer == 0:
				result_n += 1
				result_nums.append(k)
				per_day.clear()
				k = 0
		else:
			ans = 0
			break
	else:
		ans = 0
		break
	k += 1
if ans and per_day == {}:
	print(result_n)
	print(*result_nums)
elif ans == 0 or per_day != {}:
	print(-1)


n = int(input())
s = set()
ss = set()
i = 0
seg = []
gud = True
for e in map(int, input().split()):
	if e > 0:
		if e in ss:
			gud = False
			break
		s.add(e)
		ss.add(e)
	else:
		if -e not in s:
			gud = False
			break
		s.remove(-e)
	i += 1
	if len(s) == 0:
		seg.append(i)
		ss = set()
		i = 0
if len(s) != 0:
	gud = False
if not gud:
	print(-1)
else:
	print(len(seg))
	print(*seg)


def main():
	n = int(input())
	err_ = False
	array = list(map(int, input().split()))
	peolpe = {}
	peolpe_sum = 0
	event = 0
	ans = []
	for i in range(n):
		a = array[i]
		if a > 0 and a not in peolpe:
			peolpe[a] = True
			peolpe_sum += a
		elif a < 0 and -a in peolpe:
			peolpe_sum += a
		else:
			err_ = True
			break
		event += 1
		if peolpe_sum == 0:
			ans.append(str(event))
			peolpe = {}
			event = 0
	if err_ or peolpe_sum != 0:
		print(-1)
	else:
		print(len(ans))
		print(' '.join(ans))
main()


n = int(input())
lst = list(map(int, input().split()))
Dict = {}
ans = 0
ans_lst = []
start = 0
total = 0
flag = 0
for i in range(n):
	ele = lst[i]
	if ele > 0:
		if Dict.get(ele) != None:
			flag = 1
			break
		else:
			Dict[ele] = True
			total += ele
	elif total == 0:
		flag = 1
		break
	else:
		total += ele
		if total < 0 or Dict.get(-ele) == None:
			flag = -1
			break
		elif total == 0:
			ans += 1
			Dict = {}
			ans_lst.append(i - start + 1)
			start = i + 1
if flag or total != 0:
	print(-1)
else:
	print(ans)
	print(*ans_lst)


import math
n = int(input())
a = list(map(int, input().split()))
s = set()
(d, l) = ({}, [])
ans = 0
(c, t) = (0, 0)
for i in range(n):
	if a[i] < 0 and -a[i] not in d:
		c = 1
		break
	elif a[i] in d:
		if 2 * len(s) + t == i + 1:
			l.append(ans)
			t += ans
			s = set()
			s.add(abs(a[i]))
			d = {}
			d[a[i]] = 1
			ans = 1
		else:
			c = 1
			break
	else:
		s.add(abs(a[i]))
		ans += 1
		if 2 * len(s) + t == i + 1:
			s = set()
			d = {}
			t += ans
			l.append(ans)
			ans = 0
		else:
			d[a[i]] = 1
if n % 2 != 0:
	print(-1)
elif len(s) != 0:
	print(-1)
elif c == 1:
	print(-1)
else:
	print(len(l))
	print(*l)


t = 1
while t:
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	cnt = 0
	day = 0
	ele = 0
	dd = []
	ch = 0
	for i in range(n):
		if a[i] < 0:
			if d.get(abs(a[i]), 0) == 1:
				d[abs(a[i])] -= 1
				ele += 1
				cnt -= 1
			else:
				ch = -1
				break
		elif d.get(a[i], -1) != -1:
			ch -= 1
			break
		else:
			ele += 1
			cnt += 1
			d[a[i]] = 1
		if cnt == 0:
			d = {}
			day += 1
			dd.append(ele)
			ele = 0
	if ch == -1 or day == 0 or cnt != 0:
		print(-1)
	else:
		print(day)
		for i in range(day):
			print(dd[i], end=' ')
	t -= 1


ans = []
N = int(input())
arr = list(map(int, input().split()))
count = set()
balance = 0
start = 0
possible = True
for (ind, val) in enumerate(arr):
	if val > 0:
		balance += 1
		if val in count:
			possible = False
			break
		else:
			count.add(val)
	else:
		if val in count or abs(val) not in count:
			possible = False
			break
		count.add(val)
		balance -= 1
	if balance == 0:
		ans.append(arr[start:ind + 1])
		start = ind + 1
		count = set()
if balance != 0 or not possible:
	print(-1)
else:
	print(len(ans))
	print(' '.join((str(len(i)) for i in ans)))


import sys
input = sys.stdin.readline

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
a = I()
ans = []
inn = [0] * 1000001

def no():
	print(-1)
	exit()
cur = 0
s = set()
last = 0
for i in range(n):
	x = a[i]
	if x > 0:
		if inn[x] or x in s:
			no()
		inn[x] = 1
		s.add(x)
		cur += 1
	else:
		x = -x
		if inn[x] == 0:
			no()
		inn[x] = 0
		cur -= 1
	if cur == 0:
		s = set()
		ans.append(i + 1 - last)
		last = i + 1
if cur:
	no()
print(len(ans))
print(*ans)


n = int(input())
a = list(map(int, input().split()))
ans = []
now_in = set()
was = set()
summ = 0
last = 0
t = 0
for i in range(n):
	summ += a[i]
	if a[i] > 0:
		if a[i] not in was:
			now_in.add(a[i])
			was.add(a[i])
		else:
			t = 1
			break
	else:
		if abs(a[i]) not in was:
			t = 1
			break
		now_in.discard(abs(a[i]))
	if summ == 0:
		if len(now_in) == 0:
			ans.append(i + 1 - last)
			last = i + 1
			was.clear()
		else:
			t = 1
			break
if len(now_in) != 0 or summ != 0:
	t = 1
if t == 0:
	print(len(ans))
	for i in ans:
		print(i, end=' ')
else:
	print(-1)


def count_subarrays(ar):
	sum = 0
	c = []
	e = 0
	x = {}
	for n in ar:
		if n < 0 and abs(n) not in x:
			c = [-1]
			return c
		elif abs(n) in x and x[abs(n)] == 2:
			c = [-1]
			return c
		elif abs(n) in x:
			x[abs(n)] += 1
		else:
			x[n] = 1
		sum += n
		e += 1
		if sum == 0:
			c.append(e)
			e = 0
			x.clear()
	if sum != 0:
		return [-1]
	return c
n = int(input())
ar = list(map(int, input().strip().split()))
c = count_subarrays(ar)
if -1 in c or len(c) == 0:
	print(-1)
else:
	print(len(c))
	for i in range(len(c) - 1):
		print(c[i], end=' ')
	print(c.pop())


mod = 10 ** 9 + 7
import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def main():
	n = inin()
	a = ain()
	d = {}
	e = {}
	x = 0
	ans = []
	q = -1
	an = 0
	for i in a:
		x += 1
		if len(d) == 0 and x > 1:
			ans.append(x - 1)
			x = 1
			e = {}
			e[i] = 1
		if i > 0:
			if i in e:
				if len(d) != 0:
					an = -1
					break
			else:
				e[i] = 1
			if i not in d:
				d[i] = 1
			else:
				an = -1
				break
		if i < 0:
			i = abs(i)
			if i in d:
				del d[i]
			else:
				an = -1
				break
	if len(d) != 0:
		an = -1
	if an == q:
		print(-1)
	else:
		ans.append(x)
		print(len(ans))
		print(*ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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 sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


n = int(input())
a = [int(s) for s in input().split()]
c = []
office = set()
day = set()
for i in range(n):
	if a[i] > 0:
		if a[i] in day:
			print(-1)
			break
		office.add(a[i])
		day.add(a[i])
	else:
		if -a[i] not in office:
			print(-1)
			break
		office.remove(-a[i])
		if len(office) == 0:
			c.append(2 * len(day))
			day = set()
else:
	if len(office) == 0:
		print(len(c))
		print(' '.join([str(i) for i in c]))
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
events = []
s = 0
incom = set()
outgo = set()
for i in range(n):
	if len(incom) == 0 and len(outgo) == 0:
		events.append(0)
	s += a[i]
	if a[i] > 0 and (not a[i] in incom) and (not a[i] in outgo):
		incom.add(a[i])
		events[len(events) - 1] += 1
	elif a[i] < 0 and (not -a[i] in outgo) and (-a[i] in incom):
		outgo.add(-a[i])
		events[len(events) - 1] += 1
	else:
		events.clear()
		break
	if s == 0:
		incom.clear()
		outgo.clear()
if n % 2 != 0 or len(events) == 0 or s != 0:
	print(-1)
else:
	print(len(events))
	print(' '.join(map(str, events)))


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	stack = set()
	used = set()
	res = [0]
	j = 0
	for i in range(n):
		if arr[i] > 0:
			if arr[i] in used:
				print(-1)
				return
			stack.add(arr[i])
			used.add(arr[i])
			res[j] += 1
		elif -arr[i] in stack:
			stack.remove(-arr[i])
			res[j] += 1
			if not stack:
				res.append(0)
				used = set()
				j += 1
		else:
			print(-1)
			return
	if stack:
		print(-1)
		return
	else:
		if res[-1] == 0:
			res.pop()
		print(len(res))
		print(*res)
main()


n = int(input())
a = list(map(int, input().split()))
s = set()
c = set()
ans = []
last = 0
for (i, v) in enumerate(a):
	if v > 0:
		if v in s or v in c:
			ans = 'BAD'
			break
		s.add(v)
	else:
		v *= -1
		if v not in s:
			ans = 'BAD'
			break
		s.remove(v)
		c.add(v)
		if len(s) == 0:
			ans.append(i + 1 - last)
			last = i + 1
			c = set()
if ans == 'BAD' or len(s) != 0:
	print(-1)
else:
	print(len(ans))
	print(*ans)


n = int(input())
l = list(map(int, input().split()))
a = [0] * (10 ** 6 + 1)
use = {}
ans = [0]
t = 0
false = 0
for i in range(n):
	if l[i] > 0:
		if l[i] not in use:
			a[l[i]] = 1
			t += 1
			use[l[i]] = 1
		else:
			false = 1
			break
	if l[i] < 0:
		if a[-l[i]] == 1:
			a[-l[i]] = 0
			t -= 1
		else:
			false = 1
			break
	if t == 0:
		ans.append(i + 1)
		use = {}
if t != 0:
	false = 1
if false == 1:
	print(-1)
else:
	print(len(ans) - 1)
	for i in range(0, len(ans) - 1):
		print(ans[i + 1] - ans[i], end=' ')


n = int(input())
li = list(map(int, input().split()))
dic = {}
ans = []
valid = True
add = 0
count = 0
le = 0
for i in range(n):
	val = dic.get(li[i], -1)
	if val == -1:
		if li[i] > 0:
			dic.update({li[i]: 1})
			add += li[i]
			count += 1
		else:
			temp = dic.get(abs(li[i]), -1)
			if temp == -1:
				valid = False
				break
			else:
				dic.update({li[i]: 1})
				add += li[i]
				count += 1
	else:
		valid = False
		break
	if add == 0:
		le += 1
		dic = {}
		ans.append(count)
		count = 0
		add = 0
if add != 0:
	valid = False
if valid:
	print(le)
	for i in range(le):
		print(ans[i], end=' ')
else:
	print(-1)


from collections import Counter
from collections import defaultdict
import math
import bisect
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(lambda : 0)
s = set()
l = list()
f = 0
c = 0
q = 1
k = 0
p = 0
for i in range(0, n):
	p = p + a[i]
	if d[-a[i]] > 0:
		h = 0
	else:
		if a[i] < 0:
			q = 0
			break
		d[a[i]] = d[a[i]] + 1
		if d[a[i]] == 1:
			k = k + 1
		if d[a[i]] > 1:
			q = 0
			break
	c = c + 1
	if c / 2 == k and p == 0:
		f = 1
		d = defaultdict(lambda : 0)
		l.append(c)
		c = 0
		k = 0
if f and q and (c == 0) and (k == 0) and (p == 0):
	print(len(l))
	print(*l)
else:
	print(-1)


n = int(input())
ls = [int(x) for x in input().split()]
su = 0
d = dict()
ans = []
k = 0
f = 0
for i in ls:
	if i > 0 and abs(i) in d:
		f = 1
		break
	elif i < 0 and abs(i) not in d:
		f = 1
		break
	else:
		su += i
		d[abs(i)] = 1
		if su == 0:
			su = 0
			d.clear()
			ans.append(k + 1)
			k = -1
	k += 1
if su != 0 or f == 1:
	print(-1)
elif f == 0:
	print(len(ans))
	print(' '.join((str(a) for a in ans)))


def solve(n, L):
	s = set()
	w = set()
	r = []
	count = 0
	for i in L:
		count += 1
		if i < 0:
			if -i not in s:
				print(-1)
				return
			s.remove(-i)
			if len(s) == 0:
				r.append(count)
				w = set()
				count = 0
		else:
			if i in w:
				print(-1)
				return
			s.add(i)
			w.add(i)
	if len(s) != 0:
		print(-1)
		return
	print(len(r))
	print(*r)
n = int(input())
L = list(map(int, input().split()))
solve(n, L)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		n = ri()
		a = ria()
		nd = 0
		d = {}
		v = 0
		s = 0
		ans = []
		f = 0
		for i in a:
			if i < 0:
				if -i not in d:
					f = 1
					break
				else:
					v += i
					s += 1
			elif i in d:
				f = 1
				break
			else:
				d[i] = 1
				v += i
				s += 1
			if v == 0:
				nd += 1
				ans.append(s)
				d.clear()
				v = 0
				s = 0
		if v != 0:
			f = 1
		if f == 0:
			print(nd)
			print(*ans)
		else:
			print(-1)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


n = int(input())
arr = [int(p) for p in input().split()]
preSum = arr.copy()
for i in range(1, n):
	preSum[i] += preSum[i - 1]
s = set()
size = []
for i in range(len(preSum)):
	if arr[i] < 0:
		if -arr[i] not in s:
			print(-1)
			exit()
	if preSum[i] == 0:
		size.append(len(s) + 1)
		s = set()
	elif arr[i] in s:
		print(-1)
		exit()
	else:
		s.add(arr[i])
if sum(size) == n:
	print(len(size))
	print(*size)
else:
	print(-1)


n = int(input())
array = list(map(int, input().split()))
(days, flag) = (0, 1)
(ans, day, arrived) = ([], set(), set())
for i in array:
	if i > 0:
		if i in arrived:
			flag = 0
			break
		else:
			day.add(i)
			arrived.add(i)
	else:
		j = -i
		if j in day:
			day.remove(j)
		else:
			flag = 0
			break
	if len(day) == 0:
		days += 1
		ans.append(len(arrived) * 2)
		(day, arrived) = (set(), set())
if flag == 1 and n == sum(ans):
	print(days)
	print(*ans)
else:
	print(-1)


vis = [-1 for i in range(1000005)]
val_days = list()

def valid_day(mov):
	tot_sum = 0
	if mov[0] < 0:
		print(-1)
		return
	for m in mov:
		tot_sum += m
	if tot_sum != 0:
		print(-1)
		return
	curr_sum = 0
	curr_cnt = 0
	for i in range(len(mov)):
		if mov[i] > 0:
			if vis[mov[i]] < len(val_days):
				vis[mov[i]] = len(val_days)
				curr_sum += mov[i]
				curr_cnt += 1
			else:
				print(-1)
				return
		elif vis[abs(mov[i])] == len(val_days):
			curr_sum += mov[i]
			curr_cnt += 1
		else:
			print(-1)
			return
		if curr_cnt != 0:
			if curr_sum == 0:
				val_days.append(curr_cnt)
				curr_sum = 0
				curr_cnt = 0
	print(len(val_days))
	fin_ans = str(val_days[0])
	for i in range(1, len(val_days)):
		fin_ans += ' ' + str(val_days[i])
	print(fin_ans)
n = int(input())
arr = input().split(' ')
mov = list()
for a in arr:
	mov.append(int(a))
valid_day(mov)


n = int(input())
a = list(map(int, input().split()))
m = {}
ans = [0]
is_valid = True
s = 0
for i in range(n):
	k = a[i]
	if k < 0 and (not -k in m):
		is_valid = False
		break
	elif k in m:
		is_valid = False
		break
	s += k
	m[k] = True
	if s == 0:
		m.clear()
		ans.append(i + 1)
if ans[-1] != n:
	is_valid = False
if is_valid:
	ans = [j - i for (i, j) in zip(ans[:-1], ans[1:])]
	print(len(ans))
	print(*ans)
else:
	print(-1)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	n = inp()
	l = li()
	x = []
	c = 0
	i = 0
	p = set()
	s = set()
	while i < n:
		if l[i] < 0:
			if -l[i] not in s:
				print(-1)
				return
			else:
				s.discard(-l[i])
				c += 1
				p.add(-l[i])
		elif l[i] in s:
			print(-1)
			return
		else:
			if l[i] in p:
				if len(s) > 0:
					pr(-1)
					return
				else:
					s.add(l[i])
					p.add(l[i])
			else:
				s.add(l[i])
				p.add(l[i])
			c += 1
		if len(s) == 0:
			x.append(c)
			p = set()
			c = 0
		i += 1
	if len(s) == 0:
		print(len(x))
		print(*x)
	else:
		pr(-1)
for _ in range(1):
	solve()


from collections import Counter, defaultdict, deque
n = int(input())
arr = [int(x) for x in input().split()]
d = defaultdict(int)
s = 0
l = 0
res = []
for el in arr:
	if el < 0:
		if d[-el] != 1:
			print(-1)
			exit()
		d[el] -= 101
		s += el
		l += 1
		if s == 0:
			res.append(l)
			l = 0
			d = defaultdict(int)
		continue
	if d[el] != 0:
		print(-1)
		exit()
	d[el] += 1
	l += 1
	s += el
if s != 0:
	print(-1)
else:
	print(len(res))
	print(*res)


import collections
n = int(input())
a = list(map(int, input().split()))
if n % 2:
	print(-1)
else:
	d = 0
	c = []
	curr = 0
	came = set()
	day = set()
	inc = False
	for i in range(n):
		if a[i] > 0:
			if a[i] in day:
				inc = True
				break
			else:
				day.add(a[i])
				came.add(a[i])
		elif abs(a[i]) not in came:
			inc = True
			break
		else:
			came.remove(abs(a[i]))
		if len(came) == 0:
			d += 1
			c.append(i + 1)
			day = set()
	if len(came) > 0:
		inc = True
	if inc:
		print(-1)
	else:
		print(d)
		print(c[0])
		for i in range(1, len(c)):
			print(c[i] - c[i - 1])


from collections import defaultdict as dc
import sys
import math
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
q = []
f = 1
x = dc(int)
c = 0
p = []
if l[0] < 0:
	print(-1)
else:
	i = 0
	while i < n:
		if l[i] < 0:
			f = 0
			break
		y = dc(int)
		if y[l[i]] == 1:
			f = 0
			break
		q.append(l[i])
		c = 1
		y[l[i]] = 1
		x[l[i]] = 1
		i += 1
		while i < n and q:
			if y[l[i]] == 1:
				f = 0
				break
			else:
				y[l[i]] = 1
			if l[i] > 0:
				if x[l[i]] > 0:
					break
				else:
					x[l[i]] = 1
					q.append(l[i])
					c += 1
			elif x[abs(l[i])] == 1:
				q.remove(abs(l[i]))
				x[abs(l[i])] = 0
				c += 1
			else:
				f = 0
				break
			i += 1
		if f == 0 or q:
			break
		else:
			p.append(c)
	if f == 0 or q:
		print(-1)
	else:
		print(len(p))
		print(*p)


def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	office = set()
	haveEntered = set()
	days = []
	l = 0
	for a in A:
		if a > 0:
			if a in haveEntered:
				return -1
			else:
				l += 1
				haveEntered.add(a)
				office.add(a)
		else:
			a = -a
			if a not in office:
				return -1
			else:
				l += 1
				office.discard(a)
		if not office and l > 0:
			days.append(l)
			l = 0
			haveEntered.clear()
	if office:
		return -1
	ans = str(len(days)) + '\n' + ' '.join((str(i) for i in days))
	return ans
print(f())


n = int(input())
t = list(map(int, input().split(' ')))
sum_ = 0
elements = set()
(err_, events) = (False, 0)
result = []
for index in range(n):
	element = t[index]
	if element > 0 and element not in elements:
		elements.add(element)
		sum_ += element
	elif element < 0 and -element in elements:
		sum_ += element
	else:
		err_ = True
		break
	events += 1
	if sum_ == 0:
		result.append(events)
		events = 0
		elements = set()
if err_ or sum_ != 0:
	print(-1)
else:
	print(len(result))
	print(*result)


a = int(input())
b = list(map(int, input().split()))

def solve(a, b):
	checkedin = set()
	blocked = set()
	ans = []
	if a % 2 != 0:
		return -1
	for i in b:
		if i > 0:
			if i in blocked or i in checkedin:
				return -1
			else:
				checkedin.add(i)
		elif -i in checkedin:
			blocked.add(-i)
			checkedin.remove(-i)
		else:
			return -1
		if len(checkedin) == 0:
			ans.append(len(blocked) * 2)
			blocked.clear()
	if len(checkedin) != 0:
		return -1
	return ans
c = solve(a, b)
if c == -1:
	print(-1)
else:
	print(len(c))
	print(' '.join([str(x) for x in c]))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = [-1]
d = Counter()

def ng(*args):
	print(-1)
	exit()
h = 0

def end_day(i):
	d.clear()
	ans.append(i)
for (i, id_) in enumerate(a):
	if id_ < 0:
		if d[-id_] != 1:
			ng(1)
		h -= 1
		d[-id_] = 2
		if h == 0:
			end_day(i)
	else:
		if d[id_] > 0:
			ng(2, id_, d[id_])
		h += 1
		d[id_] = 1
if h > 0:
	ng(4)
ans = [y - x for (x, y) in zip(ans, ans[1:])]
print(len(ans))
print(*ans)


from collections import defaultdict
n = int(input())
l = list(map(int, input().split(' ')))
s = 0
d = defaultdict(int)
curr = defaultdict(int)
ans = []
check = 1
for i in range(n):
	if curr[l[i]]:
		check = 0
		break
	if l[i] < 0:
		if d[abs(l[i])]:
			s += l[i]
			d[abs(l[i])] -= 1
		else:
			check = 0
			break
	else:
		if d[l[i]]:
			check = 0
			break
		s += l[i]
		d[l[i]] += 1
		curr[l[i]] += 1
	if s == 0:
		curr = defaultdict(int)
		ans.append(i + 1)
if check and s == 0:
	last = 0
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i] - last, end=' ')
		last = ans[i]
else:
	print(-1)


n = int(input())
a = map(int, input().split())
b = []
j = -1
o = {}
c = 0
for (i, x) in enumerate(a):
	if x > 0:
		if o.get(x, 0):
			print(-1)
			break
		else:
			o[x] = 1
			c += 1
	else:
		y = o.get(-x, 0)
		if y == 1:
			o[-x] = 2
			c -= 1
		else:
			print(-1)
			break
	if not c:
		b += (i - j,)
		j = i
		o = {}
else:
	if c:
		print(-1)
	else:
		print(len(b))
		print(' '.join(map(str, b)))


n = int(input())
a = [int(j) for j in input().split()]
days = []
cur_emp = set()
day_emp = set()
day_cnt = 0
for event in a:
	emp = abs(event)
	if event > 0:
		if emp in day_emp:
			print(-1)
			exit(0)
		day_emp.add(emp)
		cur_emp.add(emp)
	else:
		if emp not in cur_emp:
			print(-1)
			exit(0)
		cur_emp.discard(emp)
	day_cnt += 1
	if len(cur_emp) == 0:
		day_emp = set()
		days.append(day_cnt)
		day_cnt = 0
if len(cur_emp) != 0:
	print(-1)
	exit(0)
print(len(days))
for day in days:
	print(day)


n = int(input())
ls = [int(x) for x in input().split()]
s = set()
vis = set()
flag = 0
ans = []
count = 0
for i in range(len(ls)):
	count += 1
	if ls[i] > 0:
		if ls[i] in s or ls[i] in vis:
			flag = 1
			break
		else:
			s.add(ls[i])
			vis.add(ls[i])
	else:
		a = -1 * ls[i]
		if a not in s:
			flag = 1
			break
		s.remove(a)
	if len(s) == 0:
		ans.append(count)
		count = 0
		vis = set()
if flag == 1 or len(s) > 0:
	print('-1')
else:
	print(len(ans))
	print(' '.join((str(i) for i in ans)))


n = int(input())
log = list(map(int, input().split()))
come = [0] * 1000001
was = [False] * 1000001
inside = 0
answer = []
exist = True
prev = -1
wasList = []
for i in range(n):
	if log[i] > 0:
		if come[log[i]] > 0 or was[log[i]]:
			exist = False
			break
		wasList.append(log[i])
		come[log[i]] += 1
		inside += 1
		was[log[i]] = True
	elif come[-log[i]] > 0:
		come[-log[i]] -= 1
		inside -= 1
		if inside == 0:
			answer.append(i - prev)
			prev = i
			for idx in wasList:
				was[idx] = False
			wasList = []
	else:
		exist = False
		break
if exist and inside == 0:
	print(len(answer))
	print(' '.join(map(str, answer)))
else:
	print(-1)


n = int(input())
ls = list(map(int, input().split()))
office = 0
emp = [0 for i in range(1000001)]
emp2 = []
(flag, index) = (0, 1)
days = 0
s1 = ''
for i in ls:
	if i > 0:
		if emp[i] != 0:
			flag = 1
			break
		else:
			emp[i] = 1
			office += 1
	else:
		i = -i
		if emp[i] != 1:
			flag = 1
			break
		else:
			emp[i] = 2
			office -= 1
			emp2.append(i)
	if office == 0:
		days += 1
		s1 += str(index) + ' '
		index = 0
		for j in emp2:
			emp[j] = 0
		emp2 = []
	index += 1
if flag == 1 or office > 0:
	print(-1)
else:
	print(days)
	print(s1)


n = int(input())
ln = [int(i) for i in input().split(' ')]
seen = {}
sm = 0
f = True
tk = 0
pts = []
for i in range(0, len(ln)):
	sm += ln[i]
	if ln[i] < 0 and -ln[i] not in seen:
		f = False
	if ln[i] in seen:
		seen[ln[i]] += 1
		f = False
		break
	else:
		seen[ln[i]] = 1
	tk += 1
	if sm == 0:
		seen = {}
		pts.append(tk)
		tk = 0
if sm != 0:
	f = False
if not f:
	print(-1)
else:
	print(len(pts))
	print(' '.join([str(i) for i in pts]))


n = int(input())
ar = list(map(int, input().split()))
hs = set()
cnt = 0
possible = True
ans = []
day = set()
for i in range(n):
	x = ar[i]
	if x in hs or x in day:
		possible = False
		break
	cnt += 1
	day.add(x)
	if -x > x and -x in hs:
		hs.remove(-x)
		if len(hs) == 0:
			day = set()
			ans.append(cnt)
			cnt = 0
	elif -x > x:
		possible = False
		break
	else:
		hs.add(x)
if len(ans) == 0 or not possible or len(hs) != 0 or (len(day) != 0):
	print(-1)
else:
	print(len(ans))
	ans = [str(i) for i in ans]
	print(' '.join(ans))


n = int(input())
A = [int(x) for x in input().split()]
inside = set()
same_day = set()
d = 0
r = []
for x in A:
	d += 1
	if x > 0:
		if x in inside or x in same_day:
			break
		else:
			inside.add(x)
			same_day.add(x)
	elif abs(x) not in inside:
		inside.add(0)
		break
	else:
		inside.remove(abs(x))
		if len(inside) == 0:
			r.append(d)
			same_day.clear()
			d = 0
if len(inside) > 0:
	print('-1')
else:
	print(len(r))
	print(' '.join([str(x) for x in r]))


def modulo(x):
	if x >= 0:
		return x
	else:
		return -x

def verificar_dicionario(dicionario):
	for valor in dicionario.values():
		if valor == 0:
			return False
	return True

def regras(lista):
	lista_dias = []
	dicionario = {}
	flag = 0
	contador_dias = 0
	for i in lista:
		if i > 0:
			if i in dicionario:
				return (-1, -1)
			else:
				dicionario[i] = 0
				flag = 0
		elif modulo(i) not in dicionario:
			return (-1, -1)
		else:
			dicionario[modulo(i)] = i
			resposta = verificar_dicionario(dicionario)
			if resposta:
				flag = 1
				contador_dias += 1
				lista_dias.append(len(dicionario) * 2)
				dicionario = {}
			else:
				flag = 0
	if flag == 1:
		return (contador_dias, lista_dias)
	else:
		return (-1, -1)

def main():
	tamanho = int(input())
	lista = input()
	lista = lista.split()
	lista = list(map(lambda x: int(x), lista))
	(contador_dias, lista_dias) = regras(lista)
	print(contador_dias)
	if contador_dias == -1:
		return None
	for i in range(len(lista_dias)):
		if i < len(lista_dias) - 1:
			print(lista_dias[i], end=' ')
		else:
			print(lista_dias[i])
main()


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
seen = defaultdict(bool)
cnt = 0
ret = []
s = 0
for v in a:
	cnt += 1
	if v > 0 and seen[-v] or (v < 0 and (not seen[-v])) or seen[v]:
		print(-1)
		exit()
	seen[v] = True
	s += v
	if s == 0:
		ret.append(cnt)
		cnt = 0
		seen = defaultdict(bool)
print('%d\n%s' % (len(ret), ' '.join(map(str, ret))) if cnt == 0 else -1)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
n = int_input()
a = list_input()
present = set([])
aldready = set([])
final = []
count = 0
flag = 0
for events in a:
	count += 1
	if events < 0:
		if -1 * events not in present:
			print(-1)
			flag = 1
			break
		else:
			present.remove(-1 * events)
		if len(present) == 0:
			final.append(count)
			aldready = set([])
			count = 0
	elif events > 0:
		if events not in aldready:
			present.add(events)
			aldready.add(events)
		else:
			print(-1)
			flag = 1
			break
if flag == 0:
	if len(present) == 0:
		print(len(final))
		print(*final)
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
freq = {}
possible = 1
odd = 0
res = []
ans = 0
for (i, x) in enumerate(a):
	if x < 0:
		if freq.get(abs(x), None) == None:
			possible = 0
			break
		freq[abs(x)] += 1
		if freq[abs(x)] % 2 == 0:
			odd -= 1
	else:
		if freq.get(x, None):
			possible = 0
			break
		freq[x] = 1
		odd += 1
	if odd == 0:
		ans += 1
		res.append(2 * len(freq))
		freq = {}
if possible and (not len(freq)):
	print(ans)
	print(*res)
else:
	print(-1)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	visited = set()
	nums = set()
	days = []
	for i in arr:
		if i < 0:
			if -i not in nums:
				print(-1)
				return
			visited.add(-i)
			nums.remove(-i)
			if len(nums) == 0:
				days.append(2 * len(visited))
				visited = set()
				nums = set()
		elif i in visited:
			if len(nums) != 0:
				print(-1)
				return
			days.append(2 * len(visited))
			visited = set()
			nums = set()
			nums.add(i)
		else:
			if i in nums:
				print(-1)
				return
			nums.add(i)
	if len(nums) != 0:
		print(-1)
		return
	if len(visited) > 0:
		days.append(2 * len(visited))
	print(len(days))
	for i in days:
		print(i, end=' ')
main()