Write a program to count the number of balanced parentheses in a string.
Given a string containing only ( and ), return the number of matched pairs. A closing parenthesis matches an earlier unmatched opening parenthesis; unmatched parentheses are ignored.
Input is a string, and output is an integer.
Example: "(()())" returns 3 because it contains three matched pairs. Example: "())(" returns 1.
def count_balanced_parentheses(s):