Optimal Gradient Sliding and its Application to Distributed Optimization Under Similarity