input: Write a function to add three months to a given date string.
  assert add_three_months('2020-01-31') == '2020-04-30'
  assert add_three_months('2020-02-29') == '2020-05-29'
  assert add_three_months('2021-11-30') == '2022-02-28'
output: def add_three_months(date_str):
      from datetime import datetime
      from dateutil.relativedelta import relativedelta
  
      date = datetime.strptime(date_str, '%Y-%m-%d')
      new_date = date + relativedelta(months=3)
  
      # Handle the case where the resulting day doesn't exist in the target month
      # For example, adding 3 months to January 31 should result in April 30
      while new_date.month != (date.month + 3 - 1) % 12 + 1:
          new_date -= relativedelta(days=1)
  
      return new_date.strftime('%Y-%m-%d')