Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1901

The forests of planet called Binox have several rare species of butterflies. Bino is a butterfly hunter and he wants collect the max of different species of butterflies. The forest of Binox is represented by a square grid of size **N**x**N**. Each cell of the grid can have one butterfly. The image below represents the first example of input. The species collected were: 1, 2, 3, 4 and 8.

Your task is determine the amount of species of butterflies, which Bino is able to collect, and the only information that you have is the map of the forest and all places visited by Bino. For an unknown reason, Bino always searches in the 2***N** positions in the forest.

## Input

The input consists of multiples rows. The first row have an integer **N** (0 < **N** ≤ 200) representing the size of the forest. The following N rows have **N** integers **K _{ij}** (0 <

**K**≤ 1000) each one representing one butterfly specie. The following

_{ij}**N***2 rows, each row have 2 integers, representing the cells visited by Bino.

## Output

Print out one row with an amount of different species which Bino collected.

Input Samples | Output Samples |

3 1 1 2 2 3 4 8 7 1 1 1 1 2 2 1 2 2 2 3 3 1 |
5 |

solution:

<br />#include <bits/stdc++.h> #define D(x) cout << #x " = " << (x) << endl #define endl '\n' using namespace std; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); long long n; while (cin >> n) { set<int> seen; vector<vector<int> > g(n, vector<int>(n)); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> g[i][j]; int x, y; for (int i = 0; i < 2 * n; ++i) { cin >> x >> y; seen.insert(g[x - 1][y - 1]); } cout << seen.size() << endl; } return 0; }