A Versatile Influence Function for Data Attribution with Non-Decomposable Loss