// 演算法 / Algorithm:
// 鍵盤有 8 個按鍵。把第 i 個字母(從 0 算起)的成本設為 i/8 + 1:
// 前 8 個按 1 次、接下來 8 個按 2 次…把所有成本加總即為最少總按鍵次數。
// There are 8 keys; letter i (0-indexed) costs i/8 + 1. Sum all costs.

int minimumPushes(char* word) {
    int n = 0;                       // n 記錄字母個數 / n counts the letters
    while (word[n] != '\0') {        // C 字串以 '\0' 結尾，逐字元往後數到結尾
        n++;                         // 每遇到一個字元就加一 / count each character
    }
    // 上面等同於算字串長度 strlen(word)，這裡手動寫出讓初學者看清楚
    // The loop above is just strlen(word), written out to show how it works.

    int ans = 0;                     // ans 累加總按鍵次數 / running total of pushes
    for (int i = 0; i < n; i++) {    // 依序處理第 0 到第 n-1 個字母 / for each letter
        // i / 8 是整數除法(捨去小數)，代表這個字母落在第幾「層」
        // i / 8 is integer division; it tells us which cost layer letter i is in
        // + 1 因為每層最少也要按 1 次 / +1 because the cheapest slot still costs 1
        ans += i / 8 + 1;            // 把這個字母的成本加進答案 / add this letter's cost
    }
    return ans;                      // 回傳最少總按鍵次數 / return the minimum pushes
}
