import sys

# '19xx' literally would be accepted as well but we won't tell anyone
def solve(lines):
    def detect_date(s):
        date_f = "19XX r."
        date_l = len(date_f)

        j = 0
        for i in range(len(s)):
            c = s[i]

            if j == date_l:
                return True
            elif c == date_f[j] \
                or (j in (2, 3) and c.isdigit()):
                j += 1
                continue

            j = 0

        return False

    return filter(detect_date, lines)


if __name__ == "__main__":
    lines = []
    
    fp = sys.argv[1]
    with open(fp, encoding="utf-8") as f: # following symlinks might not work on Windows
        lines = f.readlines()
    sol = solve(lines)
    with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f:
        f.writelines(sol)