longlong ans, a[2 * N]; int n, len, s, t; char str[N];
intmain(){ while (~ scanf("%d", &n)) { scanf("%s", str); len = strlen(str);
memset(a, 0, sizeof(a)); for (int i = 0; i < len; i++) a[i + N + 1] = str[i] - 28;
for (int i = N - 1; i; i--) a[i] = a[2 * i] * a[2 * i + 1] % MOD;
while (n--) { scanf("%d%d", &s, &t); if (s > len || t > len) { printf("%I64d\n", ans); continue ; //deal with wrong data } if (s > t) swap(s, t); s += N - 1; t += N + 1; for (ans = 1; s ^ t ^ 1; s >>= 1, t >>= 1) { if (~ s & 1) ans *= a[s ^ 1]; ans %= MOD; if (t & 1) ans *= a[t ^ 1]; ans %= MOD; } printf("%I64d\n", ans); } } return0; }
boolno_child(){ for (int i = 0; i < 26; i++) if (children[i]) returnfalse; returntrue; }
voidinsert(constchar *s){ TrieNode *p = this; int len = strlen(s); for (int i = 0; i < len; i++) { if (!p->children[s[i] - 'a']) p->children[s[i] - 'a'] = newTrieNode(); p = p->children[s[i] - 'a']; } p->isLeaf = true; }
boolfind(constchar *s){ TrieNode *p = this; int len = strlen(s); for (int i = 0; i < len; i++) if (!p->children[s[i] - 'a']) returnfalse; else p = p->children[s[i] - 'a']; returntrue; }
voiddel_pre(constchar *s); } root, *link[40];
voidTrieNode::del_pre(constchar *s){ TrieNode *p = this; int len = strlen(s); for (int i = 0; i < len; i++) { link[i] = p; if (!p->children[s[i] - 'a']) return ; else p = p->children[s[i] - 'a']; } link[len - 1]->children[s[len - 1] - 'a'] = 0; for (int i = len - 1; i; i--) if (link[i]->no_child()) link[i - 1]->children[s[i - 1] - 'a'] = 0; elsebreak ; }
inlinebooldigital(char x){ return ('0' <= x && x <= '9') || x == '-'; }
inline string getvar(){ string res = ""; char t = getchar(); while (t < 'a' || t > 'z') t = getchar(); do { res += t; t = getchar(); } while ('a' <= t && t <= 'z'); ungetc(t, stdin); return res; }
inlineintgetopt(){ char t = getchar(); while (t != '=' && t != '<' && t != '>') t = getchar(); char x = getchar(); if (t == '=') return0; if (x != '=') { ungetc(x, stdin); return t == '>' ? 1 : -1; } return t == '>' ? 2 : -2; }
inlineintgetint(){ int res = 0, mul = 1; char t = getchar(); while (!digital(t)) t = getchar(); if (t == '-') { mul = -1; t = getchar(); } do { res *= 10; res += t - '0'; t = getchar(); } while (digital(t)); ungetc(t, stdin); return mul * res; }
inlineboolgetdot(){ char t = getchar(); while (t != ',' && t != '\r' && t != '\n' && t != EOF) t = getchar(); return t == ','; }
intmain(){ int n = getint(), opt, val; string var; char tmp[10]; int L, R; for (int i = 1; i <= n; i++) { ans[i] = ""; do { var = getvar(); opt = getopt(); val = getint(); if (ans[i] == "no") continue ; it = m[i].find(var); if (opt == 0) L = R = val; if (opt == 1) L = val + 1, R = MAX; if (opt == 2) L = val, R = MAX; if (opt == -1) R = val - 1, L = MIN; if (opt == -2) R = val, L = MIN; if (it != m[i].end()) { if ( R < it->second.first || L > it->second.second ) ans[i] = "no"; else { it->second.second = min(R, it->second.second); it->second.first = max(L, it->second.first); // cout << "Update pair " << var << " " << it->second.first << " " << it->second.second << endl; } } else { m[i][var] = make_pair(L, R); // cout << "Insert pair " << var << " " << L << " " << R << endl; } } while (getdot());
if (ans[i] == "no") continue ;
for (int j = 1; j < i; j++) { if (ans[j] == "no") continue ; bool uni = false; for (it = m[i].begin(); it != m[i].end(); it++) { io = m[j].find(it->first); if (io != m[j].end()) if ( it->second.first > io->second.second || it->second.second < io->second.first ) { uni = true; break ; } } if (!uni) { sprintf(tmp, "%d", j); ans[i] += tmp; ans[i] += " "; } } }
ios::sync_with_stdio(0); for (int i = 1; i <= n; i++) if (ans[i] == "" || ans[i] == "no") cout << "unique" << endl; else { ans[i].erase(ans[i].length() - 1); cout << ans[i] << endl; }