if let N = Int(readLine() ?? "") { var maxSum: [Int] = [0,0,0] var minSum: [Int] = [0,0,0] for _ in 1...N { if let input = readLine(), let nums = input.split(separator: " ").compactMap({Int($0)}) as? [Int], nums.count == 3 { let a = nums[0]; let b = nums[1]; let c = nums[2] let tempMax = maxSum; let tempMin = minSum maxSum[0] = max(tempMax[0], tempMax[1]) + a maxSum[1] = (tempMax.max() ?? 0) + b maxSum[2] = max(tempMax[1], tempMax[2]) + c minSum[0] = min(tempMin[0], tempMin[1]) + a minSum[1] = (tempMin.min() ?? 0) + b minSum[2] = min(tempMin[1], tempMin[2]) + c } } print(maxSum.max() ?? 0, minSum.min() ?? 0) }