Problem:
Look for the Winner!
The citizens of TKB City are famous for their deep love in elections and vote counting.
Today they hold an election for the next chairperson of the electoral commission.
Now the voting has just been closed and the counting is going to start.
The TKB citizens have strong desire to know the winner as early as possible during vote counting.
The election candidate receiving the most votes shall be the next chairperson.
Suppose for instance that we have three candidates
A
,
B
, and
C
and ten votes.
Suppose also that we have already counted six of the ten votes and the vote counts of
A
,
B
, and
C
are four, one, and one, respectively.
At this moment, every candidate has a chance to receive four more votes and so everyone can still be the winner.
However, if the next vote counted is cast for
A
,
A
is ensured to be the winner since
A
already has five votes and
B
or
C
can have at most four votes at the end.
In this example, therefore, the TKB citizens can know the winner just when the seventh vote is counted.
Your mission is to write a program that receives every vote counted, one by one, identifies the winner, and determines when the winner gets ensured.
Input
The input consists of at most 1500 datasets, each consisting of two lines in the following format.
n
c
1
c
2
…
c
n
n
in the first line represents the number of votes, and is a positive integer no greater than 100.
The second line represents the
n
votes, separated by a space.
Each
c
i
(1 ≤
i
≤
n
) is a single uppercase letter,
i.e.
one of 'A' through 'Z'.
This represents the election candidate for which the
i
-th vote was cast.
Counting shall be done in the given order from
c
1
to
c
n
.
You should assume that at least two stand as candidates even when all the votes are cast for one candidate.
The end of the input is indicated by a line containing a zero.
Output
For each dataset, unless the election ends in a tie, output a single line containing an uppercase letter
c
and an integer
d
separated by a space:
c
should represent the election winner and
d
should represent after counting how many votes the winner is identified.
Otherwise, that is, if the election ends in a tie, output a single line containing `TIE'.
Sample Input
1
A
4
A A B B
5
L M N L N
6
K K K K K K
6
X X X Y Z X
10
A A A B A C A C C B
10
U U U U U V V W W W
0
Output for the Sample Input
A 1
TIE
TIE
K 4
X 5
A 7
U 8

Submitted solutions:

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int N;
char S[100009];

void Testcase() {
    pair<int, char> votes[26], votes2[256];
    for (int i = 0; i < 26; i++) votes[i] = make_pair(0, 'A' + i);

    // Simulation
    for (int i = 0; i < N; i++) {
        votes[S[i] - 'A'].first += 1;

        // Sorting
        for (int j = 0; j < 26; j++) votes2[j] = votes[j];
        sort(votes2, votes2 + 26);
        reverse(votes2, votes2 + 26);

        // Deciding
        if (votes2[0].first > votes2[1].first + (N - i - 1)) {
            cout << votes2[0].second << " " << i + 1 << endl;
            return;
        }
    }

    // If Draw
    cout << "TIE" << endl;
}

int main() {
    while (true) {
        cin >> N; if (N == 0) break;
        for (int i = 0; i < N; i++) cin >> S[i];
        Testcase();
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3380
final_rank: 11

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
... 2nd output should repmax_votesent after counting how many votes the winner is identified ...

*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 100;
static int vect[MAX_N];

const int LETTERS = 26;
static int counts[LETTERS];

//------------------------------------------------------------------------------
void reset()
{
    for (int x=0; x<LETTERS; ++x) counts[x] = 0;
}

int max_vote(int N, int banned)
{
    int res = 0;
    for (int i=0; i<N; ++i)
        for (int x=0; x<LETTERS; ++x)
            if (x != banned && counts[x] > res)
                res = counts[x];
    return res;
}
void query(int N)
{
    int num = 0;
    int y1 = -1;
    int max_votes = 0;
    for (int x=0; x<LETTERS; ++x)
    {
        if (counts[x] > max_votes) { y1 = x; max_votes = counts[x]; num = 1; }
        else if (counts[x] == max_votes) num++;
    }
    if (num > 1) { printf("TIE\n"); return; }

    reset();
    for (int i=0; i<N; ++i)
    {
        counts[vect[i]]++;
        if (counts[y1] > max_vote(N,y1) + N-i-1) { printf("%c %d\n", y1+'A', i+1); return; }
    }
}


//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, num;
    char c;
    while (true)
    {
        num = scanf("%d ", &N); if (N == 0) break;
        reset();
        for (int i=0; i<N; ++i)
        {
            num = scanf("%c ", &c);
            vect[i] = c-'A';
            counts[c-'A']++;
        }
        if (DEBUG)
        {
            for (int x=0; x<LETTERS; ++x)
                if (counts[x])
                    printf("%c => %d\n", x+'A', counts[x]);
        }
        query(N);
    }
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 20
memory_kb: 3568
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
while(1) {
    int N;
    cin >> N;
    if (N == 0) return 0;
    int NOW[26] = {};
    vector<int> V(N);
    rep(i,0,N) {
        char C;
        cin >> C;
        V[i] = C - 'A';
    }
    bool check = false;
    rep(i,0,N) {
        NOW[V[i]]++;
        vector<pair<int,int>> X(26);
        rep(j,0,26) X[j] = {NOW[j],j};
        sort(ALL(X));
        reverse(ALL(X));
        if (X[0].first > X[1].first + N - i - 1) {
            cout << (char)(X[0].second + 'A') << ' ' << i + 1 << endl;
            check = true;
            break;
        }
    }
    if (!check) {
        cout << "TIE" << endl;
    }
}
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 14

code_snippet: #include <bits/stdc++.h>
//using
using intl = long long;
using ll = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e18;
const intl MOD = 1e9+7; //1e9より大きい最小の素数, 1e9より小さい最大の素数は998244353
const ld EPS = 1.0e-14;
const ld PI = acos(-1);

//テンプレート関数
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl modpow(intl a, intl n, intl mod) {intl res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
intl modpow(intl a, intl n) {intl res = 1; while (n > 0) {if (n & 1) res = res * a % MOD;a = a * a % MOD;n >>= 1;}return res;}
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)
intl mceil(intl a, intl b){ return (a + b - 1) / b; }//aをbで割って切り上げる関数,O(1)


//--------------入力受け取る場所----------------------------------------------------
intl n;
vector<char> c;


void input_var(){
    cin >> n;
    if (n == 0) exit(0);
    c.resize(n);
    rep(i, n) cin >> c[i];
}
//-------------------------------------------------------------------------------

void solve(){
    map<char, intl> m;
    for (char i = 'A'; i <= 'Z'; i++) {
        m[i] = 0;
    }
    rep(i, n) {
        m[c[i]]++;
        intl num1 = 0;
        char ch1 = '0';
        intl num2 = 0;
        char ch2 = '0';
        for (char i = 'A'; i <= 'Z'; i++) {
            if (m[i] > num1) {
                num2 = num1;
                ch2 = ch1;
                num1 = m[i];
                ch1 = i;
            }
            else if (m[i] > num2) {
                num2 = m[i];
                ch2 = i;
            }
        }
        if (num1 - num2 > n - i - 1) {
            cout << ch1 << " " << i + 1 << endl;
            return;
        }
    }
    cout << "TIE" << endl;
}

signed main(){
    cout << fixed << setprecision(10);

    while (true) {
        input_var();
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
bool solve()
{
    int N;
    cin>>N;
    if(N==0)return 0;
    vector<char>C(N);
    for(int i=0;i<N;i++)cin>>C[i];
    int rem=N;
    vector<int>cnt(26,0);
    for(int i=0;i<N;i++)
    {
        rem--;
        cnt[C[i]-'A']++;
        for(int c=0;c<26;c++)
        {
            int MAX=0;
            for(int d=0;d<26;d++)if(c!=d)MAX=max(MAX,cnt[d]);
            if(cnt[c]>MAX+rem)
            {
                cout<<char('A'+c)<<' '<<i+1<<'\n';
                return 1;
            }
        }
    }
    cout<<"TIE"<<'\n';
    return 1;
}
int main(){while(solve()){}}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
using vvl = vector<vector<long long>>; using vs = vector<string>;
using pl = pair<long long, long long>;
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
template <typename T> T gcd(T a, T b) {if (b == 0)return a; else return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b) {return a /gcd(a, b)*b;}
const ll INF = 1LL << 60;
const ld PI = acos(-1);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec);
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr);
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const pair<T, U> &pa);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa);
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp);
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp);
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl);
 
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
template <class... T> std::istream &operator>>(std::istream &is, std::tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa) { return os << '(' << pa.first << ',' << pa.second << ')'; }
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl
#define dbgif(cond, x) ((cond) ? std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl : std::cerr)
#else
#define dbg(x) ((void)0)
#define dbgif(cond, x) ((void)0)
#endif
void solve();
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}
//見切り発車で実装しては行けない．頭の中でコードが完全に出来上がるまで書き始めるな．
void solve(){
  while(true){
    ll N;cin>>N;
    if(N==0)return;
    vector<ll> cnt(26),res(26);
    vector<char> A(N);
    rep(i,N){
      cin>>A[i];
      res[A[i]-'A']++;
    }
    ll ans = -1;
    char who = 'A';
    rep(i,N){
      char a = A[i];
      cnt[a-'A']++;
      //本当に勝ったか?
      //自分以外の人が残りを全て得ても超えられない
      rep(k,26){
        bool ok = true;
        rep(j,26){
          if(j==k)continue;
          ok&=cnt[k]>cnt[j]+N-i-1;
        }
        if(ok){
          who = 'A'+k;
          ans = i+1;
          break;
        }
      }
      if(ans!=-1)break;
    }
    if(ans==-1)cout<<"TIE"<<endl;
    else cout<<who<<" "<<ans<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        vector<pair<int, int>> cnt(26);
        rep(i, 0, 26) cnt[i].second = i;
        char ans = 'a';
        int d = 1e9;
        rep(i, 0, n) {
            char c;
            cin >> c;
            cnt[c - 'A'].first++;
            vector<pair<int, int>> tmp = cnt;
            sort(tmp.rbegin(), tmp.rend());
            int ma1 = tmp[0].first, ma2 = tmp[1].first;
            if(ma2 + (n - 1 - i) < ma1) {
                ans = 'A' + tmp[0].second;
                d = min(d, (int)i + 1);
            }
        }
        if(d == 1e9) {
            cout << "TIE" << '\n';
        } else {
            cout << ans << ' ' << d << '\n';
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3356
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) v.begin(),v.end()

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n==0) return 0;
        vector<int> c(n);
        for (int i = 0; i < n; ++i) {
            char x;
            cin >> x;
            c[i] = x - 'A';
        }

        int K = 26;
        vector<int> cnt(K);
        bool fin = false;
        for (int i = 0; i < n && !fin; ++i) {
            cnt[c[i]]++;

            for (int j = 0; j < K && !fin; ++j) {
                int mx = 0;
                for (int k = 0; k < K; ++k) {
                    if (j==k) continue;
                    mx = max(mx,cnt[k]);
                }

                if (cnt[j] > mx+n-i-1) {
                    cout << (char)('A'+j) << ' ' << i+1 << endl;
                    fin = true;
                }
            }
        }

        if (!fin) cout << "TIE" << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3320
final_rank: 4

code_snippet: #include <bits/stdc++.h>

int solve() {
    std::array<int, 256> ans;
    ans.fill(0);

    int n;
    std::cin >> n;
    if (n == 0) return 1;
    std::vector<char> cs(n);
    for (int i = 0; i < n; i++) std::cin >> cs[i];

    auto check = [&](int rem) -> int {
        int top_i = std::max_element(ans.begin(), ans.end()) - ans.begin();
        int top_v = ans[top_i];
        ans[top_i] = 0;
        int second_i = std::max_element(ans.begin(), ans.end()) - ans.begin();
        int second_v = ans[second_i];

        if (top_v > second_v + rem) return top_i;
        ans[top_i] = top_v;
        return -1;
    };

    for (int i = 0; i < n; i++) {
        int rem = n - i - 1;
        ans[cs[i]]++;
        auto res = check(rem);
        if (res != -1) {
            std::cout << (char)res << ' ' << i + 1 << std::endl;
            return 0;
        }
    }
    std::cout << "TIE" << std::endl;
    return 0;
}

int main() {
    while (!solve());
}
accuracy: 1
time_ms: 20
memory_kb: 3356
final_rank: 10

code_snippet: #include<bits/stdc++.h>

using namespace std;

string func(int n){
	map<string,int> m;
	string res = "TIE";
	for(int i=0;i<n;++i){
		string p;
		cin >> p;
		++m[p];
		int r = n - i - 1;
		vector<pair<int,string>> line;
		line.emplace_back(0,"A");
		for(auto i:m)line.emplace_back(i.second,i.first);
		sort(line.begin(),line.end());
		if(line[line.size()-2].first + r < line[line.size()-1].first){
			if(res == "TIE")res = line.back().second + " " + to_string(i+1);
		}
	}
	return res;
}

int main(){
	int n;
	while(cin >> n && n){
		cout << func(n) << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3552
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int cnt[128] = {};
    auto f = [&](int k) -> int {
      auto p = max_element(begin(cnt), end(cnt));
      for (auto q = cnt; q < end(cnt); q++) {
        if (q != p) {
          if (*p <= *q + k) {
            return -1;
          }
        }
      }
      return p - cnt;
    };
    bool flag = false;
    for (auto i = 0; i != n; ++i) {
      char c;
      cin >> c;
      cnt[c]++;
      auto r = f(n - 1 - i);
      if (~r && !flag) {
        cout << char(r) << " " << i + 1 << "\n";
        flag = 1;
      }
    }
    if (!flag) cout << "TIE\n";
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
using namespace atcoder;
#endif
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
#define rep(i, n) for(ll i = 0; i < n; i++)

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    while(true){
        int n; cin >> n;
        if(n == 0)break;
        vector<char> c(n);
        rep(i,n)cin >> c[i];
        map<char,int> num;
        int m1 = 0,m2 = 0,i1 = -1;
        bool flag = false;
        rep(i,n){
            num[c[i]]++;
            m1 = 0,m2 = 0,i1 = -1;
            rep(j,26){
                if(num['A'+j] > m1 && i1 != j){
                    m2 = m1;
                    m1 = num['A'+j];
                    i1 = j;
                }
                else if(num['A'+j] > m2){
                    m2 = num['A'+j];
                }
            }
            // cout << m1 << " " << m2 << endl;
            if(m1 - m2 > n-i-1){
                cout << (char)('A'+i1) << " " << i+1 << endl;
                flag = true;
                break;
            }
        }
        if(!flag) cout << "TIE" << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3444
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
    while(true){
        bool go_nxt = false;
        int64_t N; cin >> N;
        if(N == 0){
            return 0;
        }
        vector<int64_t> vote(27);
        for(int64_t i = 0; i < N; i++){
            char c; cin >> c;
            if(go_nxt) continue;
            vote[c - 'A']++;
            for(int64_t k = 0; k < 26; k++){
                bool flag = true;
                for(int64_t j = 0; j < 26; j++){
                    if(k == j) continue;
                    if(vote[k] <= vote[j] + N - i - 1) flag = false;
                }
                if(flag){
                    cout << char('A' + k) << " " << i+1 << '\n';
                    go_nxt = true;
                }
            }
        }
        if(not go_nxt) cout << "TIE" << '\n';
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3196
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = (int)m; i < (int)n; i++)

#define ALL(x) x.begin(),x.end()

#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define keta(x) cout << std::fixed << std::setprecision(15) << (double)x << endl;

void solve(int n){
    vector<char> c(n);
    rep(i, n) cin >> c[i];
    int max_num = 0; //票数の最大値
    int next_max_num = 0;

    map<char, int> cnt;
    for(char s = 'A'; s <= 'Z'; s++){
        cnt[s] = 0;
    }

    rep(i, n){
        cnt[c[i]]++;
        //最大値の番号と数を求める
        char maxID; int maxNum = 0;
        //最大値の次の数
        int nextNum = 0;

        for(char s = 'A'; s <= 'Z'; s++){
            if(maxNum <= cnt[s]){
                maxNum = cnt[s];
                maxID = s;
            }
        }

        //次の票
        for(char s = 'A'; s <= 'Z'; s++){
            if(maxID == s) continue;
            if(nextNum <= cnt[s]){
                nextNum = cnt[s];
            }
        }

        if(maxNum - nextNum > n-i-1){
            cout << maxID << " " << i+1 << endl;
            return;
        }
    }
    cout << "TIE" << endl;
    
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        solve(n);
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3340
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long;

int n;
vector<char> vc;

void solve(){
	vector<int> cnt(26);
	for(int i = 0;i<n;i++){
		cnt[vc[i]-'A']++;
		int amari = n-i-1;
		for(int j = 0;j<26;j++){
			bool is_c = true;
			for(int k = 0;k<26;k++){
				if(k==j)continue;
				if(cnt[j]<=cnt[k]+amari)is_c = false;
			}
			if(is_c){
				cout<<(char)(j+'A')<<' '<<i+1<<endl;
				return;
			}
		}
	}
	cout<<"TIE"<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		cin >> n;
		if(n==0)break;
		vc = vector<char>(n);
		for(auto &i:vc)cin >> i;
		solve();
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3452
final_rank: 17

code_snippet: #line 2 "library/KowerKoint/base.hpp"

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef ONLINE_JUDGE
template<typename... Args>
void dbg(const Args &... args) {}
#else
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#endif

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template<typename T>
vector<vector<T>> split(typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T val) {
    vector<vector<T>> res;
    vector<T> cur;
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

vector<string> split(typename string::const_iterator begin, typename string::const_iterator end, char val) {
    vector<string> res;
    string cur = "";
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 3 "library/KowerKoint/internal_operator.hpp"

namespace internal_operator {
    template <typename T>
    T default_add(T a, T b) { return a + b; }
    template <typename T>
    T default_sub(T a, T b) { return a - b; }
    template <typename T>
    T zero() { return T(0); }
    template <typename T>
    T default_div(T a, T b) { return a / b; }
    template <typename T>
    T default_mult(T a, T b) { return a * b; }
    template <typename T>
    T one() { return T(1); }
    template <typename T>
    T default_xor(T a, T b) { return a ^ b; }
    template <typename T>
    T default_and(T a, T b) { return a & b; }
    template <typename T>
    T default_or(T a, T b) { return a | b; }
    ll mod3() { return 998244353LL; }
    ll mod7() { return 1000000007LL; }
    ll mod9() { return 1000000009LL; }
}

#line 3 "library/KowerKoint/integer.hpp"

VL divisor(ll n) {
    assert(n > 0);
    VL fow, bck;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            fow.push_back(i);
            if(i * i != n) bck.push_back(n / i);
        }
    }
    reverse(ALL(bck));
    fow.insert(fow.end(), ALL(bck));
    return fow;
}

bool is_prime(ll n) {
    assert(n > 0);
    for(ll d = 2; d*d <= n; d++) {
        if(n % d == 0) return false;
    }
    return true;
}

VL least_prime_factors(ll n) {
    assert(n > 0);
    VL lpfs(n+1, -1), primes;
    FOR(d, 2, n+1) {
        if(lpfs[d] == -1) {
            lpfs[d] = d;
            primes.push_back(d);
        }
        for(ll p : primes) {
            if(p * d > n || p > lpfs[d]) break;
            lpfs[p*d] = p;
        }
    }
    return lpfs;
}

VL prime_list(ll n) {
    assert(n > 0);
    VL primes;
    vector<bool> sieved(n+1);
    FOR(d, 2, n+1) {
        if(!sieved[d]) {
            primes.push_back(d);
            for(ll i = d*d; i <= n; i += d) sieved[i] = 1;
        }
    }
    return primes;
}

map<ll, int> prime_factor(ll n) {
    assert(n > 0);
    map<ll, int> factor;
    for(ll d = 2; d*d <= n; d++) {
        while(n%d == 0) {
            n /= d;
            factor[d]++;
        }
    }
    if(n > 1) factor[n]++;
    return factor;
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1, y = 0;
    ll nx = 0, ny = 1;
    while(b) {
        ll q = a / b;
        tie(a, b) = LP(b, a % b);
        tie(x, nx) = LP(nx, x - nx*q);
        tie(y, ny) = LP(ny, y - ny*q);
    }
    return a;
}

ll inv_mod(ll n, ll m) {
    ll x, y;
    assert(extgcd(n, m, x, y) == 1);
    x %= m;
    if(x < 0) x += m;
    return x;
}

ll pow_mod(ll a, ll n, ll m) {
    if(n == 0) return 1LL;
    if(n < 0) return inv_mod(pow_mod(a, -n, m), m);
    ll res = 1;
    while(n) {
        if(n & 1) {
            res *= a;
            res %= m;
        }
        n >>= 1;
        a *= a;
        a %= m;
    }
    return res;
}

#line 5 "library/KowerKoint/modint.hpp"

template <ll (*mod)()>
struct Modint {
    ll val;
    
    Modint(): val(0) {}

    Modint(ll x): val(x) {
        val %= mod();
        if(val < 0) val += mod();
    }

    Modint& operator+=(const Modint& r) {
        val += r.val;
        if(val >= mod()) val -= mod();
        return *this;
    }
    friend Modint operator+(const Modint& l, const Modint& r) {
        return Modint(l) += r;
    }

    Modint& operator-=(const Modint& r) {
        val -= r.val;
        if(val < mod()) val += mod();
        return *this;
    }
    friend Modint operator-(const Modint& l, const Modint& r) {
        return Modint(l) -= r;
    }

    Modint& operator*=(const Modint& r) {
        val *= r.val;
        val %= mod();
        return *this;
    }
    Modint operator*(const Modint& r) {
        return (Modint(*this) *= r);
    }
    friend Modint operator*(const Modint& l, const Modint& r) {
        return Modint(l) *= r;
    }

    Modint pow(ll n) const {
        return Modint(pow_mod(val, n, mod()));
    }

    Modint inv() const {
        return Modint(inv_mod(val, mod()));
    }

    Modint& operator/=(const Modint& r) {
        return (*this *= r.inv());
    }
    friend Modint operator/(const Modint& l, const Modint& r) {
        return Modint(l) /= r;
    }

    Modint& operator^=(const ll n) {
        val = pow_mod(val, n, mod());
        return *this;
    }
    Modint operator^(const ll n) {
        return this->pow(n);
    }

    Modint operator+() const { return *this; }
    Modint operator-() const { return Modint() - *this; }

    Modint& operator++() {
        val++;
        if(val == mod()) val = 0LL;
        return *this;
    }
    Modint& operator++(int) {
        Modint res(*this);
        ++*this;
        return res;
    }

    Modint& operator--() {
        if(val == 0LL) val = mod();
        val--;
        return *this;
    }
    Modint& operator--(int) {
        Modint res(*this);
        --*this;
        return res;
    }

    friend bool operator==(const Modint& l, const Modint& r) {
        return l.val == r.val;
    }
    friend bool operator!=(const Modint& l, const Modint& r) {
        return l.val != r.val;
    }

    static pair<vector<Modint>, vector<Modint>> factorial(int n) {
        vector<Modint> fact(n+1), rfact(n+1);
        fact[0] = 1;
        REP(i, n) fact[i+1] = fact[i] * (i+1);
        rfact[n] = 1 / fact[n];
        for(int i = n-1; i >= 0; i--) rfact[i] = rfact[i+1] * (i+1);
        return {fact, rfact};
    }

    friend istream& operator>>(istream& is, Modint& mi) {
        is >> mi.val;
        return is;
    }

    friend ostream& operator<<(ostream& os, const Modint& mi) {
        os << mi.val;
        return os;
    }
};

using MI3 = Modint<internal_operator::mod3>;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;
using MI7 = Modint<internal_operator::mod7>;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI9 = Modint<internal_operator::mod9>;
using V9 = vector<MI9>;
using VV9 = vector<V9>;
using VVV9 = vector<VV9>;
#line 3 "library/KowerKoint/counting.hpp"

template <typename T>
struct Counting {
    vector<T> fact, ifact;

    Counting() {}
    Counting(ll n) {
        expand(n);
    }

    void expand(ll n) {
        ll sz = (ll)fact.size();
        if(sz > n) return;
        fact.resize(n+1);
        ifact.resize(n+1);
        fact[0] = 1;
        FOR(i, max(1LL, sz), n+1) fact[i] = fact[i-1] * i;
        ifact[n] = 1 / fact[n];
        for(ll i = n-1; i >= sz; i--) ifact[i] = ifact[i+1] * (i+1);
    }

    T permutation(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[n-r];
    }

    T combination(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[r] * ifact[n-r];
    }

    T stirling(ll n, ll k) {
        assert(n >= k);
        assert(k >= 0);
        if(n == 0) return 1;
        T res = 0;
        int sign = k%2? -1 : 1;
        expand(k);
        REP(i, k+1) {
            res += sign * ifact[i] * ifact[k-i] * T(i).pow(n);
            sign *= -1;
        }
        return res;
    }

    vector<vector<T>> stirling_table(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        vector<vector<T>> res(n+1, vector<T>(k+1));
        res[0][0] = 1;
        FOR(i, 1, n+1) FOR(j, 1, k+1) {
            res[i][j] = res[i-1][j-1] + j * res[i-1][j];
        }
        return res;
    }

    T bell(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        expand(k);
        vector<T> tmp(k+1);
        int sign = 1;
        tmp[0] = 1;
        FOR(i, 1, k+1) {
            sign *= -1;
            tmp[i] = tmp[i-1] + sign * ifact[i];
        }
        T res = 0;
        REP(i, k+1) {
            res += T(i).pow(n) * ifact[i] * tmp[k-i];
        }
        return res;
    }

    vector<vector<T>> partition_table(ll n) {
        assert(n >= 0);
        vector<vector<T>> res(n+1, vector<T>(n+1));
        REP(i, n+1) res[0][i] = 1;
        FOR(i, 1, n+1) FOR(j, 1, n+1) {
            res[i][j] = res[i][j-1] + (i<j? 0 : res[i-j][j]);
        }
        return res;
    }
};
#line 2 "Contests/Dummy/main.cpp"

/* #include "atcoder/all" */
/* using namespace atcoder; */
/* #include "KowerKoint/expansion/ac-library/all.hpp" */

void solve(){
    while(1) {
        int n; cin >> n;
        if(!n) break;
        VC v(n); cin >> v;
        VP cnt(26);
        REP(i, 26) cnt[i].second = i;
        bool tie = true;
        REP(i, n) {
            cnt[v[i]-'A'].first++;
            VP cnt_s = cnt;
            sort(ALL(cnt_s));
            if(cnt_s[25].first > cnt_s[24].first+(n-i-1)) {
                tie = false;
                print((char)('A' + cnt_s[25].second), i+1);
                break;
            }
        }
        if(tie) print("TIE");
    }
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 3452
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define all(a)  (a).begin(),(a).end()
#define rall(a)  (a).rbegin(),(a).rend()
typedef long long ll;
typedef pair<ll,ll> pl;

int main() {
    while(true) {
        int n;
        cin >> n;
        if(n==0) break;
        vector<char> c(n);
        map<char,int> mp;
        bool flag=false;
        rep(i,n) {
            cin >> c[i];
            mp[c[i]]++;
            if(!flag) {
                vector<pair<int,char>> vec;
                for(auto u:mp) vec.push_back({u.second,u.first});
                sort(rall(vec));
                if((int)vec.size()==1) {
                    if(vec[0].first>n/2) {
                        cout << vec[0].second << " " << i+1 << endl;
                        flag=true;
                    }
                } else {
                    if(vec[0].first-vec[1].first>n-i-1) {
                        cout << vec[0].second << " " << i+1 << endl;
                        flag=true;
                    }
                }
            } 
        }
        if(!flag) cout << "TIE" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3300
final_rank: 3

code_snippet: #include <iostream>
#include <queue>
using namespace std;

const int MAX_N = 100;
const int MAX_CANDIDATE = 26;

int Diff( int *count )
{
    priority_queue<int> pq;
    for ( int i = 0; i < MAX_CANDIDATE; i++ )
    {
        pq.push( count[i] );
    }
    int first = pq.top(); pq.pop();
    int second = pq.top(); pq.pop();
    
    return first - second;
}

char Max( int *count )
{
    int max_count = 0;
    int index = 0;
    for ( int i = 0; i < MAX_CANDIDATE; i++ )
    {
        if ( count[i] > max_count )
        {
            max_count = count[i];
            index = i;
        }
    }
    
    return (char)index + 'A';
}

int main()
{
    int n;
    char c[MAX_N];
    
    while ( 1 )
    {
        cin >> n;
        if ( !n ) break;
        
        for ( int i = 0; i < n; i++ )
        {
            cin >> c[i];
        }
        
        int count[MAX_CANDIDATE] = { 0 };
        int i;
        for ( i = 0; i < n; i++ )
        {
            count[c[i] - 'A']++;
            int diff = Diff( count );
            
            if ( n - i - 1 < diff )
            {
                cout << Max( count ) << ' ' << i + 1 << endl;
                break;
            }
        }
        if ( i >= n ) cout << "TIE" << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3048
final_rank: 1

code_snippet: #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lscan(x) scanf("%I64d", &x)
#define lprint(x) printf("%I64d", x)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define REP(i, l, r) for (ll i = l; i < (r); i++)
#define REP2(i, l, r) for (ll i = (ll)r - 1; i >= (l); i--)
#define siz(x) (ll) x.size()
template <class T>
using rque = priority_queue<T, vector<T>, greater<T>>;

template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
bool chmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}

__int128_t gcd(__int128_t a, __int128_t b) {
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    __int128_t cnt = a % b;
    while (cnt != 0) {
        a = b;
        b = cnt;
        cnt = a % b;
    }
    return b;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

struct UnionFind {
    vector<ll> data;
    int num;

    UnionFind(int sz) {
        data.assign(sz, -1);
        num = sz;
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        num--;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    ll size(int k) {
        return (-data[find(k)]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {
    }

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {
    }

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const {
        return ModInt(-x);
    }

    ModInt operator+(const ModInt &p) const {
        return ModInt(*this) += p;
    }

    ModInt operator-(const ModInt &p) const {
        return ModInt(*this) -= p;
    }

    ModInt &operator++() {
        return *this += ModInt(1);
    }

    ModInt operator++(int) {
        ModInt tmp = *this;
        ++*this;
        return tmp;
    }

    ModInt &operator--() {
        return *this -= ModInt(1);
    }

    ModInt operator--(int) {
        ModInt tmp = *this;
        --*this;
        return tmp;
    }

    ModInt operator*(const ModInt &p) const {
        return ModInt(*this) *= p;
    }

    ModInt operator/(const ModInt &p) const {
        return ModInt(*this) /= p;
    }

    bool operator==(const ModInt &p) const {
        return x == p.x;
    }

    bool operator!=(const ModInt &p) const {
        return x != p.x;
    }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {
        return mod;
    }
};

ll mpow2(ll x, ll n, ll mod) {
    ll ans = 1;
    while (n != 0) {
        if (n & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ans;
}
ll modinv2(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= mod;
    if (u < 0)
        u += mod;
    return u;
}

// constexpr int mod = 1000000007;
constexpr int mod = 998244353;
// constexpr int mod = 31607;
using mint = ModInt<mod>;

mint mpow(mint x, ll n) {
    mint ans = 1;
    while (n != 0) {
        if (n & 1)
            ans *= x;
        x *= x;
        n = n >> 1;
    }
    return ans;
}

// ----- library -------
// ----- library -------

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(15);

    while (1) {
        int n;
        cin >> n;
        if (n == 0)
            break;
        char c;
        int ans = -1;
        char ansc;
        vector<int> cnt(26, 0);
        rep(i, n) {
            cin >> c;
            cnt[c - 'A']++;
            if (ans == -1) {
                vector<pair<int, int>> v;
                rep(i, 26) v.pb(cnt[i], i);
                sort(rall(v));
                if (v[0].first > v[1].first + n - 1 - i) {
                    ans = i + 1;
                    ansc = (char)('A' + v[0].second);
                }
            }
        }
        if (ans == -1)
            cout << "TIE\n";
        else
            cout << ansc << ' ' << ans << '\n';
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3416
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const ll INF = 1 << 30;

int main() {
    int m;

    while (1) {
        cin >> m;
        if (m == 0) break;
        map<char, int> v;
        vector<char> vv(m);
        for (int i = 0; i < m; i++) {
            cin >> vv[i];
            // v[vv[i]] = 0;
        }
        bool flag = true;
        for (int i = 1; i <= m; i++) {
            char c;
            c = vv[i - 1];
            v[c]++;
            for (auto e : v) {
                bool flag2 = true;
                for (auto ee : v) {
                    if (e != ee) {
                        if (flag && flag2 && e.sc <= ee.sc + (m - i)) {
                            flag2 = false;
                        }
                    }
                }
                if (v.size() != 1 && flag2 && flag) {
                    cout << e.fs << " " << i << endl;
                    flag = false;
                } else if (v.size() == 1 && flag2 && flag) {
                    if (e.sc * 2 > m) {
                        cout << e.fs << " " << i << endl;
                        flag = false;
                    }
                }
            }
        }
        if (flag) {
            cout << "TIE" << endl;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3380
final_rank: 11