#include <iostream>
using namespace std;

int main() {
    int n, m, np, mp, frames;
    cout << "Enter the total number of pages in the process: ";
    cin >> n;
    cout << "Enter the total number of pages in the memory: ";
    cin >> m;
    np = n / m;
    if(n % m != 0) np++;
    int process[np][m];
    for(int i = 0; i < np; i++) {
        cout << "Enter the page frames for process " << i << ": ";
        for(int j = 0; j < m; j++) {
            cin >> process[i][j];
        }
    }
    cout << "Enter the total number of page frames in the memory: ";
    cin >> mp;
    frames = mp / m;
    int memory[frames][m];
    for(int i = 0; i < frames; i++) {
        cout << "Enter the page frames for memory frame " << i << ": ";
        for(int j = 0; j < m; j++) {
            cin >> memory[i][j];
        }
    }
    int hit = 0, miss = 0;
    for(int i = 0; i < np; i++) {
        for(int j = 0; j < m; j++) {
            int flag = 0;
            for(int k = 0; k < frames; k++) {
                if(memory[k][j] == process[i][j]) {
                    hit++;
                    flag = 1;
                    break;
                }
            }
            if(flag == 0) {
                miss++;
                for(int k = 0; k < frames; k++) {
                    if(memory[k][j] == -1) {
                        for(int l = 0; l < m; l++) {
                            memory[k][l] = process[i][l];
                        }
                        break;
                    }
                }
            }
        }
    }
    cout << "Number of page hits: " << hit << endl;
    cout << "Number of page faults: " << miss << endl;
    return 0;
}