import java.util.Arrays;
import java.util.Collection;
class Solution {
public int[] solution(String S, int[] P, int[] Q) {
int len = P.length;
int[] ans = new int[len];
char[] cmap = S.toCharArray();
int[] imap = new int[S.length()];
for(int i=0 ; i<cmap.length ; i++) {
imap[i] = c2i(cmap[i]);
}
for(int i=0 ; i<len ; i++) {
int start = Math.min(P[i],Q[i]);
int end = Math.max(P[i],Q[i]);
ans[i] = partMin(start,end,imap);
}
return ans;
}
private int partMin(int start, int end, int[] imap) {
int min = 9;
int[] part = Arrays.copyOfRange(imap,start,end+1);
Arrays.sort(part);
min = part[0];
return min;
}
public static void main(String[] args) {
tester("CAGCCTA",new int[] {2,5,0}, new int[] {4,5,6}, new int[] {2,4,1});
}
public static void tester(String s, int[] p , int[] q, int[] ans) {
Solution ss = new Solution();
int[] ret = ss.solution(s,p,q);
for(int i=0 ; i<ans.length ; i++) {
if (ret[i] != ans[i]) {
System.out.println("NG");
return;
}
}
System.out.println("OK");
}
private static int c2i(char c) {
char[] TRANS = {'A','C','G','T'};
for(int i=0 ; i< TRANS.length ; i++) {
if(c == TRANS[i]) {
return i+1;
}
}
return -1;
}
}