class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param students int整型vector
     * @param sandwiches int整型vector
     * @return int整型
     */
    int countStudents(vector<int>& students, vector<int>& sandwiches) {
        queue<int> studentQueue;
        for (int student : students) {
            studentQueue.push(student);
        }

        int sandwichIndex = 0;
        int n = sandwiches.size();
        int unmatchedCount = 0;

        while (!studentQueue.empty() && unmatchedCount < students.size()) {
            if (studentQueue.front() == sandwiches[sandwichIndex]) {
                studentQueue.pop();
                sandwichIndex++;
                unmatchedCount = 0;
            } else {
                studentQueue.push(studentQueue.front());
                studentQueue.pop();
                unmatchedCount++;
            }
        }

        return studentQueue.size();
    }
};