Just a runnable solution
\n\nimpl Solution {\n    pub fn minimum_moves(nums: Vec<i32>, k: i32, max_changes: i32) -> i64 {\n        let n = nums.len();\n        let mut ones = vec![];\n 
\n```\nimpl Solution {\n    pub fn minimum_moves(nums: Vec<i32>, k: i32, max_changes: i32) -> i64 {\n        let n = nums.len();\n        let mut ones = vec![];\n        for (i, &nums_i) in nums.iter().enumerate().take(n) {\n            if nums_i == 1 {\n                ones.push(i);\n            }\n        }\n        if ones.is_empty() {\n            return 2 * k as i64;\n        }\n        let mut duo = -1;\n        let mut trio = -1;\n        for i in 0..n - 1 {\n            if nums[i] == 1 && nums[i + 1] == 1 {\n                duo = i as i32;\n            }\n        }\n        for i in 0..n - 2 {\n            if nums[i] + nums[i + 1] + nums[i + 2] == 3 {\n                trio = i as i32;\n            }\n        }\n        let mut hi = 1;\n        if duo != -1 {\n            hi = 2;\n        }\n        if trio != -1 {\n            hi = 3;\n        }\n        if max_changes + hi >= k {\n            hi = hi.min(k);\n            let k = k - hi;\n            return (hi - 1 + 2 * k) as _;\n        }\n        let m = ones.len();\n        let mut p = vec![0; m + 1];\n        for i in 0..m {\n            p[i + 1] = p[i] + ones[i] as i64;\n        }\n        let k = k - max_changes;\n        let precost = 2 * max_changes as i64;\n        let mut ans = std::i64::MAX;\n        for l in 0..m as i32 - k + 1 {\n            let r = l + k - 1;\n            let im = (r + l) / 2;\n            let mid = ones[im as usize] as i64;\n            let lsum = p[im as usize + 1] - p[l as usize];\n            let rsum = p[r as usize + 1] - p[im as usize];\n            let left = mid * (im - l + 1) as i64 - lsum;\n            let right = rsum - mid * (r - im + 1) as i64;\n            ans = ans.min(precost + left + right);\n        }\n        ans\n    }\n}\n```
['Rust']