COUNT THE NUMBER OF HOUSES AT A CERTAIN DISTANCE || SOLUTION
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public:\n  vector<long long> countOfPairs(int n, int x, int y) {\n    if (x > y)\n      swap(x, y);\n\n    const int ringLen = y - x + 1;\n    const int leftLineLen = x - 1;\n    const int rightLineLen = n - y;\n\n    vector<long long> ans(n);\n    ans = addVectors(ans, bothInRing(n, ringLen));\n    ans = addVectors(ans, bothInTheSameLine(n, leftLineLen));\n    ans = addVectors(ans, bothInTheSameLine(n, rightLineLen));\n    ans = addVectors(ans, lineToRing(n, leftLineLen, ringLen));\n    ans = addVectors(ans, lineToRing(n, rightLineLen, ringLen));\n    ans = addVectors(ans, lineToLine(n, x, y, leftLineLen, rightLineLen));\n    for (long long& freq : ans)\n      freq *= 2;\n    return ans;\n  }\n\n private:\n  vector<long long> bothInRing(int n, int ringLen) {\n    vector<long long> res(n);\n    for (int k = 1; k <= (ringLen - 1) / 2; ++k)\n      res[k - 1] += ringLen;\n    if (ringLen % 2 == 0)\n      res[ringLen / 2 - 1] += ringLen / 2;\n    return res;\n  }\n  vector<long long> bothInTheSameLine(int n, int lineLen) {\n    vector<long long> res(n);\n    for (int k = 1; k <= lineLen; ++k)\n      res[k - 1] += lineLen - k;\n    return res;\n  }\n  vector<long long> lineToRing(int n, int lineLen, int ringLen) {\n    vector<long long> res(n);\n    for (int k = 1; k <= lineLen + ringLen; ++k) {\n      const int maxInRingLen = min(k - 1, ringLen / 2);\n      const int minInRingLen = max(0, k - lineLen);\n      if (minInRingLen <= maxInRingLen) {\n        res[k - 1] += (maxInRingLen - minInRingLen + 1) * 2;\n        if (minInRingLen == 0)\n          // Subtract 1 since there\'s no split.\n          res[k - 1] -= 1;\n        if (maxInRingLen * 2 == ringLen)\n          res[k - 1] -= 1;\n      }\n    }\n    return res;\n  }\n\n  vector<long long> lineToLine(int n, int x, int y, int leftLineLen,\n                               int rightLineLen) {\n    vector<long long> res(n);\n    for (int k = 1; k <= leftLineLen + rightLineLen + 2; ++k) {\n      const int maxInLeft = min(leftLineLen, k - 1 - (x < y));\n      const int minInLeft = max(1, k - rightLineLen - (x < y));\n      if (minInLeft <= maxInLeft)\n        res[k - 1] += maxInLeft - minInLeft + 1;\n    }\n    return res;\n  }\n\n  vector<long long> addVectors(const vector<long long>& a,\n                               const vector<long long>& b) {\n    vector<long long> res(a.size());\n    transform(a.begin(), a.end(), b.begin(), res.begin(), plus<int>());\n    return res;\n  };\n};\n```
['C++']