**PROBLEM LINK**:

Practice

Contest, div. 1

Contest, div. 2

**Author:** Vivek Chauhan

**Tester:** Ildar Gainullin

**Editorialist:** Oleksandr Kulkov

**DIFFICULTY**:

CAKEWALK

**PREREQUISITES**:

None

**PROBLEM**:

You’re given a sequence A_1, \dots, A_n. Find the number of pairs (i,j) such that A_i + A_j = A_i \cdot A_j.

**QUICK EXPLANATION**:

Keep an eye on twos and zeros.

**EXPLANATION**:

We may rewrite it as A_i=A_j(A_i-1), or A_j = \frac{A_i}{A_i-1}. Since A_j is integer it’s only possible when either A_i=A_j=2 or A_i=A_j=0, so we just have to calculate amount of occurences of 0's and 2's in the sequence.

```
void solve() {
int n;
cin >> n;
map<int, int> cnt;
for(int i = 0; i < n; i++) {
int ai;
cin >> ai;
cnt[ai]++;
}
cout << cnt[0] * (cnt[0] - 1) / 2 + cnt[2] * (cnt[2] - 1) / 2 << endl;
}
```

**AUTHOR’S AND TESTER’S SOLUTIONS**:

Tester’s solution can be found here.

Editorialist’s solution can be found here.