#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <cctype>
using namespace std;
bool no_same_substr(const string& str) {
unordered_map<string, int> last_substr_pos; //记录的int是最后一次子串的起始位置
for(int i = 0; i < str.size() - 2; ++i) {
string substr = str.substr(i, 3);
if(last_substr_pos.find(substr) != last_substr_pos.end()) {
if(i > last_substr_pos[substr] + 2) {
return false;
}
} else {
last_substr_pos[substr] = i;
}
}
return true;
}
bool has_at_least_three_type(const string& str) {
int has_digit = 0, has_upper = 0, has_lower = 0, has_special = 0;
for(const char& c: str) {
if(isdigit(c)) has_digit = 1;
else if(isupper(c)) has_upper = 1;
else if(islower(c)) has_lower = 1;
else has_special = 1;
if(has_special + has_digit + has_lower + has_upper >= 3) {
return true;
} //在里面可以提前返回
}
return false;
}
int main() {
string str;
vector<string> ans;
while(cin >> str) {
if(str.size() < 8) {
ans.push_back("NG");
continue;
}
if(!has_at_least_three_type(str)) {
ans.push_back("NG");
continue;
}
if(no_same_substr(str)) {
ans.push_back("OK");
} else ans.push_back("NG");
}
for(const string& s: ans) {
cout << s << endl;
}
return 0;
}