A number is called 2050-number if it is $2050$, $20500$, ..., ($2050 \cdot 10^k$ for integer $k \ge 0$).

Given a number $n$, you are asked to represent $n$ as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.


-----Input-----

The first line contains a single integer $T$ ($1\le T\leq 1000$) denoting the number of test cases.

The only line of each test case contains a single integer $n$ ($1\le n\le 10^{18}$) denoting the number to be represented.


-----Output-----

For each test case, output the minimum number of 2050-numbers in one line.

If $n$ cannot be represented as the sum of 2050-numbers, output $-1$ instead.


-----Examples-----

Input
6
205
2050
4100
20500
22550
25308639900
Output
-1
1
2
1
2
36


-----Note-----

In the third case, $4100 = 2050 + 2050$.

In the fifth case, $22550 = 20500 + 2050$.

Difficulty: EASY
Tags: Mathematics

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
		continue
	n = n // 2050
	sumo = 0
	while n > 0:
		sumo += n % 10
		n = n // 10
	print(sumo)


def getSum(n):
	sum = 0
	for digit in str(n):
		sum += int(digit)
	return sum
for _ in range(int(input())):
	n = int(input())
	if n % 2050 == 0:
		ans = n // 2050
		print(getSum(ans))
	else:
		print(-1)


import sys
input = sys.stdin.readline
from math import gcd
for _ in range(int(input().strip())):
	n = int(input().strip())
	if n % 2050 != 0:
		print(-1)
		continue
	print(sum(map(int, list(str(n // 2050)))))


tests = int(input())
for test in range(tests):
	n = int(input())
	(x, y) = divmod(n, 2050)
	if y == 0:
		res = 0
		for i in str(x):
			res += int(i)
		print(res)
	else:
		print(-1)


def div2050(n):
	if n < 2050:
		return -1
	if n % 2050 == 0:
		num = n // 2050
		count = 0
		while num != 0:
			count += num % 10
			num = num // 10
		return count
	else:
		return -1
n = int(input())
for i in range(n):
	num = int(input())
	print(div2050(num))


def biggestlessthan(a):
	if int('2050' + '0' * (len(str(a)) - 4)) <= a:
		return int('2050' + '0' * (len(str(a)) - 4))
	return int('2050' + '0' * (len(str(a)) - 5))

def solve():
	count = 0
	a = int(input())
	while a >= 2050:
		a -= biggestlessthan(a)
		count += 1
	if a != 0:
		return -1
	return count

def main():
	for i in range(int(input())):
		print(solve())
main()


def some_random_function():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function5():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
import os, sys
from io import BytesIO, IOBase

def dig(x):
	ans = 0
	while x:
		ans += x % 10
		x //= 10
	return ans

def main():
	for _ in range(int(input())):
		n = int(input())
		if n % 2050:
			print(-1)
			continue
		n //= 2050
		print(dig(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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def some_random_function1():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function2():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function3():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function4():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function6():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function7():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function8():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
main()


for i in range(int(input())):
	n = int(input())
	if n % 2050 == 0:
		print(sum(map(int, str(n // 2050))))
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		count = 0
		digits = int(n / 2050)
		while digits != 0:
			count += int(digits % 10)
			digits = int(digits / 10)
		print(count)


import sys

def solve(n):
	if n % 2050:
		return '-1'
	return str(sum(map(int, str(n // 2050))))

def main():
	res = ''
	input = sys.stdin.readline
	print = sys.stdout.write
	t = int(input())
	for _ in range(t):
		n = int(input())
		res += solve(n) + '\n'
	print(res)
main()


T = int(input())
for t in range(T):
	n = int(input())
	if n % 2050 != 0:
		an = -1
	else:
		ans = n // 2050
		an = 0
		while ans != 0:
			an += ans % 10
			ans = ans // 10
	print(an)


for t in range(int(input())):
	n = int(input())
	if n % 2050 == 0:
		x = n / 2050
		s = 0
		while x != 0:
			s += x % 10
			x //= 10
		print(int(s))
	else:
		print(-1)


t = int(input())
while t != 0:
	t = t - 1
	s = '2050'
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		c = 0
		while n != 0:
			le = len(str(n)) - 4
			for i in range(le):
				s = s + '0'
			if int(s) > n:
				s = s[:-1]
			n = n - int(s)
			s = '2050'
			c = c + 1
		print(c)


def tinh(n):
	x = 0
	while n != 0:
		x += n % 10
		n //= 10
	return x

def Solve():
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		k = n // 2050
		print(tinh(k))
q = int(input())
while q:
	Solve()
	q -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2050 != 0:
		print('-1')
	else:
		a = n // 2050
		s = str(a)
		count = 0
		for i in s:
			temp = int(i)
			count += temp
		print(count)


import math
for i in range(int(input())):
	n = int(input())
	if n % 2050:
		print(-1)
	else:
		print(sum(map(int, str(n // 2050))))


def getSum(number):
	sum = 0
	for digit in str(number):
		sum += int(digit)
	return sum
for _ in range(int(input())):
	n = int(input())
	num = n % 2050
	if num != 0:
		print(-1)
	else:
		k = n // 2050
		print(getSum(k))


def cf1(n):
	if n % 2050 != 0:
		return -1
	else:
		x = n // 2050
		sum1 = 0
		while x > 0:
			sum1 += x % 10
			x = x // 10
		return sum1
t = int(input())
for i in range(t):
	n = int(input())
	print(cf1(n))


t = int(input())
while t > 0:
	k = 2050
	n = int(input())
	q = n // k
	rem = n % k
	if rem == 0:
		print(sum((int(digit) for digit in str(q))))
	else:
		print(-1)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	temp = n / 2050
	if n % 2050 == 0:
		temp = str(int(temp))
		for i in range(len(temp)):
			count += int(temp[i])
		print(count)
	elif temp == 0:
		print('-1')
	else:
		print('-1')


t = int(input())
for t1 in range(t):
	a = int(input())
	if a % 2050 == 0:
		g = str(a // 2050)
		s = 0
		for j in g:
			s = s + int(j)
		print(s)
	else:
		print('-1')


N = int(input())
for i in range(N):
	s = 0
	n = int(input())
	if n % 2050 != 0:
		print('-1')
		continue
	else:
		j = n / 2050
		while j > 0:
			k = j % 10
			s += k
			j -= k
			j /= 10
		print(int(s))


w = int(input())
import math
sum = 0
l = []
for i in range(w):
	k = int(input())
	l.append(k)
for i in l:
	if i % 2050 != 0:
		print(-1)
	else:
		ans = str(math.floor(i // 2050))
		for i in ans:
			sum += int(i)
		print(sum)
	sum = 0


from sys import stdin, stdout, maxsize
from math import sqrt, log, factorial as ft, gcd, ceil
from collections import defaultdict as D
from bisect import insort
for _ in range(int(input())):
	n = int(input())
	ans = 0
	p = 2050 * 100000000000000000
	while n > 0 and p > 205:
		while n >= p:
			n -= p
			ans += 1
		p //= 10
	if n == 0:
		print(ans)
	else:
		print(-1)


t = int(input())

def getResult(v):
	if v % 2050 != 0:
		return -1
	v //= 2050
	res = 0
	while v:
		res += v % 10
		v //= 10
	return res
for i in range(t):
	n = int(input())
	print(getResult(n))


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())

def solve(n):
	if n % 2050 == 0:
		l = str(n // 2050)
		tot = 0
		for i in l:
			tot += int(i)
		print(tot)
	else:
		print(-1)
for _ in range(int(input())):
	n = int(input())
	solve(n)


l = [2050 * 10 ** i for i in range(19)][::-1]
for s in [*open(0)][1:]:
	n = int(s)
	a = 0
	for i in l:
		a += n // i
		n = n % i
	print([-1, a][n % 2050 < 1])


for _ in range(int(input())):
	n = int(input())
	c = 0
	k = 2050 * int(10 ** (len(str(n)) - 4))
	while n >= 2050:
		c += n // k
		n %= k
		k //= 10
	if n == 0:
		print(int(c))
	else:
		print('-1')


numoftests = int(input())
testnums = []
for x in range(numoftests):
	testnums.append(int(input()))
for y in testnums:
	if y % 2050 != 0:
		print(-1)
	else:
		digitlist = list(map(int, str(int(y / 2050))))
		print(sum(digitlist))


import sys

def ans():
	n = int(input())
	if n % 2050 != 0:
		print(-1)
		return
	low = n // 2050
	ans = 0
	while low > 0:
		ans += low % 10
		low = low // 10
	print(ans)
	return
for _ in range(int(input())):
	ans()


for _ in range(int(input())):
	n = int(input())
	x = n % 2050
	if x != 0:
		print(-1)
	else:
		x = n // 2050
		s = 0
		for i in str(x):
			s += int(i)
		print(s)


num = int(input())
for i in range(num):
	a = int(input())
	sum = 0
	if a % 2050 != 0:
		print(-1)
	else:
		tmp = a / 2050
		while tmp > 0:
			sum += tmp % 10
			tmp = tmp // 10
		print(int(sum))


import math

def get_int():
	return int(input())

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

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

def get_tuple_ints():
	return tuple(map(int, input().split()))

def print_iterable(p):
	print(' '.join(map(str, p)))

def main():
	t = get_int()
	for i in range(t):
		n = get_int()
		c = 0
		if n % 2050 != 0:
			print(-1)
		else:
			n = n / 2050
			d = int(math.log10(n))
			val = 0
			if d == 0:
				val = n
			else:
				while d != 0:
					val += int(n / 10 ** d)
					n = n % 10 ** d
					d -= 1
				val += n
			print(int(val))
main()


n = int(input())
k = 2050
l = list()
for _ in range(n):
	l.append(int(input()))
for num in l:
	if num % k != 0:
		print(-1)
	else:
		print(sum([int(x) for x in list(str(num // k))]))


testcases = int(input())
while testcases > 0:
	n = int(input())
	if n % 2050 != 0:
		print('-1')
	else:
		n //= 2050
		count = 0
		while n != 0:
			count += n % 10
			n //= 10
		print(count)
	testcases -= 1


t = int(input())
a = list()
for i in range(t):
	n = int(input())
	a.append(n)
for n in a:
	if n % 2050 > 0:
		print(-1)
	else:
		s = 0
		d = str(n // 2050)
		for i in d:
			s += int(i)
		print(s)


import math

def solution():
	num = int(input())
	if num % 2050 != 0:
		return -1
	num /= 2050
	cnt = 0
	if math.log(num, 10) == 0:
		return 1
	while num > 0:
		cnt += num % 10
		num = num // 10
	return int(cnt)
for tc in range(int(input())):
	print(solution())


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		n = n // 2050
		s = str(n)
		a = 0
		for i in range(len(s)):
			a = a + int(s[i])
		print(a)


for test in range(int(input())):
	n = int(input())
	div = int(n / 2050)
	if n % 2050 == 0:
		lst = list(map(int, str(div)))
		print(sum(lst))
	else:
		print(-1)


n = int(input())
a = []

def solve(x):
	if x % 2050 != 0:
		return -1
	y = int(x / 2050)
	result = int(0)
	while y != 0:
		result += y % 10
		y = int(y / 10)
	return result
for i in range(n):
	a.append(int(input()))
for i in range(n):
	print(solve(a[i]))


t = int(input())
for z in range(t):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		k = n // 2050
		k = list(str(k))
		for i in range(len(k)):
			k[i] = int(k[i])
		print(sum(k))


for i in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print('-1')
		continue
	s = n // 2050
	sum1 = 0
	for digit in str(s):
		sum1 += int(digit)
	print(sum1)


for i in range(int(input())):
	n = int(input())
	if n % 2050:
		print(-1)
	else:
		n //= 2050
		cnt = 0
		s = str(n)
		for i in s:
			cnt += int(i)
		print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		n = n // 2050
		n = str(n)
		s = 0
		for j in n:
			s += int(j)
		print(s)


import sys
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
	num = int(sys.stdin.readline().rstrip())
	mock = num // 2050
	nam = num % 2050
	if mock == 0 or nam != 0:
		print(-1)
	else:
		result = 0
		for i in str(mock):
			result += int(i)
		print(result)


T = int(input())
y = []
for a in range(T):
	n = int(input())
	if n % 2050 == 0:
		i = int(n / 2050)
		s = sum(list(map(int, str(i))))
		y.append(s)
	else:
		y.append(-1)
for a in range(T):
	print(int(y[a]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = len(str(n)) - 4
	cnt = 0
	while n > 0 and a >= 0:
		if n >= 2050 * 10 ** a:
			n -= 2050 * 10 ** a
			cnt += 1
		else:
			a -= 1
	if n != 0:
		print(-1)
	else:
		print(cnt)


n = int(input())
for i in range(n):
	x = int(input())
	a = 0
	if x < 2050:
		print(-1)
	else:
		c = 0
		if x % 2050 == 0:
			a = x / 2050
			z = str(int(a))
			for i in z:
				c += int(i)
			print(c)
		else:
			print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2050:
		print('-1')
		continue
	if n % 2050 != 0:
		print('-1')
		continue
	q = n // 2050
	q = str(q)
	res = 0
	for i in range(len(q)):
		res += int(q[i])
	print(res)


for i in range(int(input())):
	n = int(input())
	result = 0
	if n % 2050 != 0:
		print('-1')
	else:
		s = n // 2050
		while s > 0:
			rem = s % 10
			result = result + rem
			s = int(s / 10)
		print(result)


for _ in range(int(input())):
	n = int(input())
	s = 0
	if n < 2050 or n % 2050 != 0:
		print(-1)
	else:
		n = n // 2050
		while n != 0:
			s += n % 10
			n = n // 10
		print(s)


def rainy(N):
	if N % 2050:
		return -1
	allDigits = list(map(int, str(int(N // 2050))))
	return sum(allDigits)
for _ in range(int(input())):
	print(rainy(int(input())))


def fun(n):
	v = n
	count = 0
	if n % 2050 == 0:
		st = n // 2050
		st = str(st)
		for i in st:
			count += int(i)
		print(count)
	else:
		print(-1)
T = int(input())
for i in range(T):
	val = int(input())
	fun(val)


t = int(input())
for i in range(t):
	n = int(input())
	d = 0
	if n // 2050 > 0 and n % 2050 == 0:
		a = n // 2050
		while a != 0:
			d = d + a % 10
			a = a // 10
		print(d)
	else:
		print(-1)


for s in [0] * int(input()):
	n = int(input())
	print(n % 2050 and -1 or sum(map(int, str(n // 2050))))


for iii in range(int(input())):
	n = int(input())
	w = 16
	x = 2050
	cou = 0
	for i in range(17):
		while n >= x * 10 ** w:
			n = n - x * 10 ** w
			cou += 1
		w -= 1
	if n != 0:
		print(-1)
	else:
		print(cou)


for _ in range(int(input())):
	a = int(input())
	if a < 2050:
		print(-1)
		continue
	b = a
	count = 0
	while b > 2050:
		c = str(b)
		x = len(c)
		x1 = 205 * pow(10, x - 3)
		if x1 <= b:
			count += b // x1
			b -= b // x1 * x1
		else:
			x1 = x1 // 10
			count = count + b // x1
			b -= b // x1 * x1
	if b == 2050:
		print(count + 1)
	elif b == 0:
		print(count)
	else:
		print(-1)


a = int(input())
i = 0
while i < a:
	b = int(input())
	d = []
	if b % 2050 == 0:
		b = b // 2050
		b = str(b)
		s = 0
		while s < len(b):
			d.append(int(b[s]))
			s = s + 1
		print(sum(d))
	else:
		print(-1)
	i = i + 1


for _ in ' ' * int(input()):
	n = int(input())
	c = n % 2050 == 0
	print(int(c * sum(list(map(lambda x: int(x), list(str(n // 2050)))))) + int((not c) * -1))


t = int(input())
for i in range(t):
	s = input()
	l = len(s)
	nn = int(s)
	if nn % 2050 != 0:
		print(-1)
		continue
	cc = 0
	k = l - 4
	while k >= 0:
		tf = 2050 * 10 ** k
		r1 = nn // tf
		nn = nn % tf
		cc += r1
		k -= 1
	print(cc)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	if n % 2050 != 0:
		print(-1)
		continue
	n = n // 2050
	rem = 0
	while n > 0:
		rem = n % 10
		ans += rem
		n //= 10
	print(ans)


for _ in range(int(input())):
	n = int(input())
	if n % 2050:
		print('-1')
	else:
		ans = 0
		temp = str(n // 2050)
		for i in temp:
			ans += int(i)
		print(ans)


for t in range(int(input())):
	n = int(input())
	if n % 2050 != 0 or n == 0:
		print(-1)
	else:
		k = n // 2050
		sum1 = 0
		s = str(k)
		for i in s:
			sum1 += int(i)
		print(sum1)


def getSum():
	d = 0
	n = int(input())
	for i in range(16, 0, -1):
		d = d + n // A[i]
		n = n % A[i]
	if n == 0:
		print(d)
	else:
		print('-1')
A = []
A.append(0)
t = int(input())
for i in range(t):
	x = 205
	for i in range(1, 17):
		x = x * 10
		A.append(x)
	getSum()


t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = 0
	if n % 2050 == 0:
		a = list(str(n // 2050))
		for i in a:
			ans += int(i)
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	if n % 2050 == 0:
		arr = list(map(int, list(str(int(n // 2050)))))
		print(sum(arr))
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		nums = [2050 * 10 ** x for x in range(20)]
		nums.reverse()
		ans = 0
		low = 0
		while low < len(nums):
			while n - nums[low] >= 0:
				n -= nums[low]
				ans += 1
			low += 1
		if n == 0:
			print(ans)
		else:
			print(-1)
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()


for _ in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		ans = -1
	else:
		n = n // 2050
		ans = 0
		for item in str(n):
			ans = ans + int(item)
	print(ans)


t = int(input())

def fun(n):
	if n < 2050:
		return -1
	ans = 0
	while n >= 2050:
		l = len(str(n)) - 4
		p = 2050 * 10 ** l
		if n >= p:
			ans += n // p
			n = n % p
		else:
			ans += n // (2050 * 10 ** (l - 1))
			n = n % (2050 * 10 ** (l - 1))
	if n == 0:
		return ans
	else:
		return -1
for i in range(t):
	print(fun(int(input())))


t = int(input())
for i in range(t):
	s = []
	p = 0
	k = int(input())
	if k % 2050 == 0 and k >= 2050:
		k = k // 2050
		p = [int(a) for a in str(k)]
		print(sum(p))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		n //= 2050
		n = sum((int(digit) for digit in str(n)))
		print(n)


t = int(input())
for _ in range(t):
	n = int(input())
	m = n
	count = 0
	while m > 0:
		m = m // 10
		count += 1
	if count < 4:
		print(-1)
	else:
		m = 2050 * 10 ** (count - 4)
		count = 0
		flag = 0
		while n >= 2050:
			if m > n:
				while m > n:
					m = m // 10
			k = n // m
			if n % m == 0:
				flag = 1
			count += k
			n = n - m * k
		if flag == 1:
			print(count)
		else:
			print(-1)


def check(x: int):
	x = int(x)
	ans = 0
	if x >= 2050 and x % 2050 == 0:
		factor = x // 2050
		while factor > 0:
			ans += factor % 10
			factor = factor // 10
	else:
		ans = -1
	return ans
cases = int(input())
anss = []
for case in range(cases):
	anss.append(check(input()))
for x in anss:
	print(x, end='\n')


t = int(input())
while t:
	s = 0
	n = int(input())
	r = int(n / 2050)
	while r:
		rr = r % 10
		s = s + rr
		r = int(r / 10)
	if s and n % 2050 == 0:
		print(s)
	else:
		print(-1)
	t = t - 1


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter

def func(n):
	if n % 2050 != 0:
		return -1
	n = n // 2050
	return sum([int(i) for i in str(n)])

def main():
	num_test = int(parse_input())
	result = []
	for _ in range(num_test):
		n = int(parse_input())
		result.append(func(n))
	print('\n'.join(map(str, result)))
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for t in range(int(input())):
	n = int(input())
	if n % 2050:
		print(-1)
		continue
	else:
		n //= 2050
	print(sum((int(i) for i in str(n))))


for _ in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	elif n / 2050 == 0:
		print(1)
	else:
		n = n / 2050
		total = 0
		while n != 0:
			r = n % 10
			total += r
			n = n // 10
		print(int(total))


for _ in range(int(input())):
	a = int(input())
	b = 205 * 10 ** 18
	res = 0
	while b > 205:
		if a >= b:
			res += a // b
			a %= b
		b //= 10
	if not a:
		print(res)
	else:
		print(-1)


import math
test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	num = n
	count = 0
	while True:
		pow = len(str(num)) - 4
		if pow < 0:
			pow = 0
		x = 2050 * 10 ** pow
		if x > num and num > 2050:
			pow -= 1
		num -= 2050 * 10 ** pow
		if num < 2050 and num != 0:
			count = -1
			break
		count += 1
		if num == 0:
			break
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	if n < 2050 or n % 2050 != 0:
		print(-1)
		continue
	c = 0
	while n > 0:
		zeros = len(str(n))
		zeros -= 4
		while n < 2050 * 10 ** zeros:
			zeros -= 1
		if zeros < 0:
			zeros = 0
		n -= 2050 * 10 ** zeros
		c += 1
	print(c)


n = int(input())
for i in range(n):
	k = int(input())
	if k % 2050 == 0:
		h = str(k // 2050)
		c = 0
		for j in h:
			c += int(j)
		print(c)
	else:
		print('-1')


def getSum(n):
	sum = 0
	for digit in str(n):
		sum += int(digit)
	return sum
n = int(input())
for i in range(n):
	num = int(input())
	if num % 2050 != 0:
		print(-1)
		continue
	else:
		num = num // 2050
		print(getSum(num))
		continue


import os
from sys import stdin
from collections import deque
candidates = deque()

def precomp():
	num = 2050
	while num <= int(1e+18):
		candidates.appendleft(num)
		num *= 10

def solve(tc):
	N = int(stdin.readline().strip())
	cnt = 0
	for num in candidates:
		while N >= num:
			N -= num
			cnt += 1
	if N == 0:
		print(cnt)
	else:
		print(-1)
precomp()
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


class sumof2050:

	def __init__(self, n):
		self.n = n

	def ans(self):
		if self.n % 2050 != 0:
			return -1
		else:
			self.n = int(self.n / 2050)
			self.n = list(map(int, list(str(self.n))))
			return sum(self.n)
for i in range(int(input())):
	n = int(input())
	print(sumof2050(n).ans())


import math
import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	a = int(input())
	if a % 2050 != 0:
		print(-1)
	else:
		ans = 0
		l = []
		while a > 0:
			k = math.log(a, 10)
			k = math.ceil(k)
			if 2050 * 10 ** (k - 4) <= a:
				a -= 2050 * 10 ** (k - 4)
			else:
				a -= 2050 * 10 ** (k - 5)
			ans += 1
		print(ans)


for i in range(int(input())):
	n = int(input())
	sum = 0
	temp = n // 2050
	if n % 2050 != 0:
		print(-1)
	else:
		while temp > 0:
			sum = sum + temp % 10
			temp = temp // 10
		print(sum)


import math

def ans():
	n = int(input())
	if n % 2050 != 0:
		print(-1)
		return
	else:
		rem = math.ceil(n / 2050)
		strr = str(rem)
		list_of_number = list(map(int, strr.strip()))
		print(sum(list_of_number))
		return
t = int(input())
while t > 0:
	ans()
	t -= 1


def sumOf2050(num):
	diff = getLenDiff(num)
	total = 0
	while num >= 2050:
		d = 2050 * 10 ** diff
		mod = num // d
		total += mod
		num %= d
		diff = getLenDiff(num) - (1 if mod == 0 else 0)
	return -1 if num != 0 else total

def getLenDiff(n):
	return len(str(n)) - len(str(2050))
n = int(input())
for _ in range(n):
	num = int(input())
	print(sumOf2050(num))


def getSum(n):
	sum = 0
	while n > 0:
		sum += int(n % 10)
		n = int(n / 10)
	return sum
t = int(input())
for q in range(t):
	n = int(input())
	quotient = 0
	if n < 2050 or n % 2050 != 0:
		print(-1)
	else:
		print(getSum(n // 2050))


n = int(input())
while n != 0:
	p = int(input())
	sum = 0
	if p % 2050 == 0:
		nn = p // 2050
		while nn != 0:
			d = nn % 10
			sum = sum + d
			nn = nn // 10
		print(sum)
	else:
		print('-1')
	n = n - 1


from collections import Counter, deque
from itertools import accumulate, product, groupby
import operator
import math
from functools import reduce

def solve():
	num = int(input())
	if num % 2050 != 0:
		return -1
	num //= 2050
	return sum([int(char) for char in str(num)])
for _ in range(int(input())):
	print(solve())


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	if n % 2050:
		print(-1)
		continue
	n = n // 2050
	ans = 0
	while n > 0:
		ans += n % 10
		n = n // 10
	print(ans)


n = int(input())
l = []
for i in range(n):
	p = int(input())
	l.append(p)
for i in l:
	if i % 2050 == 0:
		main_var = 2050
		length = len(list(str(i)))
		if length > 4:
			main_var *= pow(10, length - 4)
		count = 0
		while 1:
			count += i // main_var
			i = i % main_var
			if i < main_var:
				main_var //= 10
			if i == 0:
				break
		print(count)
	else:
		print('-1')


import sys
r = sys.stdin.readline
for _ in range(int(r())):
	N = int(r())
	ans = 0
	while 1:
		s = 2050
		if N == 0:
			print(ans)
			break
		if N < 2050:
			print(-1)
			break
		while N >= 10 * s:
			s *= 10
		N -= s
		ans += 1


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2050 == 0:
		d = n // 2050
		print(sum(map(int, str(int(d)))))
	else:
		print(-1)


def solve():
	a = int(input())
	if a % 2050:
		print(-1)
		return
	a //= 2050
	s = 0
	while a > 0:
		s += a % 10
		a //= 10
	print(s)
t = int(input())
for i in range(t):
	solve()


import sys

def ans(n):
	if n < 100:
		return n
	k = 0
	while n > 0:
		k = k + n % 10
		n = n // 10
	return ans(k)
for _ in range(int(input())):
	n = int(input())
	if n < 2050:
		print(-1)
		continue
	if n % 2050 != 0:
		print(-1)
		continue
	solo = n // 2050
	c = 0
	while solo > 0:
		c = c + solo % 10
		solo = solo // 10
	print(c)


import functools
tests = int(input())
m = 2050
for case in range(tests):
	n = int(input())
	if n % m != 0:
		print(-1)
	else:
		print(functools.reduce(lambda a, b: int(a) + int(b), str(int(n / m))))


try:
	t = int(input())
	while t > 0:
		n = int(input().strip())
		if n % 2050 != 0:
			print('-1')
		else:
			s = 0
			p = str(n // 2050)
			for i in p:
				s += int(i)
			print(s)
		t -= 1
except:
	pass


for i in range(int(input())):
	n = int(input())
	ans = 0
	if n % 2050 != 0:
		print(-1)
	else:
		s = n // 2050
		while s:
			ans = ans + s % 10
			s = s // 10
		print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	if n == 0:
		print(1)
		continue
	if n % 2050 != 0:
		print(-1)
		continue
	ans = 0
	for i in range(18, -1, -1):
		num2050 = 2050 * 10 ** i
		j = 1
		while j * num2050 <= n:
			j += 1
		if j * num2050 == n:
			ans += j
			break
		j -= 1
		ans += j
		n -= j * num2050
		if n == 0:
			break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		nn = n // 2050
		print(sum([int(s) for s in str(nn)]))


t = int(input())
for i in range(t):
	n = int(input())
	q = n // 2050
	r = n % 2050
	if r == 0:
		if q == 0 and r == 0:
			print(-1)
		elif q < 10 and r == 0:
			print(q)
		else:
			s = 0
			while q != 0:
				d = q % 10
				s += d
				q = q // 10
			print(s)
	else:
		print(-1)


n = int(input())
for i in range(n):
	t = int(input())
	if t < 2050 or t % 2050 != 0:
		print(-1)
	else:
		z = t // 2050
		z = list(str(z))
		z = map(int, z)
		print(sum(z))


attempts = int(input())
for i in range(attempts):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		wii = int(n / 2050)
		answer = 0
		for i in str(wii):
			answer = answer + int(i)
		print(answer)


from sys import stdin, stdout
input = stdin.readline
I = int
R = range
listInput = lambda : list(map(int, input().strip().split()))
lineInput = lambda : map(int, input().strip().split())

def main():
	for _ in R(I(input())):
		n = I(input().strip())
		if n % 2050 != 0:
			print(-1)
			continue
		ansDigits = n // 2050
		print(sum(map(int, str(ansDigits))))
main()


for _ in range(int(input())):
	n = int(input())
	if n % 2050:
		print('-1')
	else:
		s = str(n // 2050)
		ans = 0
		for y in s:
			ans += int(y)
		print(ans)


for _ in range(int(input())):
	n = int(input())
	if n % 2050 == 0:
		i = 18
		coun = 0
		while i >= 0:
			if n >= 2050 * 10 ** i:
				n -= 2050 * 10 ** i
				coun += 1
			else:
				i -= 1
		print(coun)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
		continue
	x = n // 2050
	c = 0
	for m in str(x):
		c += int(m)
	print(c)


for test in range(int(input())):
	n = int(input())
	ans = 0
	val = 2050
	for j in range(15, -1, -1):
		div = val * 10 ** j
		if n // div > 0:
			ans += n // div
			n = n % div
	if n == 0:
		print(ans)
	else:
		print(-1)


ct = 0
test = int(input())
for i in range(test):
	num = int(input())
	if num % 2050 != 0:
		print(-1)
	else:
		num = int(num / 2050)
		while num:
			ct = ct + num % 10
			num = int(num / 10)
		print(ct)
		ct = 0


for t in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
		continue
	else:
		x = n // 2050
		count = 0
		while x > 0:
			count += x % 10
			x //= 10
		print(count)


for _ in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		res = n // 2050
		c = 0
		for i in str(res):
			c += int(i)
		print(c)


import sys

def solve(a):
	if a % 2050:
		return -1
	res = 0
	x = a // 2050
	for c in str(x):
		res += int(c)
	return res
n = int(sys.stdin.readline())
for _ in range(n):
	a = int(sys.stdin.readline())
	res = solve(a)
	print(res)


from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve(n):
	if n % 2050 != 0:
		return -1
	n = n // 2050
	ans = 0
	while n > 0:
		ans += n % 10
		n = n // 10
	return ans
test = 1
test = int(input().strip())
for t in range(0, test):
	n = int(input().strip())
	ans = solve(n)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	rem = sum([int(x) for x in list(str(n // 2050))])
	if rem == 0:
		print(-1)
	elif n % 2050 != 0:
		print(-1)
	else:
		print(rem)


def find(n):
	if n % 2050 == 0:
		k = n // 2050
		t = 0
		while k > 0:
			t += k % 10
			k //= 10
		return t
	return -1
for _ in range(int(input())):
	n = int(input())
	print(find(n))


q = int(input())
for i in range(q):
	n = int(input())
	if n % 2050 != 0:
		print('-1')
	else:
		n = n // 2050
		w = str(n)
		s = 0
		for j in w:
			s += int(j)
		print(s)


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

def mapIn():
	return map(int, input().split())
d = [0] * 16
for i in range(16):
	d[i] = 2050 * pow(10, i)
for ii in range(int(input())):
	n = int(input())
	if n % 2050:
		print(-1)
	else:
		ans = 0
		for i in range(14, -1, -1):
			ans += n // d[i]
			n = n % d[i]
		print(ans)


def solve(n):
	SUMA = 2050
	if n % SUMA == 0:
		n //= SUMA
		ans = 0
		while n > 0:
			m = n % 10
			ans += m
			n //= 10
		return ans
	return -1

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		ans = solve(n)
		print(ans)
main()


a = int(input())
for i in range(a):
	b = int(input())
	if b < 2050 or b % 2050 != 0:
		print(-1)
	else:
		emp = list(map(int, str(b // 2050)))
		print(sum(emp))


for _ in range(int(input())):
	n = int(input())
	if n % 2050 == 0:
		k = str(n // 2050)
		sum1 = 0
		for i in k:
			sum1 += int(i)
		print(sum1)
	else:
		print('-1')


n = int(input())
while n:
	num = int(input())
	if num % 2050 != 0:
		print(-1)
	else:
		total = 0
		num = num // 2050
		for s in str(num):
			total += int(s)
		print(total)
	n -= 1


def isValid(number):
	if number % 2050 != 0:
		return -1
	number = number // 2050
	sum = 0
	while number > 0:
		sum += number % 10
		number = number // 10
	return sum
t = int(input())
while t:
	t -= 1
	print(isValid(int(input())))


t = int(input())
for i in range(t):
	a = int(input())
	i = 16
	s = 0
	while i >= 0:
		if a - 2050 * 10 ** i >= 0:
			a -= 2050 * 10 ** i
			s += 1
		else:
			i -= 1
	if a > 0:
		print(-1)
	else:
		print(s)


def kval(num):
	sum = 2050
	while num >= sum:
		sum *= 10
	return sum // 10
for i in range(int(input())):
	n = int(input())
	s = 0
	if n % 2050 != 0:
		print(-1)
	else:
		while n > 0:
			n -= kval(n)
			s += 1
		print(s)


for _ in ' ' * int(input()):
	n = int(input())
	if n % 2050:
		print(-1)
	else:
		p = 2050
		while p < n:
			p *= 10
		ans = 0
		while p >= 2050:
			if n >= p:
				ans += n // p
				n = n - p * (n // p)
			p = p // 10
		print(ans)


t = int(input())

def solve():
	n = int(input())
	ans = 0
	while n >= 2050:
		sub = 2050
		while sub * 10 <= n:
			sub *= 10
		n -= sub
		ans += 1
	if n == 0:
		print(ans)
	else:
		print(-1)
for i in range(t):
	solve()


def solve():
	n = int(input())
	if n % 2050 == 0:
		num = n // 2050
		res = num % 10
		num = num // 10
		while num > 0:
			res += num % 10
			num = num // 10
		print(res)
		return
	print(-1)
for _ in range(int(input())):
	solve()


for i in [int(input()) for _ in range(int(input()))]:
	print(-1 if i % 2050 != 0 else sum((int(j) for j in str(i // 2050))))


t = int(input())
while t:
	n = int(input())
	q = 2050 * 10 ** 18
	ans = 0
	for i in range(19):
		ans += n // q
		n %= q
		q //= 10
	if n == 0:
		print(ans)
	else:
		print(-1)
	t -= 1


def sumDigits(n):
	sum = 0
	while n:
		sum += n % 10
		n //= 10
	return sum
t = int(input())
while t:
	if t == 0:
		break
	t -= 1
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		print(sumDigits(n // 2050))


t = int(input())
for i in range(0, t):
	n = int(input())
	if n % 2050 != 0:
		print('-1')
		continue
	no = int(n / 2050)
	le = len(str(no)) - 1
	count = 0
	while no >= 1:
		a = 10 ** le
		n = n - 2050 * a
		count += 1
		no = int(n / 2050)
		le = len(str(no)) - 1
	print(count)


tc = int(input())
for _ in range(tc):
	n = int(input())
	l = len(str(n))
	(a, c) = (0, 0)
	while l >= 4:
		s = '2050' + '0' * (l - 4)
		ss = int(s)
		if n % ss == 0:
			a += n // ss
			c = 1
			break
		elif n > ss:
			n -= ss
			a += 1
			l = len(str(n))
		else:
			l -= 1
	if c == 0:
		a = -1
	print(a)


for t in range(int(input())):
	inp = input()
	i = len(inp) - 3
	j = 0
	n = int(inp)
	while n > 200 and i > 0:
		while True:
			if n >= 205 * 10 ** i:
				n -= 205 * 10 ** i
				j += 1
			else:
				break
		i -= 1
	if n == 0:
		print(j)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	print(-1 if n % 2050 != 0 else sum(map(int, str(n // 2050))))


for i in range(int(input())):
	n = int(input())
	if n < 2050:
		print(-1)
	elif n % 2050 == 0:
		n = n // 2050
		n = str(n)
		ans = 0
		for i in range(len(n)):
			ans += int(n[i])
		print(ans)
	else:
		print(-1)


def tin(n):
	if n % 2050 != 0:
		return -1
	num = n // 2050
	summ = 0
	while 1:
		if num == 0:
			break
		digit = num % 10
		summ += digit
		num = num // 10
	return summ
t = int(input())
for i in range(0, t):
	n = int(input())
	print(tin(n))


numOfInputs = int(input())
inputArray = []
for i in range(numOfInputs):
	num = int(input())
	inputArray.append(num)
for each in inputArray:
	if each % 2050 != 0:
		print(-1)
	else:
		red = str(int(each / 2050))
		print(sum([int(i) for i in red]))


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	number = 2050 * 10 ** 15
	while True:
		if n < 2050:
			break
		if n >= number and number >= 2050:
			n -= number
			ans += 1
		else:
			number = number // 10
	if n != 0:
		print(-1)
	else:
		print(ans)


import sys
input = iter(sys.stdin.read().splitlines()).__next__

def solve(N):
	if N % 2050 != 0:
		return -1
	N = N // 2050
	res = 0
	while N > 0:
		res += N % 10
		N //= 10
	return res
TC = int(input())
for tc in range(TC):
	N = int(input())
	res = solve(N)
	print(res)


import math
for _ in range(int(input())):
	n = int(input())
	if n < 2050 or n % 2050 != 0:
		print(-1)
	else:
		c = n // 2050
		d = math.log(c, 10)
		if math.ceil(d) == math.floor(d):
			print(1)
		else:
			s = 0
			while c > 0:
				s = s + c % 10
				c = c // 10
			print(s)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	k = len(str(n))
	s = '2050' + (k - 4) * '0'
	if k < 4:
		print(-1)
		continue
	ans = 0
	while len(s) >= 4:
		ans += n // int(s)
		n = n % int(s)
		s = s[:len(s) - 1]
	if n == 0:
		print(ans)
	else:
		print(-1)


for ttt in range(int(input())):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		n = n // 2050
		ss = [int(str(n)[i]) for i in range(len(str(n)))]
		print(sum(ss))


t = int(input())
for i in range(t):
	x = int(input())
	y = str(x)
	count = 0
	flag = 0
	while 1:
		count += 1
		l = len(y) - 4
		x = int(x)
		if x < 2050:
			flag = 1
		x = x - 2050 * 10 ** l
		if x < 0:
			x = x + 2050 * 10 ** l
			x = x - 2050 * 10 ** (l - 1)
		if x == 0 and flag != 1:
			print(count)
			break
		if x < 2050 or flag == 1:
			print('-1')
			break
		y = str(x)


T = int(input())
for t in range(T):
	n = int(input())
	print(-1 if n % 2050 != 0 else sum([int(c) for c in str(n // 2050)]))


t = int(input())
for _ in range(t):
	n = int(input())
	k = 2050
	check = False
	if n % 2050 != 0:
		check = True
	if check:
		print(-1)
	else:
		res = str(n // 2050)
		k = 0
		for i in res:
			k += int(i)
		print(k)


T = int(input())
for _ in range(T):
	n = int(input())
	if n % 2050 != 0:
		result = -1
	else:
		n //= 2050
		result = sum((int(x) for x in str(n)))
	print(result)


trails = int(input())
answer_list = []
for x in range(trails):
	n = int(input())
	if n % 2050 != 0:
		answer = -1
	else:
		div = n // 2050
		answer = 0
		for a in str(div):
			answer += int(a)
	answer_list.append(answer)
for g in answer_list:
	print(g)


for _ in range(int(input())):
	n = int(input())
	if n % 2050 == 0:
		print(sum([int(x) for x in f'{n // 2050}']))
	else:
		print(-1)


n = int(input())
for i in range(n):
	f = int(input())
	if f % 2050 != 0:
		print(-1)
	else:
		r = 0
		rr = int(f / 2050)
		for i in str(rr):
			r += int(i)
		print(r)


for _ in range(int(input())):
	n = input()
	l = len(n)
	n = int(n)
	if l < 3:
		print(-1)
	else:
		x = l - 4
		c = 0
		for i in range(x, -1, -1):
			c += n // (2050 * 10 ** i)
			n = n % (2050 * 10 ** i)
		if n:
			print(-1)
		else:
			print(c)


t = int(input())
for i in range(t):
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		v = n // 2050
		s = 0
		x = str(v)
		for i in x:
			s = s + int(i)
		print(s)


for _ in range(int(input())):
	possible_answer: int
	not_div: int
	(possible_answer, not_div) = divmod(int(input()), 2050)
	print(-1 if not_div else sum(map(int, str(possible_answer))))


number = int(input())
for i in range(number):
	m = int(input())
	if m % 2050 != 0:
		print(-1)
	else:
		x = int(m / 2050)
		zero = 0
		for i in str(x):
			zero = zero + int(i)
		print(zero)


from sys import stdin, stdout

def inp():
	return stdin.readline()

def iinp():
	return int(stdin.readline())
t = iinp()
for i in range(t):
	n = iinp()
	if n % 2050 != 0:
		print(-1)
	else:
		cnt = 0
		while n > 0:
			x = len(str(n))
			y = int('2050' + '0' * (x - 4))
			if n < y:
				y = y // 10
			cnt += n // y
			n %= y
		print(cnt)


t = int(input())
for z in range(t):
	n = int(input())
	d = 0
	while n >= 2050:
		a = n
		c = 0
		while a != 0:
			a = a // 10
			c += 1
		b = 2050 * 10 ** (c - 4)
		if n >= b:
			n -= b
		else:
			n -= 2050 * 10 ** (c - 5)
		d += 1
	if n == 0:
		print(d)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	if n % 2050 != 0:
		print(-1)
	else:
		ans = n // 2050
		a = 0
		while ans > 0:
			temp = ans % 10
			a += temp
			ans = ans // 10
		print(a)
	t -= 1


A = []
p = 2050
for i in range(20):
	A.append(p)
	p *= 10
A = A[::-1]
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	for i in range(20):
		f = 0
		while n >= A[i]:
			n -= A[i]
			ans += 1
	if not n:
		print(ans)
	else:
		print(-1)


def sumDigit(n):
	res = 0
	while n > 0:
		res += n % 10
		n //= 10
	return res
t = int(input())
for i in range(t):
	n = int(input())
	if n % 2050 == 0:
		print(sumDigit(n // 2050))
	else:
		print(-1)


mass = []
destr = []
t = int(input())
for i in range(t):
	mass.append(int(input()))
for each in mass:
	if each % 2050 != 0:
		destr.append(int(-1))
	else:
		destr.append(sum((int(i) for i in str(each // 2050))))
for each in destr:
	print(each)


t = int(input())
for _ in range(t):
	n = input()
	ns = len(n)
	n = int(n)
	if not n % 2050 == 0:
		print('-1')
	else:
		rem = ns - 4
		ans = 0
		tp = n
		for i in range(rem, -1, -1):
			r = 2050 * 10 ** i
			f = tp // r
			ans += f
			tp = tp % r
		print(ans)


def chck(n):
	count = 0
	if len(str(n)) > 4:
		str1 = '2050' + (len(str(n)) - 4) * '0'
	elif len(str(n)) == 4:
		str1 = '2050'
	else:
		return -1
	n2 = int(str1)
	count = count + n // n2
	n = n % n2
	n2 = n2 // 10
	while n >= 2050:
		count = count + n // n2
		n = n % n2
		n2 = n2 // 10
	if n == 0:
		return count
	else:
		return -1
t = int(input())
for _ in range(t):
	n = int(input())
	print(chck(n))


n = int(input())
for i in range(n):
	s = int(input())
	if s % 2050 != 0:
		print('-1')
	else:
		d = int(s / 2050)
		sum = 0
		for digit in str(d):
			sum += int(digit)
		print(sum)


t = int(input())
while t:
	n = int(input())
	if n < 2050 or n % 2050 != 0:
		print('-1')
	else:
		n = n // 2050
		c = 0
		while n:
			c = c + n % 10
			n = n // 10
		print(c)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	n25 = 2050
	m = 18
	p = 0
	while n >= n25:
		if n25 * 10 ** m <= n:
			n -= n25 * 10 ** m
			p += 1
		else:
			m -= 1
		if m < 0:
			break
	print(-1 if p == 0 or n != 0 else p)


n = int(input(''))
lis = []
for i in range(n):
	a = int(input(''))
	lis.append(a)
for i in lis:
	if i % 2050 != 0:
		print('-1')
	else:
		s = i // 2050
		d = str(s)
		si = 0
		for j in d:
			si += int(j)
		print(si)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
for _ in range(II()):
	n = II()
	ans = 0
	while True:
		s = str(n)
		l = len(s)
		run = 0
		if l < 4:
			break
		if int(s[:4]) >= 2050:
			n -= int(str(2050) + str(0) * (l - 4))
			ans += 1
			run = 1
			continue
		elif l >= 5:
			n -= int(str(2050) + str(0) * (l - 5))
			ans += 1
			run = 1
			continue
		if run == 0:
			break
	if n == 0:
		print(ans)
	else:
		print(-1)


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, insort
from time import perf_counter
from fractions import Fraction
import copy
from copy import deepcopy
import time
starttime = time.time()
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)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
for _ in range(L()[0]):
	n = L()[0]
	if n % 2050:
		print(-1)
	else:
		x = n // 2050
		k = 0
		y = 10 ** 18
		while y != 1:
			k += x // y
			x = x % y
			y //= 10
		print(k + x)
endtime = time.time()