```
class Solution {
public:
int minDistance(int height, int width, vector<int>& tree, vector<int>& squirrel, vector<vector<int>>& nuts) {
int save = INT_MIN, ans = 0;
for(auto e : nuts)
{
int distTree = abs(e[0] - tree[0]) + abs(e[1] - tree[1]);
int distSql = abs(e[0] - squirrel[0]) + abs(e[1] - squirrel[1]);
save = max(save, distTree - distSql);
ans += 2*distTree;
}
return ans - save;
}
};
```