## 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. 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;
};

struct specialty {
    string name;
    int required;
};

struct faculty {
    string name;
    int k;
    vector<int> subjects;
    vector<tuple<int, int, int>> thresholds;
    vector<specialty> specs;
};

int n, m;
vector<int> scores;
vector<faculty> faculties;

void read() {
    cin >> n >> m;
    scores.assign(m, 0);
    cin >> scores;

    faculties.assign(n, {});
    for(auto& f: faculties) {
        cin >> ws;
        getline(cin, f.name);
        cin >> f.k;
        f.subjects.assign(f.k, 0);
        cin >> f.subjects;
        f.thresholds.assign(f.k, {});
        for(auto& [x, y, z]: f.thresholds) {
            cin >> x >> y >> z;
        }

        int s;
        cin >> s;
        f.specs.assign(s, {});
        for(auto& sp: f.specs) {
            cin >> ws;
            getline(cin, sp.name);
            cin >> sp.required;
        }
    }
}

void solve() {
    // Pure implementation. For each faculty we look up Peter's score on
    // every required subject, convert it to a 2/3/4/5 grade via the
    // X<Y<Z thresholds, sum the grades, and accept every specialty whose
    // required sum is at most that total. The only mildly fiddly part is
    // the parsing, since faculty and specialty names can contain spaces,
    // so we read the input line by line.

    vector<string> accepted;
    for(const auto& f: faculties) {
        int total = 0;
        for(int j = 0; j < f.k; j++) {
            int t = scores[f.subjects[j] - 1];
            auto [x, y, z] = f.thresholds[j];
            int grade = t < x ? 2 : t < y ? 3 : t < z ? 4 : 5;
            total += grade;
        }
        for(const auto& sp: f.specs) {
            if(total >= sp.required) {
                accepted.push_back(f.name + ' ' + sp.name);
            }
        }
    }

    if(accepted.empty()) {
        cout << "Army\n";
    } else {
        for(const auto& line: accepted) {
            cout << line << '\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();
        solve();
    }

    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.
