// 演算法 / Algorithm:
// 8 個按鍵。第 i 個字母(0-indexed)成本 = i/8 + 1(前 8 個按 1 次、下 8 個按 2 次…)。
// 因字母不重複,只需按順序把每個成本加總即得最少總按鍵次數。
// 8 keys; letter i costs i/8 + 1. Distinct letters, so just sum the costs.

class Solution {
public:
    int minimumPushes(string word) {
        int n = word.size();         // string::size() 直接取得長度 / length of the word
        int ans = 0;                 // 累加答案 / running total of pushes
        for (int i = 0; i < n; i++) {// 走訪每個字母的位置 / loop over each position
            // i / 8: 整數除法決定成本層 (0,1,2...) / integer division picks the layer
            // + 1: 每層至少按 1 次 / every layer costs at least one push
            ans += i / 8 + 1;        // 加上第 i 個字母的成本 / add cost of letter i
        }
        return ans;                  // 回傳最少總按鍵次數 / return the minimum pushes
    }
};
