AtCoder Beginner Contest 136 - Uneven Numbers

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

-----Constraints-----
 - 1 \leq N \leq 10^5

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
Print the number of positive integers less than or equal to N that have an odd number of digits.

-----Sample Input-----
11

-----Sample Output-----
9

Among the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \ldots, 9.

Difficulty: EASY

Starter code:

Solutions:
n = int(input())
ans = 0
for i in range(1, n + 1):
	if len(str(i)) & 1 == 1:
		ans += 1
print(ans)


print(len(list(filter(lambda n: len(str(n)) % 2 == 1, range(1, int(input()) + 1)))))


N = int(input())
sum = 0
for i in range(N):
	sum += len(str(i + 1)) % 2
print(sum)


N = int(input())
cnt = 0
for i in range(1, N + 1):
	if len(str(i)) & 1 == 1:
		cnt += 1
print(cnt)


N = int(input())
n = list(map(int, str(N)))
a = len(n)
if a % 2 == 0:
	print(int((10 ** int(a) - 1) / 11))
elif a == 1:
	print(N)
else:
	print(int((100 ** int(a / 2) - 1) / 11) + N - 10 ** int(a - 1) + 1)


print(sum([1 for _ in range(1, int(input()) + 1) if len(str(_)) % 2 == 1]))


n = int(input())
res = 0
for i in range(1, n + 1):
	if len(str(i)) % 2:
		res += 1
print(res)


N = int(input())
A = 0
for i in range(1, N + 1):
	if len(str(i)) % 2 == 1:
		A += 1
print(A)


N = int(input())
ans = 0
for i in range(1, N + 1):
	num = len(str(i))
	if num % 2 != 0:
		ans += 1
print(ans)


a = int(input())
b = [i for i in range(a) if len(str(i + 1)) % 2 != 0]
print(len(b))


n = int(input())
l = [i for i in range(1, 1 + n) if len(str(i)) % 2 == 1]
print(len(l))


n = int(input())
num_list = []
num_odd_list = []
for i in range(1, n + 1):
	num_list.append(i)
for j in num_list:
	if 10 <= j < 100 or 1000 <= j < 10000 or 100000 <= j < 1000000:
		num_odd_list.append(j)
print(len(num_list) - len(num_odd_list))


N = int(input())
kazu = 1
if N < 10:
	kazu = N
elif N < 100:
	kazu = 9
elif N < 1000:
	kazu = N - 90
elif N < 10000:
	kazu = 900 + 9
elif N < 100000:
	kazu = N - 9000 - 90
elif N == 100000:
	kazu = 90000 + 900 + 9
print(kazu)


N = int(input())
cnt = 0
for i in range(1, N + 1):
	S = list(str(i))
	if len(S) % 2 != 0:
		cnt += 1
print(cnt)


n = int(input())
ans = 0
for i in range(1, n + 1):
	s = list(str(i))
	if len(s) % 2 == 1:
		ans += 1
print(ans)


n = int(input())
ans = sum((len(str(i)) % 2 for i in range(1, n + 1)))
print(ans)


n = int(input())
if n < 10:
	print(n)
elif 10 <= n <= 99:
	print(9)
elif 100 <= n <= 999:
	print(n - 90)
elif 1000 <= n <= 9999:
	print(9 + 900)
elif 10000 <= n <= 99999:
	print(n - 9090)
elif 100000 <= n <= 100000:
	print(9 + 900 + 90000)


n = int(input())
res = sum((1 for i in range(n) if len(str(i + 1)) & 1))
print(res)


N = int(input())
ans = 0
for x in range(1, N + 1):
	if len(str(x)) % 2 == 1:
		ans += 1
print(ans)


N = int(input())
N_list = []
for i in range(1, N + 1):
	if len(str(i)) % 2 == 1:
		N_list.append(i)
print(len(N_list))


N = int(input())
if N < 10:
	print(N)
elif 10 <= N and N < 100:
	print(9)
elif 100 <= N and N < 1000:
	print(9 + (N - 100 + 1))
elif 1000 <= N and N < 10000:
	print(909)
elif 10000 <= N and N < 100000:
	print(909 + (N - 10000 + 1))
else:
	print(90909)


c = 0
for i in range(1, int(input()) + 1):
	if len(str(i)) % 2 == 1:
		c += 1
print(c)


def main():
	n = int(input())
	ans = 0
	for v in range(1, n + 1):
		if len(str(v)) % 2 == 1:
			ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


def __starting_point():
	N = int(input())
	ans = 0
	for n in range(1, N + 1):
		if len(str(n)) % 2 != 0:
			ans += 1
	print(ans)
__starting_point()


N = int(input())
answer = sum((len(str(i)) & 1 for i in range(1, N + 1)))
print(answer)


N = int(input())
ans = 0
for i in range(1, N + 1):
	if len(str(i)) in [1, 3, 5]:
		ans += 1
print(ans)


print(len([None for i in range(1, int(input()) + 1) if len(str(i)) % 2]))


n = int(input())
gen = (x for x in range(1, n + 1) if len(str(x)) % 2 == 1)
print(len(list(gen)))


n = int(input())
count = 0
for i in range(1, n + 1):
	number = list(str(i))
	if len(number) % 2 != 0:
		count += 1
print(count)


a = input()
N = int(a)
if N == 10 ** 5:
	print(90909)
elif N >= 10 ** 4:
	print(N - (9000 + 90))
elif N >= 10 ** 3:
	print(909)
elif N >= 10 ** 2:
	print(N - 90)
elif N >= 10:
	print(9)
else:
	print(N)


n = input()
l = len(n)
if l == 1:
	print(n)
elif l == 2:
	print(9)
elif l == 3:
	print(9 + int(n) - 99)
elif l == 4:
	print(909)
elif l == 5:
	print(909 + int(n) - 9999)
else:
	print(90909)


N = int(input())
l = [len(str(n)) % 2 == 1 for n in range(1, N + 1)]
print(sum(l))


def resolve():
	n = int(input())
	cnt = 0
	for i in range(1, n + 1):
		if len(str(i)) % 2 != 0:
			cnt += 1
	print(cnt)
resolve()


import array
import bisect

def answer(n: int) -> int:
	numbers = array.array('L')
	i = 0
	while 100 ** i <= n:
		start = 100 ** i
		stop = int('9' * len(str(start))) + 1
		numbers.extend(list(range(start, stop)))
		i += 1
	return bisect.bisect_right(numbers, n)

def main():
	n = int(input())
	print(answer(n))

def __starting_point():
	main()
__starting_point()


N = int(input())
a = 0
for i in range(N):
	a += len(str(i + 1)) & 1
print(a)


n = int(input())
l = len(str(n))
if l == 6:
	ans = 90909
elif l == 5:
	ans = n - 9090
elif l == 4:
	ans = 909
elif l == 3:
	ans = n - 90
elif l == 2:
	ans = 9
else:
	ans = n
print(ans)


import math
N = int(input())
m = int(math.log10(N)) + 1
a = N // pow(10, m)
ans = 0
for i in range(1, m, 2):
	ans += 9 * pow(10, i - 1)
if m % 2 == 1:
	ans += N - pow(10, m - 1) + 1
print(ans)


n = int(input())
ret = 0
for i in range(1, n + 1):
	ret += len(str(i)) % 2
print(ret)


N = int(input())
print(len(list(filter(lambda x: len(str(x)) % 2 == 1, range(1, N + 1)))))


N = int(input())

def ans136(N):
	odd_count = 0
	for i in range(1, N + 1):
		if len(str(i)) % 2 == 1:
			odd_count += 1
	return odd_count
print(ans136(N))


n = int(input())
count = 0
for i in range(1, n + 1):
	s = str(i)
	if len(s) % 2 != 0:
		count += 1
print(count)


S = str(input())
N = len(S)
ans = 0
for i in range(1, N, 2):
	ans += 9 * 10 ** (i - 1)
if N % 2 != 0:
	ans += int(S) - 10 ** (N - 1) + 1
print(ans)


n = int(input())
print(sum((1 for x in range(1, n + 1) if len(str(x)) % 2 == 1)))


N = int(input())
print(len([1 for n in range(1, N + 1) if len(str(n)) % 2 != 0]))


N = int(input())
ii = 0
for i in range(1, N + 1):
	s = str(i)
	if len(s) % 2 == 1:
		ii += 1
print(ii)


n = int(input())
print(min(9, n) + max(0, min(999, n) - 99) + max(0, min(99999, n) - 9999))


N = input()
n = int(N)
ans = 0
if len(N) == 1:
	print(n)
	return
if len(N) % 2 == 1:
	ans += n - 10 ** (len(N) - 1) + 1
	n -= ans
	for i in range(1, len(str(n)) + 1):
		if i % 2 == 1:
			ans += 9 * 10 ** (i - 1)
	print(ans)
else:
	n -= n - 10 ** (len(N) - 1) + 1
	for i in range(1, len(str(n)) + 1):
		if i % 2 == 1:
			ans += 9 * 10 ** (i - 1)
	print(ans)


N = int(input())
count = sum((1 for n in range(1, N + 1) if len(str(n)) % 2 == 1))
print(count)


n = int(input())
r = len(list(filter(lambda x: len(str(x)) % 2 != 0, range(1, n + 1))))
print(r)


N = int(input())
a = sum((1 for i in range(1, N + 1) if len(str(i)) % 2 == 1))
print(a)


result = 0
for n in range(int(input())):
	result += len(str(n + 1)) % 2
print(result)


n = int(input())
cnt = 0
while n > 0:
	if len(str(n)) % 2 != 0:
		cnt += 1
	n -= 1
print(cnt)


print(sum((1 for i in range(1, int(input().strip()) + 1) if len(str(i)) % 2 == 1)))


m = int(input())
ans = 0
for i in range(1, m + 1):
	if len(str(i)) % 2 == 1:
		ans += 1
print(ans)


n = int(input())
print(sum((len(str(s)) % 2 == 1 for s in range(1, n + 1))))


n = int(input())
s = len(str(n))
if s == 1:
	print(n)
elif s == 2:
	print(9)
elif s == 3:
	print(n - 90)
elif s == 4:
	print(9 + 900)
elif s == 5:
	print(9 + 900 + n - 10000 + 1)
else:
	print(90909)


n = int(input())
ans = 0

def check_even(n):
	n_l = list(str(n))
	n_count = len(n_l)
	if n_count % 2 == 0:
		return True
	else:
		return False
for i in range(1, n + 1):
	if check_even(i):
		continue
	ans += 1
print(ans)


n = int(input())
l = list()
for i in range(1, n + 1):
	m = list(str(i))
	if len(m) % 2 != 0:
		l.append(i)
print(len(l))


n = int(input())
ns = range(1, n + 1)
ans = len([n for n in ns if len(str(n)) % 2 == 1])
print(ans)


n = int(input())
print(len([l for l in list(map(str, range(1, n + 1))) if len(l) % 2 == 1]))


N = int(input())
print(len(list((i for i in range(1, N + 1) if len(str(i)) % 2 == 1))))


N = int(input())
print(sum([1 if len(list(str(x))) % 2 != 0 else 0 for x in range(1, N + 1)]))


N = int(input())
n = len(str(N))
ans = 0
for i in range(1, n + 1):
	if i == n and n % 2 != 0:
		ans += N - 10 ** (n - 1) + 1
		break
	elif i % 2 != 0:
		ans += 9 * 10 ** (i - 1)
print(ans)


N = int(input())
Uneven_Numbers = []
for i in range(1, N + 1):
	count = len(str(i))
	if count % 2 != 0:
		Uneven_Numbers.append(i)
print(len(Uneven_Numbers))


N = int(input())
count = 0
for i in range(1, N + 1):
	if len(str(i)) % 2 == 0:
		continue
	else:
		count += 1
print(count)


a = int(input())
ans = -1
for i in range(a + 1):
	if len(str(i)) % 2 == 1:
		ans += 1
print(ans)


n = int(input())
print(len(tuple(filter(lambda x: len(str(x)) % 2 == 1, range(1, n + 1)))))


n = input()
l = len(n)
a = '090909'[:l]
print(a[1:] if l % 2 == 0 else int(n) - int(a))


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

def I():
	return map(int, input().split())
mod = 10 ** 9 + 7

def main():
	n = int(input())
	ans = 0
	for i in range(1, n + 1):
		if len(str(i)) % 2 == 1:
			ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
import math
digit = int(math.log10(N)) + 1
S = 0
if digit % 2 == 0:
	for i in range(1, int(digit / 2) + 1):
		S += pow(10, 2 * i - 1) - pow(10, 2 * i - 2)
	print(S)
if digit % 2 == 1:
	for i in range(1, int((digit + 1) / 2)):
		S += pow(10, 2 * i - 1) - pow(10, 2 * i - 2)
	S += N - pow(10, digit - 1) + 1
	print(S)


import math
n = int(input())
count = 0
for i in range(n):
	if len(str(i)) % 2 != 0:
		count += 1
if len(str(n)) % 2 == 0:
	count -= 1
print(count)


import math
import collections
import itertools

def resolve():
	N = int(input())
	ans = 0
	for i in range(1, N + 1):
		if 10 <= i <= 99 or 1000 <= i <= 9999 or 100000 <= i <= 999999:
			continue
		ans += 1
	print(ans)
resolve()


print(sum((bool(num + 1) for num in range(int(input())) if len(str(num + 1)) % 2 == 1)))


from math import log10
print(sum((not int(log10(n)) & 1 for n in range(1, int(input()) + 1))))


n = int(input())
cnt = 0
for i in range(1, n + 1):
	cnt += len(str(i)) & 1
print(cnt)


n = int(input())
a = [i for i in range(1, n + 1) if len(list(str(i))) % 2 == 1]
print(len(a))


N = int(input())
ct = 0
for i in range(1, N + 1):
	l = len(str(i))
	if l % 2 == 1:
		ct += 1
print(ct)


n = int(input())
print(sum(map(lambda x: len(str(x)) & 1, range(1, n + 1))))


N = int(input())
keta = []
for i in range(1, N + 1):
	keta.append(len(str(i)))
odd = list(filter(lambda n: n % 2 == 1, keta))
print(len(odd))


N = int(input())
ans = 0

def count_dig(N):
	cnt = 0
	while True:
		cnt += 1
		if N < 10:
			break
		else:
			N /= 10
	return cnt
for i in range(1, N + 1):
	if count_dig(i) % 2 == 1:
		ans += 1
print(ans)


import math
N = int(input())
print(sum([int(math.log10(x)) % 2 == 0 for x in range(1, N + 1)]))


N = int(input())
print(min(N, 9) + max(min(N, 999) - 99, 0) + max(min(N, 99999) - 9999, 0))


N = int(input())
i = 1
result = 0
while i <= N:
	i_l = len(str(i))
	if i_l % 2 != 0:
		result += 1
	i += 1
print(result)


n = input()
k = len(n)
print(sum((9 * 10 ** (~-i) for i in range(k) if i % 2)) - (10 ** (~-k) - int(n) - 1) * (k % 2))


a = int(input())
lis = [str(i) for i in range(1, a + 1)]
count = 0
for i in lis:
	if int(len(i)) % 2 != 0:
		count += 1
print(count)


print(sum([len(str(x + 1)) % 2 for x in range(0, int(input()))]))