A global simulation of the magnetosphere with a long tail: Southward and northward interplanetary magnetic field