Check if you can make word2 out of the letters of word1 (Beginner) : The task is to input two words that are made up of uppercase latin letters that are >1 and <250 characters and have the program output whether the second word can be made out of the 1st word's letters.

I've been tackling this exercise all day and when I send it in, I only pass 11/12 tests. After asking 3 people for help and using their codes, I started getting 4/12... that's why I'm here.

My code:

    #include <iostream>
    using namespace std;
    
    int main()
    {
        string word1, word2; // inputted words
        cin >> word1 >> word2;
        if (word2.size() > word1.size())
        {
            return 0;
        }
        for (int i = 0; i < word1.size(); i++) // safe proofing
        {
            if(islower(word1[i]) || islower(word2[i]) || word1.size() < 1 || word1.size() > 250 || word2.size() < 1 || word2.size() > 250)
            {
                return 0;
            }
        }
        int sk1 = 0, sk2 = 0; // times a letter appears in the respective words
        int a = 0; // variable outside of for loop for the end if statement to work
        for(a; a < word2.size(); a++) //checks how many times each letter of the 2nd word appears in both words
        {
            for(int i = 0; i < word1.size(); i++) //checks how many times the letter appears in the 1st word
            {
                if (word2[a] == word1[i])
                    {
                        sk1++; // counts the times it appears
                    }
            }
            for(int i = 0; i < word2.size(); i++)//checks how many times the letter appears in the 2nd word
            {
                if (word2[a] == word2[i])
                    {
                        sk2++; // counts the times it appears
                    }
            }
            if(sk1 < sk2) // if the 1st word has less of the letter than needed, it outputs that you can't make the 2nd word
            {
                cout << "NO";
                break;
            }
            sk1=0;
            sk2=0;
        }
        if (a == word2.size()) //if it goes through all the letters and there are enough of them to make the 2nd word, it says that it can be made.
        {
            cout << "YES";
        }
        }

