<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def datetime_to_nanos(dt):
 """ Accepts a string, Pandas Timestamp, or long, and returns nanos since the epoch. """

    if isinstance(dt, pd.Timestamp):
        return dt.value
    elif isinstance(dt, str):
        return pd.Timestamp(dt).value
    elif isinstance(dt, long):
        return dt
    elif isinstance(dt, datetime):
	return long(dt.strftime("%s%f")) * 1000

    raise ValueError