#include "digitsTree.hpp"


int main() {
    string digit_str;
    getline(cin, digit_str);
    int d = stoi(digit_str);

    string format;
    getline(cin, format);
    BinaryTree<int> t;
    t.setInputOutputFormat(format=="INLINEFORMAT"?BinaryTree<int>::INLINEFORMAT:BinaryTree<int>::VISUALFORMAT);
    while (cin >> t and not t.isEmpty()) {
    	cout << (treeContainsDigit(t, d)?"SI":"NO") << endl;
  	}
}
