from typing import Counter


def count_passwords(r_start: int, r_end: int):
    """ Calculate the number of passwrods that meet the predefined criteria """
    counter = 0
    for i in range(r_start, r_end):
        numbers = str(i)
        prev = numbers[0]
        if len(numbers) != 6:
            continue
        increasing, similar_digits = True, set()
        for x in numbers[1:]:
            if prev > x:
                increasing = False
                break
            if prev == x:
                similar_digits.add(x)
            prev = x
        histogram = Counter(numbers)
        proper_similar_digits = any(
            [histogram[x] == 2 for x in similar_digits])
        if increasing and proper_similar_digits:
            counter += 1
    return counter