[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
in the function to_num which takes a string s and returns an integer
    if size of s is greater than or equal to 4
        if s.substr(s.size() - 4) = "lios" then return 0
    end of the block
    if size of s >= 5
        if s.substr(s.size() - 5) = "liala" then return 1
    end of the block
    if size of s >= 3
        if s.substr(s.size() - 3) = "etr" then return 2
    end of the block
    if size of s >= 4
        if s.substr(s.size() - 4) = "etra" then return 3
    end of the block
    if size of s >=6
        if s.substr(s.size() - 6) = "initis" then return 4
    end of the block
    if size of s >= 6
        if s.substr(s.size() - 6) = "inites" then return 5
    end of the block
    return -1
end of the block
in the function islegal which takes a integer vector ans and returns a boolean
    if ans[0] % 2 is equal to 0
        for i=1 to size of ans exclusive
            if ans[i] % 2 is not equal to 0 then return false
    else do the following
        for i=1 to size of ans exclusive
            if ans[i] is equal to -1 then return false
            if ans[i] % 2 = 0 then return false
        end of the block
    end of the block
    return true
end of the block
in the function isok which takes an integer vector ans and returns a boolean
    create a boolean f = false
    for i=0 to size of ans exclusive
        if ans[i]/2 is equal to 0 and f is false
            set f to true
            continue
        end of the block
        if f is false
            if ans[i]/2 is not equal to 0 then return false
        else do the following
            if ans[i]/2 is not equal to 2 then return false
        end of the block
    end of the block
    if f is false then return false
    return true
end of the block
define the main function
    c=array of chars of size 100010
    s= string
    res= vector of string
    ans = vector of integer
    create an integer pos=0
    read c
    set s=c
    for i=0 to size of s exclusive
        if s[i] is empty
            add s.substr(pos, i - pos) to the end of res
            set pos to i+1
        end of the block
    add s.substr(pos) to end of res
    for i=0 to size of res exclusive add to_num(res[i] to end of ans
    if size of ans is equal to 1 and asn[0] >=0
        print YES
        return to indicate successful execution
    end of the block
    if islegal(ans) is true
        if isok(ans)is true
            print YES
        else do the following
            print NO
    else do the following
        print NO
    return to indicate successful execution
end of the block

[CODE]:

int to_num(string s) {
    if (s.size() >= 4) {
        if (s.substr(s.size() - 4) == "lios") return 0;
    }
    if (s.size() >= 5) {
        if (s.substr(s.size() - 5) == "liala") return 1;
    }
    if (s.size() >= 3) {
        if (s.substr(s.size() - 3) == "etr") return 2;
    }
    if (s.size() >= 4) {
        if (s.substr(s.size() - 4) == "etra") return 3;
    }
    if (s.size() >= 6) {
        if (s.substr(s.size() - 6) == "initis") return 4;
    }
    if (s.size() >= 6) {
        if (s.substr(s.size() - 6) == "inites") return 5;
    }
    return -1;
}
bool islegal(vector<int> ans) {
    if (ans[0] % 2 == 0) {
        for (int i = 1; i < ans.size(); i++)
            if (ans[i] % 2 != 0) return false;
    } else {
        for (int i = 0; i < ans.size(); i++) {
            if (ans[i] == -1) return false;
            if (ans[i] % 2 == 0) return false;
        }
    }
    return true;
}
bool isok(vector<int> ans) {
    bool f = false;
    for (int i = 0; i < ans.size(); i++) {
        if ((ans[i] / 2) == 1 && !f) {
            f = true;
            continue;
        }
        if (!f) {
            if (ans[i] / 2 != 0) return false;
        } else {
            if (ans[i] / 2 != 2) return false;
        }
    }
    if (!f) { return false; }
    return true;
}
int main() {
    char c[100010];
    string s;
    vector<string> res;
    vector<int> ans;
    int pos = 0;
    gets(c);
    s = c;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == ' ') {
            res.push_back(s.substr(pos, i - pos));
            pos = i + 1;
        }
    res.push_back(s.substr(pos));
    for (int i = 0; i < res.size(); i++) ans.push_back(to_num(res[i]));
    if (ans.size() == 1 && ans[0] >= 0) {
        puts("YES");
        return 0;
    }
    if (islegal(ans)) {
        if (isok(ans))
            puts("YES");
        else
            puts("NO");
    } else
        puts("NO");
    return 0;
}