def count_paragraphs(s):
    """Counts the number of paragraphs in the given string."""
    last_line = ""
    count = 0
    for line in s.split("\n"):
        if len(line) > 0 and (len(last_line) == 0 or last_line == "\n"):
            count += 1
        last_line = line
    return count