My Solution
1. Calculate according to the different situations\n\n/**\n * Time Complexity: O(n)\n * Space Complexity: O(1)\n */\nclass Solution {\n public:\n  vector<long l
**1. Calculate according to the different situations**\n```\n/**\n * Time Complexity: O(n)\n * Space Complexity: O(1)\n */\nclass Solution {\n public:\n  vector<long long> countOfPairs(const int n, const int x, const int y) {\n    if (x > y) {\n      return countOfPairs(n, y, x);\n    }\n    \n    vector<long long> ret(n);\n    if (y - x < 2) {\n      handle_a_a(n, ret);\n      return ret;\n    }\n    \n    /**\n     * 1, 2, ..., x, x + 1, ..., y, y + 1, ..., n\n     * let\n     * 1. interval `a` is [1, x - 1]\n     * 2. interval `b` is [x, y]\n     * 3. interval `c` is [y + 1, n]\n     */\n    /**\n     * case 1: two houses are both in the interval `a`\n     */\n    handle_a_a(x - 1, ret);\n    /**\n     * case 2: two houses are both in the interval `c`\n     */\n    handle_a_a(n - y, ret);\n    /**\n     * case 3: one house is in the interval `a`,\n     *         and the other house is in the interval `b`\n     */\n    handle_a_b(x - 1, y - x + 1, ret);\n    /**\n     * case 4: one house is in the interval `c`,\n     *         and the other house is in the interval `b`\n     */\n    handle_a_b(n - y, y - x + 1, ret);\n    /**\n     * case 5: one house is in the interval `a`,\n     *         and the other house is in the interval `c`\n     */\n    handle_a_c(x - 1, n - y, ret);\n    /**\n     * case 6: two houses are both in the interval `b`\n     */\n    handle_b_b(y - x + 1, ret);\n    return ret;\n  }\n  \n private:\n  void handle_a_a(const int a, vector<long long> &result) {\n    for (int streets = 1; streets < a; ++streets) {\n      /**\n       * assume that streets start from `start`, and end with `end`\n       * 1 <= start <= a\n       * 1 <= end <= a\n       * end = start + streets\n       *        ||\n       *        \\/\n       * 1 <= start <= a\n       * 1 - streets <= start <= a - streets\n       */\n      const int lower = max(1, 1 - streets);\n      const int upper = min(a, a - streets);\n      result[streets - 1] += (upper - lower + 1) << 1;\n    }\n  }\n  \n  void handle_a_b(const int a, const int b, vector<long long> &result) {\n    /**\n     * like the following,\n     * 1, 2, ..., a, 1, 2, ..., b\n     *               ^          |\n     *               |--<----<--|\n     */\n    for (int streets = 1; streets < a + (b >> 1) + 1; ++streets) {\n      /**\n       * the first part\n       * 1, 2, ..., a, 1, 2, ..., (b / 2) + 1\n       * assume that streets start from `start`, and end with `end`\n       * 1 <= start <= a\n       * a + 1 <= end <= a + (b / 2) + 1\n       * end = start + streets\n       *        ||\n       *        \\/\n       * 1 <= start <= a\n       * a + 1 - streets <= start <= a + (b / 2) + 1 - streets\n       */\n      {\n        const int lower = max(1, a + 1 - streets);\n        const int upper = min(a, a + (b >> 1) + 1 - streets);\n        result[streets - 1] += (upper - lower + 1) << 1;\n      }\n      /**\n       * the second part\n       * 1, 2, ..., a, 1, 2, ..., b - ((b / 2) + 1) + 1\n       * assume that streets start from `start`, and end with `end`\n       * 1 <= start <= a\n       * a + 2 <= end <= a + (b - (b / 2))\n       * end = start + streets\n       *        ||\n       *        \\/\n       * 1 <= start <= a\n       * a + 2 - streets <= start <= a + (b - (b / 2)) - streets\n       */\n      {\n        const int lower = max(1, a + 2 - streets);\n        const int upper = min(a, a + (b - (b >> 1)) - streets);\n        result[streets - 1] += (upper - lower + 1) << 1;\n      }\n    }\n  }\n  \n  void handle_a_c(const int a, const int c, vector<long long> &result) {\n    /**\n     * like the following,\n     * 1, 2, ..., a, x, y, 1, 2, ..., c\n     */\n    for (int streets = 3; streets < a + 2 + c; ++streets) {\n      /**\n       * assume that streets start from `start`, and end with `end`\n       * 1 <= start <= a\n       * a + 3 <= end <= a + 2 + c\n       * end = start + streets\n       *        ||\n       *        \\/\n       * 1 <= start <= a\n       * a + 3 - strees <= start <= a + 2 + c - streets\n       */\n      const int lower = max(1, a + 3 - streets);\n      const int upper = min(a, a + 2 + c - streets);\n      result[streets - 1] += (upper - lower + 1) << 1;\n    }\n  }\n  \n  void handle_b_b(const int b, vector<long long> &result) {\n    /**\n     * like the following,\n     * 1, 2, ..., b\n     * ^          |\n     * |--<----<--|\n     */\n    for (int streets = 1; streets < (b >> 1) + 1; ++streets) {\n      result[streets - 1] += streets != b - streets ? (b << 1) : b;\n    }\n  }\n};\n```
[]