## 1. Abridged problem statement

Peter has test scores for `M` subjects. There are `N` university faculties. Each faculty requires `K` subjects and gives conversion rules from test score to exam grade `2`, `3`, `4`, or `5` using three thresholds `X < Y < Z`.

For each specialty of a faculty, a minimum required sum of grades is given. Peter applied to every specialty. For every accepted application, output:

```text
FacultyName SpecialtyName
```

If none are accepted, output:

```text
Army
```

Faculty and specialty names may contain spaces, so they must be read as full lines.

---

## 2. Detailed editorial

For every faculty, we need to calculate Peter's total exam grade sum according to that faculty's rules.

Peter has scores:

```text
B[1], B[2], ..., B[M]
```

Each faculty specifies:

- `K` required subjects,
- the subject indices,
- for each required subject, thresholds `X, Y, Z`.

For a subject with Peter's score `T`:

- if `T < X`, grade is `2`;
- else if `T < Y`, grade is `3`;
- else if `T < Z`, grade is `4`;
- otherwise, grade is `5`.

After computing the sum of grades for the faculty, compare it with every specialty's required sum. If Peter's sum is at least the required sum, the application is accepted.

The only tricky part is input parsing:

- Faculty names and specialty names can contain spaces.
- Therefore, they must be read using `getline` in C++ or `input()` in Python.
- Before reading a full line after reading integers, we must consume leftover whitespace/newlines.

The constraints are small:

```text
N <= 100
M <= 100
S <= 100
```

So a direct simulation is easily fast enough.

Time complexity:

```text
O(total number of required subjects + total number of specialties)
```

In the worst case this is around:

```text
O(N * (M + S))
```

which is very small.

Memory complexity:

```text
O(N + M + total specialties)
```

although we can also process faculties one by one without storing all of them.

---

## 3. Provided C++ solution with detailed comments

```cpp
// Include all standard C++ library headers.
#include <bits/stdc++.h>

// Use the standard namespace to avoid writing std:: everywhere.
using namespace std;

// Overload output operator for pairs.
// This helper is not essential for this problem, but is part of the template.
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    // Print the first and second elements of the pair separated by a space.
    return out << x.first << ' ' << x.second;
}

// Overload input operator for pairs.
// This helper is also part of the general template.
template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    // Read the first and second elements of the pair.
    return in >> x.first >> x.second;
}

// Overload input operator for vectors.
// Allows reading all elements of a vector using cin >> vector.
template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    // Iterate over all elements of the vector by reference.
    for(auto& x: a) {
        // Read one element.
        in >> x;
    }

    // Return the input stream.
    return in;
};

// Overload output operator for vectors.
// This helper is not essential for the solution.
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    // Print every element followed by a space.
    for(auto x: a) {
        out << x << ' ';
    }

    // Return the output stream.
    return out;
};

// Structure describing one specialty.
struct specialty {
    // Name of the specialty.
    string name;

    // Required total grade sum for admission.
    int required;
};

// Structure describing one faculty.
struct faculty {
    // Name of the faculty.
    string name;

    // Number of required exams/subjects for this faculty.
    int k;

    // Indices of required subjects.
    vector<int> subjects;

    // Thresholds for each required subject.
    // Each tuple stores X, Y, Z.
    vector<tuple<int, int, int>> thresholds;

    // List of specialties on this faculty.
    vector<specialty> specs;
};

// Number of faculties and number of subjects.
int n, m;

// Peter's test scores for all subjects.
vector<int> scores;

// All faculty descriptions.
vector<faculty> faculties;

// Reads all input data.
void read() {
    // Read number of faculties and subjects.
    cin >> n >> m;

    // Prepare vector of Peter's scores.
    scores.assign(m, 0);

    // Read all M scores using the overloaded vector input operator.
    cin >> scores;

    // Prepare vector for N faculties.
    faculties.assign(n, {});

    // Read every faculty.
    for(auto& f: faculties) {
        // Consume leading whitespace/newline before reading a full-line name.
        cin >> ws;

        // Read the faculty name, which may contain spaces.
        getline(cin, f.name);

        // Read K, the number of exams required by this faculty.
        cin >> f.k;

        // Prepare vector for K subject indices.
        f.subjects.assign(f.k, 0);

        // Read the subject indices.
        cin >> f.subjects;

        // Prepare vector for K threshold triples.
        f.thresholds.assign(f.k, {});

        // Read all threshold triples.
        for(auto& [x, y, z]: f.thresholds) {
            // Read X, Y, Z for this subject.
            cin >> x >> y >> z;
        }

        // Number of specialties on this faculty.
        int s;

        // Read number of specialties.
        cin >> s;

        // Prepare vector of specialties.
        f.specs.assign(s, {});

        // Read each specialty.
        for(auto& sp: f.specs) {
            // Consume newline/whitespace before reading a full-line name.
            cin >> ws;

            // Read specialty name, which may contain spaces.
            getline(cin, sp.name);

            // Read required total grade sum.
            cin >> sp.required;
        }
    }
}

// Solves the problem after input has been read.
void solve() {
    // Stores all accepted application output lines.
    vector<string> accepted;

    // Process every faculty.
    for(const auto& f: faculties) {
        // Total grade sum for this faculty.
        int total = 0;

        // Process every required subject of this faculty.
        for(int j = 0; j < f.k; j++) {
            // Get Peter's score for the required subject.
            // Subject numbers in input are 1-based, so subtract 1.
            int t = scores[f.subjects[j] - 1];

            // Get threshold triple X, Y, Z for this exam.
            auto [x, y, z] = f.thresholds[j];

            // Convert score t into grade according to thresholds.
            int grade = t < x ? 2 : t < y ? 3 : t < z ? 4 : 5;

            // Add the grade to the faculty total.
            total += grade;
        }

        // Check every specialty of this faculty.
        for(const auto& sp: f.specs) {
            // Application is accepted if total grade sum is large enough.
            if(total >= sp.required) {
                // Output format: faculty name, space, specialty name.
                accepted.push_back(f.name + ' ' + sp.name);
            }
        }
    }

    // If no applications were accepted, Peter goes to the army.
    if(accepted.empty()) {
        cout << "Army\n";
    } else {
        // Otherwise, print all accepted applications.
        for(const auto& line: accepted) {
            cout << line << '\n';
        }
    }
}

// Program entry point.
int main() {
    // Speed up C++ input/output.
    ios_base::sync_with_stdio(false);

    // Untie cin from cout for faster input.
    cin.tie(nullptr);

    // Number of test cases.
    // The problem has only one test case.
    int T = 1;

    // This line is commented out because input does not contain T.
    // cin >> T;

    // Run reading and solving for each test case.
    for(int test = 1; test <= T; test++) {
        // Read input.
        read();

        // Solve and print answer.
        solve();
    }

    // Return successful exit code.
    return 0;
}
```

---

## 4. Python solution with detailed comments

```python
import sys


def main():
    # Read all lines from standard input.
    lines = sys.stdin.read().splitlines()

    # Pointer to the current line.
    idx = 0

    # First line contains N and M.
    n, m = map(int, lines[idx].split())
    idx += 1

    # Second line contains Peter's scores for M subjects.
    scores = list(map(int, lines[idx].split()))
    idx += 1

    # This list will store final accepted output lines.
    accepted = []

    # Process each faculty block.
    for _ in range(n):
        # Faculty name may contain spaces, so read the entire line.
        faculty_name = lines[idx]
        idx += 1

        # Next line contains K followed by K subject indices.
        data = list(map(int, lines[idx].split()))
        idx += 1

        # First number is K.
        k = data[0]

        # Remaining K numbers are subject indices.
        subjects = data[1:]

        # Next line contains 3*K integers: X, Y, Z for each required subject.
        threshold_values = list(map(int, lines[idx].split()))
        idx += 1

        # Convert the flat list into triples.
        thresholds = []
        for i in range(k):
            x = threshold_values[3 * i]
            y = threshold_values[3 * i + 1]
            z = threshold_values[3 * i + 2]
            thresholds.append((x, y, z))

        # Compute Peter's total grade for this faculty.
        total = 0

        # For every required subject, convert the test score to a grade.
        for i in range(k):
            # Subject indices in input are 1-based.
            subject_index = subjects[i] - 1

            # Peter's test score for this subject.
            t = scores[subject_index]

            # Thresholds for this subject.
            x, y, z = thresholds[i]

            # Convert score to grade.
            if t < x:
                grade = 2
            elif t < y:
                grade = 3
            elif t < z:
                grade = 4
            else:
                grade = 5

            # Add this grade to the total.
            total += grade

        # Next line contains number of specialties.
        s = int(lines[idx])
        idx += 1

        # Process all specialties.
        for _ in range(s):
            # Specialty name may contain spaces.
            specialty_name = lines[idx]
            idx += 1

            # Required total grade sum.
            required = int(lines[idx])
            idx += 1

            # If Peter's total is enough, the application is accepted.
            if total >= required:
                accepted.append(f"{faculty_name} {specialty_name}")

    # If there are accepted applications, print them.
    if accepted:
        print("\n".join(accepted))
    else:
        # Otherwise print Army.
        print("Army")


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

---

## 5. Compressed editorial

Read Peter's scores. For each faculty, read its name, required subject indices, and threshold triples. For every required subject, take Peter's score and convert it to a grade:

```text
T < X      -> 2
X <= T < Y -> 3
Y <= T < Z -> 4
Z <= T     -> 5
```

Sum these grades for the faculty. Then check every specialty of that faculty: if the sum is at least the specialty's required value, output `FacultyName SpecialtyName`.

If nothing is accepted, output `Army`.

The main implementation detail is reading faculty and specialty names as whole lines because they may contain spaces.