Efficient Protocols for Distributed Classification and Optimization