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 with Line-by-Line Comments  

```cpp
#include <bits/stdc++.h>
using namespace std;

// Overload << and >> for pairs and vectors (not used here, but part of template)
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;

// Read input n
void read() {
    cin >> n;
}

// Solve for one test case
void solve() {
    // k = the maximum number of dice whose side-faces-sum (14 each) does not exceed n
    int k = n / 14;
    int rem = n % 14;  // what remains to be covered by top+bottom faces

    // Special handling for k=1: only rem=7 works (single die all faces exposed =21)
    if (k == 1 && n != 21) {
        cout << -1 << "\n";
    }
    // For k>=2, rem must be between 2 and 12 inclusive. Also k=0 is invalid (no dice).
    else if (k == 0 || rem <= 1 || rem >= 13) {
        cout << -1 << "\n";
    }
    else {
        // We can choose top+bottom = rem in [2..12], so solution exists with k dice
        cout << k << "\n";
    }
}

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

    read();
    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.