#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
// 分治法:找出 arr[left...right] 區間的最小值與最大值
pair<int, int> findMinMax(const vector<int>& arr, int left, int right) {
// 若只有一個元素
if (left == right) {
return {arr[left], arr[left]};
}
// 若只有兩個元素,直接比較
if (right - left == 1) {
if (arr[left] < arr[right])
return {arr[left], arr[right]};
else
return {arr[right], arr[left]};
}
// 將陣列分成兩半
int mid = left + (right - left) / 2;
auto leftPair = findMinMax(arr, left, mid);
auto rightPair = findMinMax(arr, mid + 1, right);
// 合併左右兩邊的結果
int overallMin = min(leftPair.first, rightPair.first);
int overallMax = max(leftPair.second, rightPair.second);
return {overallMin, overallMax};
}
int main() {
// 讀取一行輸入
string line;
getline(cin, line);
istringstream iss(line);
vector<int> arr;
int num;
while (iss >> num) {
arr.push_back(num);
}
if (arr.empty()) {
cout << "No input provided." << endl;
return 0;
}
// 使用分治法求最小值與最大值
auto result = findMinMax(arr, 0, arr.size() - 1);
int minVal = result.first;
int maxVal = result.second;
// 輸出最大值與最小值的差值
cout << (maxVal - minVal) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIOWIhuayu+azle+8muaJvuWHuiBhcnJbbGVmdC4uLnJpZ2h0XSDljYDplpPnmoTmnIDlsI/lgLzoiIfmnIDlpKflgLwKcGFpcjxpbnQsIGludD4gZmluZE1pbk1heChjb25zdCB2ZWN0b3I8aW50PiYgYXJyLCBpbnQgbGVmdCwgaW50IHJpZ2h0KSB7CiAgICAvLyDoi6Xlj6rmnInkuIDlgIvlhYPntKAKICAgIGlmIChsZWZ0ID09IHJpZ2h0KSB7CiAgICAgICAgcmV0dXJuIHthcnJbbGVmdF0sIGFycltsZWZ0XX07CiAgICB9CiAgICAvLyDoi6Xlj6rmnInlh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