#include using namespace std; int main() { int n, m, k; cin >> n >> m >> k; vector a(n); unordered_map cnt; for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; } int x = a[--k]; // if there is only 1 memory slot having the value of x, then we don't have to do anything if (cnt[x] == 1) { cout << 0 << '\n'; return 0; } vector> operations(m); for (int i = 0; i < m; i++) { cin >> operations[i].first >> operations[i].second; } unordered_map mp; vector values; for (const auto& [k, v] : cnt) { values.push_back(k); mp[k] = int(values.size()); } auto evaluate = [&](int u, char op, int v) -> long long { if (op == '+') { return u + v; } if (op == '-') { return u - v; } if (op == '*') { return u * 1ll * v; } return u / v; }; vector>> graph(values.size() + 1); for (const auto& elem : values) { assert(mp.find(elem) != mp.end()); for (int i = 0; i < int(operations.size()); i++) { auto nxt_value = evaluate(elem, operations[i].first, operations[i].second); if (nxt_value < 0) { continue; } if (mp.find(nxt_value) != mp.end()) { graph[mp[elem]].emplace_back(mp[nxt_value], i); } else { graph[mp[elem]].emplace_back(0, i); } } } vector dist(values.size() + 1, 1e9 + 10); vector> parent(values.size() + 1); dist[mp[x]] = 0; queue q; q.push(mp[x]); parent[mp[x]] = make_pair(-1, -1); while (!q.empty()) { auto curr = q.front(); q.pop(); for (auto [neighbor, op_index] : graph[curr]) { if (dist[neighbor] > dist[curr] + 1) { dist[neighbor] = dist[curr] + 1; parent[neighbor] = make_pair(curr, op_index); q.push(neighbor); } } } if (dist[0] >= 1e9 + 10) { cout << -1 << '\n'; } else { cout << dist[0] << '\n'; vector path; int curr = 0; while (curr != mp[x]) { path.push_back(parent[curr].second); curr = parent[curr].first; } reverse(path.begin(), path.end()); for (auto elem : path) { cout << elem + 1 << '\n'; } } }