<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

316. Code Tanks
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Hopefully yesterday you participated in the fascinating Code Game Challenge event. And now you have a unique chance to play on the side of the organizers team. You need to solve one of the many challenging tasks organizers have met during the Code Game Challenge preparation process.

The problem is the following. You are given the log of one match with N tanks participating. The log is a sequence of successful bullet shots, i.e. hits. Shots are listed in the log in the order of the corresponding bullet hit the target tank as this happened in the match. You need to calculate the number of hit points and the score of each tank at the end of the match.

Here are the Code Game Challenge rules essential for this problem:

Each tank has 100 hit points and 0 score points at the beginning of the match.

Each shot always reduces the hit points of the target tank by 8, and if the number of hit points of the target before the shot was greater than zero, the shooting tank receives 3 score points.

Only "active" tanks (with a positive number of hit points) can shoot, so you can expect to find only shots fired by the "active" tanks in the log.

At the end of the match each tanks with positive hit points additionally receive the number of score points equal to the half of its hit points.



Input
The first line of the input contains two integer numbers N and M (2 ≤ N ≤ 6; 1 ≤ M ≤ 4000), where N is the number of tanks participating in the match and M is the number of shots fired. The following M lines contain the descriptions of the shots. Each description consists of two different integer numbers from 1 to N. The first one is the number of the tank which fired the shot and the second one is the number of the tank which was hit by the shot.

Output
Write N lines to the output, one line for each tank, in the order of the tank numbers. Write two integer numbers to each line — the number of hit points and the number of score points of the corresponding tank at the end of the match.

Example(s)
sample input
sample output
3 3
2 1
1 2
2 1
84 45
92 52
100 50

<|response|>
1. Abridged Problem Statement  
You have N tanks (numbered 1…N), each starting with 100 hit points (HP) and 0 score. You are given a chronological log of M successful shots, where each entry is a pair (shooter, target). For each shot:  
- If the target’s HP before the shot was > 0, the shooter gains 3 score points.  
- The target loses 8 HP (it may go negative).  

Only tanks with positive HP ever appear as shooters in the log. After processing all shots, every tank with HP> 0 receives a bonus of ⌊HP/2⌋ score points. Output for each tank (1…N) its final HP and final score.

2. Key Observations  
- N is very small (≤ 6) and M is up to 4000, so an O(M) simulation is instantaneous.  
- We only need two arrays of length N: one for HP and one for score.  
- Shots from “dead” tanks never appear, so we don’t need to check shooter status.  
- HP can go below zero and stay there; once HP≤0, that tank is considered “dead.”  
- The only subtlety is to check the target’s HP before subtracting 8, to decide whether to award the 3-point hit bonus.

3. Full Solution Approach  
1. Initialize two arrays of size N:  
   • hp[i] = 100  
   • score[i] = 0  
2. For each logged shot (s, t) in order:  
   a. Convert to zero-based indices: s–1, t–1.  
   b. If hp[t] > 0, add 3 to score[s].  
   c. Subtract 8 from hp[t].  
3. After processing all M shots, loop over i=0…N–1:  
   If hp[i] > 0, add floor(hp[i]/2) to score[i].  
4. Print for each tank i (1…N): hp[i–1] and score[i–1].

Time complexity is O(M+N), memory O(N).

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    // Read number of tanks and number of shots
    cin >> N >> M;

    // Initialize hit points and score arrays
    vector<int> hp(N, 100);     // Each tank starts with 100 HP
    vector<int> score(N, 0);    // Each tank starts with 0 score

    // Process each shot in chronological order
    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;    // 1-based indices
        s--;              // Convert shooter to 0-based
        t--;              // Convert target to 0-based

        // If the target was alive before the shot, award 3 points to shooter
        if (hp[t] > 0) {
            score[s] += 3;
        }
        // Apply damage to the target (can go negative)
        hp[t] -= 8;
    }

    // After all shots, award the surviving tanks their bonus points
    for (int i = 0; i < N; i++) {
        if (hp[i] > 0) {
            // Bonus is floor(hp/2)
            score[i] += hp[i] / 2;
        }
    }

    // Output final HP and score for each tank in order
    for (int i = 0; i < N; i++) {
        cout << hp[i] << " " << score[i] << "\n";
    }

    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
def main():
    import sys
    data = sys.stdin.read().split()
    # First two values: N tanks, M shots
    N, M = map(int, data[:2])
    # Remaining pairs are the shots
    shots = data[2:]

    # Initialize HP and score lists
    hp = [100] * N
    score = [0] * N

    # Process each shot
    idx = 0
    for _ in range(M):
        # Read shooter and target (1-based), convert to 0-based
        s = int(shots[idx]) - 1
        t = int(shots[idx+1]) - 1
        idx += 2

        # If target was alive, shooter gets 3 points
        if hp[t] > 0:
            score[s] += 3

        # Target loses 8 HP
        hp[t] -= 8

    # Award bonus half-HP to surviving tanks
    for i in range(N):
        if hp[i] > 0:
            score[i] += hp[i] // 2

    # Print results
    out = []
    for i in range(N):
        out.append(f"{hp[i]} {score[i]}")
    print("\n".join(out))


if __name__ == "__main__":
    main()
```