Allen throws for 4 TDs, Bills beat 49ers 34-24 in Arizona