시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 17 11 6 50.000%

## 문제

Adam just moved into his new apartment and simply placed everything into it at random. This means in particular that he did not put any effort into placing his electronics in a way that each one can have its own electric socket.

Since the cables of his devices have limited reach, not every device can be plugged into every socket without moving it first. As he wants to use as many electronic devices as possible right away without moving stuff around, he now tries to figure out which device to plug into which socket. Luckily the previous owner left behind a plugbar which turns one electric socket into 3.

Can you help Adam figure out how many devices he can power in total?

## 입력

The input consists of:

• one line containing three integers m, n and k, where
• m (1 ≤ m ≤ 1 500) is the number of sockets;
• n (1 ≤ n ≤ 1 500) is the number of electronic devices;
• k (0 ≤ k ≤ 75 000) is the number of possible connections from devices to sockets.
• k lines each containing two integers xi and yi indicating that socket xi can be used to power device yi.

Sockets as well as electronic devices are numbered starting from 1.

The plugbar has no cable, i.e. if it is plugged into a socket it simply triples it.

## 출력

Output one line containing the total number of electrical devices Adam can power.

## 예제 입력 1

3 6 8
1 1
1 2
1 3
2 3
2 4
3 4
3 5
3 6


## 예제 출력 1

5


## 예제 입력 2

4 5 11
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
4 4
4 5


## 예제 출력 2

5


## 예제 입력 3

3 5 7
1 1
1 2
2 2
2 3
2 4
3 4
3 5


## 예제 출력 3

5