1. Abridged Problem Statement
Given a target sum n (1 ≤ n ≤ 10^6), build a 1×1×k stack of standard dice (each die has opposite faces summing to 7) so that the total number of pips on the exposed faces (the four vertical sides, plus the very top and very bottom faces) is exactly n. Find the minimum k≥1 for which this is possible, or output –1 if no such stack exists.

2. Detailed Editorial

Observation on a single die's contribution:
- A single die has faces numbered 1…6. Any two opposite faces sum to 7, so the total over all six faces is 21.
- If you expose exactly four lateral faces (a die standing in the tower) but hide its top and bottom faces, the sum of those four faces is
  total of all faces – (top + bottom) = 21 – 7 = 14, regardless of orientation.

When we stack k dice in a 1×1×k tower:
- Each of the k dice contributes 14 pips from its four exposed side faces.
- The bottommost die contributes one extra face (its bottom) with some value x ∈ [1..6].
- The topmost die contributes one extra face (its top) with some value y ∈ [1..6].
Hence the total exposed-pip count satisfies
  S = 14·k + x + y,    x,y ∈ {1,2,3,4,5,6}.

Special case k=1:
- There's only one die; all six faces are exposed. That sum is fixed at 21.
- Our formula S=14·1 + x + y would suggest x+y can be anything in [2..12], but in reality x and y refer to opposite faces, so x+y=7, giving S=21 only.

General solution approach:
1. Let k = ⌊n/14⌋ and rem = n – 14·k. We try this k because 14·k is the largest multiple of 14 not exceeding n, and adding x+y can cover the remainder if 2 ≤ rem ≤ 12.
2. If k ≥ 2 and 2 ≤ rem ≤ 12, we can choose (x,y) summing to rem, so answer = k.
3. If k = 1, only rem = 7 works (that reproduces the k=1, S=21 case).
4. Otherwise, no valid stack exists, answer = –1.

Edge checks:
- rem ≤ 1 ⇒ too small to be x+y (which must be ≥2).
- rem ≥ 13 ⇒ too large for x+y (max 12).
- k = 0 ⇒ n < 14, and if n≠21 no solution; but n=21 gives k=1, so when k=0 rem=n<14 we fail here (will report –1) but n=21 has k=1 not 0.

Time complexity is O(1) per query.

3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;

void read() { cin >> n; }

void solve() {
    // The four side faces of one die always sum to 14 (the six faces sum to 21
    // and the hidden top/bottom pair sums to 7). So a tower of h dice exposes
    // 14 * h dots on its sides, plus the very top face and the very bottom
    // face. For h >= 2 those two extreme faces are independent, each in 1..6,
    // contributing any s in [2, 12]; thus n = 14 * h + s with s = n % 14 forces
    // s to lie in [2, 12]. For h = 1 the top and bottom are opposite faces of
    // the same die and sum to exactly 7, so the only achievable total is 21.

    int num_dice = n / 14;
    int rem = n % 14;

    if(num_dice == 1 && n != 21) {
        cout << -1 << '\n';
    } else if(num_dice == 0 || rem <= 1 || rem == 13) {
        cout << -1 << '\n';
    } else {
        cout << num_dice << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution with Detailed Comments

```python
def solve():
    # Read the target sum n
    n = int(input().strip())

    # Base splits off as many full '14 per die' as possible
    k = n // 14
    rem = n % 14

    # Case k=1: only possible if the single die shows all faces => sum=21
    if k == 1 and n != 21:
        print(-1)
        return

    # If k=0 => n < 14 (and only n=21 works but that's k=1)
    # If remainder rem <= 1 or rem >= 13 => no way to choose top+bottom faces in [1..6]
    if k == 0 or rem <= 1 or rem >= 13:
        print(-1)
    else:
        # We can pick two face-values x,y in [1..6] summing to rem (2..12)
        print(k)

if __name__ == "__main__":
    solve()
```

5. Compressed Editorial

- Model total exposed pips as S = 14·k + x + y, where k is number of dice, x,y∈[1..6] are bottom/top face pips.
- For k≥2: x+y can range 2..12, so S∈{14k+2,…,14k+12}.
- For k=1: the top and bottom are opposite faces ⇒ x+y=7 ⇒ S=21 only.
- Given n, set k = ⌊n/14⌋, rem = n−14k.
  • If k=1: accept only n=21.
  • Else if (k≥2 and 2≤rem≤12) ⇒ answer k.
  • Otherwise no solution ⇒ –1.
