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

Solution (Python):



while True:
	n = int(input())
	if n == 0: break
	c = list(input().split())
	c = [ord(i)-ord('A') for i in c]
	f = [0]*26
	max1 = max2 = 0
	x1 = x2 = -1
	k, i = n, 0;
	while i < n:
		x = c[i]
		i, k = i+1, k-1
		f[x] += 1;
		if f[x] > max1:
			if x1 < 0 or x == x1: max1 = f[x]; x1 = x
			else: max2 = max1; x2 = x1; max1 = f[x]; x1 = x
		elif f[x] > max2: max2 = f[x]; x2 = x
		if max2+k < max1: break
	if max1 == max2: print("TIE")
	else: print(chr(x1+ord('A')), i)

Solution (Python):



A = ord('A')
while True:
	n = int(input())
	if n == 0: break
	c = list(input().split())
	c = [ord(i)-A for i in c]
	f = [0]*26
	max1 = max2 = 0
	x1 = x2 = -1
	k, i = n, 0;
	while i < n:
		x = c[i]
		i, k = i+1, k-1
		f[x] += 1;
		if f[x] > max1:
			if x1 < 0 or x == x1: max1 = f[x]; x1 = x
			else: max2 = max1; x2 = x1; max1 = f[x]; x1 = x
		elif f[x] > max2: max2 = f[x]; x2 = x
		if max2+k < max1: break
	if max1 == max2: print("TIE")
	else: print(chr(x1+A), i)

Solution (Python):
while True:
  n = int(input())
  if n == 0:break
  base = ord("A")
  vote = [0] * 26
  clst = list(input().split())
  for i, v in enumerate(clst, start=1):
    vote[ord(v) - base] += 1
    first, second = 0, 0
    for v in vote:
      if v > first:
        first, second = v ,first
      elif v > second:
        second = v
    if first - second > n - i:
      print(chr(vote.index(first) + base), i)
      break
  else:
    print("TIE")

Solution (Python):
ans_list = []
import copy
while True:
    n = int(input())
    if n == 0:
        break
    c = list(input().split())
    cnt_abc = [0 for i in range(26)]
    key = 1
    for I in range(len(c)):
        i = c[I]
        cnt_abc[ord(i) - ord("A")] += 1
        this_cnt = copy.copy(cnt_abc)
        this_cnt.sort()
        
        if this_cnt[-1] > this_cnt[-2] + (n - I - 1):

            for j in range(len(cnt_abc)):
                if cnt_abc[j] == max(cnt_abc):
                    ans_list.append([chr(j + ord("A")), I + 1])
                    break
            key = 0
            break
    if key:
        ans_list.append("TIE")

for i in ans_list:
    if i == "TIE":
        print(i)
    else:
        print(i[0], i[1])

Solution (Python):
while 1:
    n = input()
    if n==0:
        break
    dic = {}
    for i, c in enumerate(raw_input().split()):
        dic[c] = dic.get(c, 0) + 1
        if dic[c] > n/2:
            print c, i+1
            break
        if len(dic) > 2:
            keys = sorted(dic, key=lambda x: dic[x])
            b, a = keys[-2:]
            if dic[a] > dic[b] + (n-1-i):
                print a, i+1
                break
    else:
        print "TIE"

Solution (Python):
from collections import Counter
while True:
    N = int(input())
    if not N:
        break
    C = input().split()
    for i in range(N):
        cnt = Counter(C[:i+1]).most_common()
        if (len(cnt) == 1 and cnt[0][1] * 2 > N) or (len(cnt) > 1 and cnt[0][1] > cnt[1][1] + N - i - 1):
            print(cnt[0][0], i + 1)
            break
    else:
        print("TIE")

Solution (Python):
from collections import Counter
while True:
    N = int(input())
    if not N:
        break
    C = input().split()
    for i in range(N):
        cnt = Counter(C[:i+1]).most_common() + [('', 0)]
        if cnt[0][1] > cnt[1][1] + N - i - 1:
            print(cnt[0][0], i + 1)
            break
    else:
        print("TIE")

Solution (Python):
from collections import Counter
while 1:
 N=int(input())
 if N==0:break
 C=raw_input().split()
 for i in range(N):
  c=Counter(C[:i+1]).most_common()+[('',0)]
  if c[0][1]>c[1][1]+N-i-1:
   print c[0][0],i+1
   break
 else:print("TIE")

Solution (Python):
import collections as c
while 1:
 N=int(input())
 if N==0:break
 C=raw_input().split()
 for i in range(1,N+1):
  l=c.Counter(C[:i]).most_common()+[('',0)]
  if l[0][1]>l[1][1]+N-i:print l[0][0],i;break
 else:print("TIE")

Solution (Python):
def ri(): return int(input())
cand = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split()

n = ri()
while(n!=0):
    vote = input().split()
    sm = [0 for i in range(26)]
    flag = False
    for i in range(n):
        for j in range(26):
            if(vote[i] == cand[j]):
                sm[j] += 1
                break
        no1_sm = 0
        no2_sm = 0
        no1_idx = 0
        no2_idx = 0
        for j in range(26):
            if(sm[j] > no1_sm):
                no2_sm = no1_sm
                no2_idx = no1_idx
                no1_sm = sm[j]
                no1_idx = j
            elif(sm[j] > no2_sm):
                no2_sm = sm[j]
                no2_idx = j
        if((i+1) > n//2 and no1_sm > no2_sm+(n-1-i)):
            print(cand[no1_idx], i+1)
            flag = True
            break
        if(flag): break
    if(not flag):
        print("TIE")
    n = ri()

Solution (Python):
from collections import Counter
while True:
    N = int(input())
    if N == 0: break
    src = input().split()
    ctr = Counter()
    for i in range(N):
        ctr.update(src[i])
        if len(ctr) == 1:
            if list(ctr.values())[0] > N//2:
                print('{0} {1}'.format(list(ctr.keys())[0], i+1))
                break
        else:
            rem = N-1-i
            li = sorted(ctr.items(), key=lambda x:x[1], reverse=True)[:2]
            if li[0][1] > li[1][1] + rem:
                print('{0} {1}'.format(li[0][0], i+1))
                break
    else:
        print('TIE')

Solution (Python):
from collections import Counter
while True:
    n = int(input())
    if n == 0:
        quit()
    elif n == 1:
         print(input(), 1)
    else:
        c = list(input().split())
        h = [0 for i in range(26)]
        flag = 0
        for i in range(n):
            h[ord(c[i])-65] += 1
            if sorted(h)[-1] - sorted(h)[-2] >= (n-i):
                print(chr(h.index(max(h))+65), i+1)
                flag = 1
                break
        if flag == 0:
            print('TIE')

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break

    vote = list(map(str, input().split()))
    res = [0 for i in range(26)]

    for i, per in enumerate(vote):
        res[ord(per) - ord("A")] += 1
        sres = sorted(res, reverse = True)
        if sres[0] - sres[1] > n - i - 1:
            win = chr(res.index(sres[0]) + ord("A"))
            print(win, i + 1)
            break

        if i == n - 1:
            print("TIE")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = LS()
        r = 'TIE'
        d = collections.defaultdict(int)
        for i in range(n):
            d[a[i]] += 1
            s = sorted(list(d.items()) + [('-', 0)], key=lambda x: [-x[1]])
            if s[0][1] - s[1][1] > n - i - 1:
                r = '{} {}'.format(s[0][0], i+1)
                break

        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
def secMax(a):
    mx = 0
    smx = 0
    for i in range(0,len(a)):
        if a[i] > mx:
            smx = mx
            mx = a[i]
        elif a[i] > smx:
            smx = a[i]
    else:
        return smx

while True:
    n = int(input())
    if n == 0:
        break
    c = list(map(str,input().split()))
    
    alph = ["A","B","C","D","E","F","G","H",
            "I","J","K","L","M","N","O","P","Q",
            "R","S","T","U","V","W","X","Y","Z"]
    abcCount = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    for i in range(0, n):
        for j in range(0, 26):
            if c[i] == alph[j]:
                abcCount[j] = abcCount[j] + 1
                break
        
        if max(abcCount) > n-1-i+secMax(abcCount):
            print(alph[abcCount.index(max(abcCount))], sum(abcCount))
            break
    else:
        print("TIE")

Solution (Python):
import sys
sys.setrecursionlimit(10**6)


def main():
	n = int(input())
	if n == 0:
		return
	c = [ord(i)-65 for i in input().split(" ")]
	getnum = [0 for i in range(30)]
	mnum = 29
	snum = 29
	flg = True
	for i in range(n):
		getnum[c[i]] += 1
		if getnum[c[i]] >= getnum[mnum] and mnum != c[i]:
			snum = mnum
			mnum = c[i]
		elif getnum[c[i]] >= getnum[snum] and snum != c[i] and mnum != c[i]:
			snum = c[i]
		if getnum[mnum] > getnum[snum] + (n-1) - i:
			print(chr(mnum+65),i+1)
			flg = False
			break
	if flg:
		print("TIE")
	main()
	return

main()

Solution (Python):
while 1:
    n=int(input())
    if not n:break
    l=input().split()
    d={}
    f=False
    for (cnt,i) in enumerate(l):
        if i in d:
            d[i]+=1
        else:
            d[i]=1
        pl=n-cnt-1
        dd=sorted(d.items(),key=lambda x:x[1])
        if len(dd)>1:
            if dd[-1][1]>dd[-2][1]+pl:
                print(dd[-1][0],cnt+1)
                f=True
                break
        else:
            if float(dd[0][1])/n>0.5:
                print(dd[0][0],cnt+1)
                f=True
                break

    if not f:
        print("TIE")

Solution (Python):
def solve():
  n = int(input())
  if n == 0:
    exit()
  C = [c for c in input().split()]

  V = [0] * 26

  for i, c in enumerate(C, 1):
    V[ord(c) - ord('A')] += 1
    maxi = 0
    ma1 = 0
    ma2 = 0
    for j, v in enumerate(V):
      if v > ma1:
        ma1, ma2 = v, ma1
        maxi = j
      elif v > ma2:
        ma2 = v

    if ma1 - ma2 > n - i:
      print(chr(ord('A') + maxi), i)
      return

  print('TIE')

while True:
  solve()

Solution (Python):
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range(26):
    alphabet[i] = alphabet[i].upper()

def ctoi(c):
    res = 0
    for x in alphabet:
        if x == c:
            return res
        res += 1
    return res

while True:
    n = int(input())
    if n == 0:
        break
    
    c = list(input().split())

    maxi = [n for _ in range(26)]
    cnt = [0 for _ in range(26)]

    for j in range(n):
        x = c[j]
        idx = ctoi(x)

        for i in range(26):
            if i == idx:
                cnt[i] += 1
            else:
                maxi[i] -= 1
        
        shouri = False        
        for alpha in alphabet:
            idx = ctoi(alpha)
            mx = -1
            for i in range(26):
                if i != idx:
                    mx = max(mx, maxi[i])
            
            if cnt[idx] > mx:
                print(alpha, j + 1)
                shouri = True
                break
        
        if shouri:
            break
    else:
        print('TIE')

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

while True:
  n = int(input())
  if n==0:break
  A = input().split()
  data = [0]*26
  M = 0
  for i,ai in enumerate(A):
    index = ord(ai)-ord("A")
    data[index] += 1
    if M < data[index]:
      M = data[index]
      MD= index
    data[MD] = 0
    M2 = max(data);data[MD] = M
    if M2 + n - (i+1) < M:
      print(chr(MD+ord("A")),i+1)
      break
  else:
    print("TIE")

Solution (Python):
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


SIZE = 26

table = [None]*SIZE


while True:
    N = int(input())
    if N == 0:
        break

    for i in range(SIZE):
        table[i] = 0

    input_str = list(map(str,input().split()))

    who = None
    ans = N+1
    rest = N

    maximum = 0
    maximum_index = 0
    maximum_count = N

    for i in range(1,(N+1)):
        rest -= 1
        loc = ord(input_str[i-1])-ord('A')
        table[loc] += 1

        if table[loc] > maximum: 
            maximum = table[loc]
            maximum_count = 1
            maximum_index = loc
        elif table[loc] == maximum: 
            maximum_count += 1

        if maximum_count > 1:
            continue

        
        FLG = True
        for k in range(len(table)):
            if k == maximum_index:
                continue
            if table[k]+rest >= table[maximum_index]:
                FLG = False
                break

        if FLG == True:
            who = maximum_index
            ans = i
            break

    if ans == N+1:
        print("TIE")
    else:
        print("%s %d"%(chr(who+ord('A')),ans))

Solution (Python):
while 1:
    n = int(input())
    if n == 0: break
    s = input().split(' ')
    d = {}
    flag = 0
    for i in range(n):
        if s[i] in d:
            d[s[i]] += 1
        else:
            d[s[i]] = 1
        vote = sorted(d.values(), reverse=True)
        if len(vote) == 1:
            if n//2 < i+1:
                print(max(d.items(), key = lambda x:x[1])[0] + ' ' + str(i+1))
                flag = 1
                break
        elif vote[0] - vote[1] > n-i-1:
            print(max(d.items(), key = lambda x:x[1])[0] + ' ' + str(i+1))
            flag = 1
            break
    if flag == 0: print('TIE')

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    C = input().split()
    D = {}
    for x in [chr(i) for i in range(65, 65+26)]:
        D[x] = 0 
    for i in range(n):
        D[C[i]] += 1
        E = sorted(D.items(), key=lambda x: x[1], reverse=True)
        if E[0][1] > E[1][1] + n - i - 1:
            print(E[0][0], i + 1)
            break
    if E[0][1] == E[1][1]:
        print("TIE")

Solution (Python):
while(True):
	N = int(input())
	if N ==0 :break
	V = input().split()
	vote = {}
	top = 0
	second = 0
	for i in range(N):
		if V[i] in vote:
			vote[V[i]] += 1
			if top < vote[V[i]]:
				top = vote[V[i]]
			elif second < vote[V[i]]:
				second = vote[V[i]]
		else:
			vote[V[i]] = 1
			if top < vote[V[i]]:
				top = vote[V[i]]
			elif second < vote[V[i]]:
				second = vote[V[i]]
		ans = i+1
		if (N-1-i) < top-second: break
	if top == second:
		print("TIE")
	else:
		print("{} {}".format(max(vote, key=vote.get), ans))

Solution (Python):
while True:
  n = int(input())
  if n == 0:
    break
  c = list(input().split())
  count = [0 for i in range(26)]
  alphab = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
  for i in range(n):
    if c[i] == "A":
      count[0] += 1
    elif c[i] == "B":
      count[1] += 1
    elif c[i] == "C":
      count[2] += 1
    elif c[i] == "D":
      count[3] += 1
    elif c[i] == "E":
      count[4] += 1
    elif c[i] == "F":
      count[5] += 1
    elif c[i] == "G":
      count[6] += 1
    elif c[i] == "H":
      count[7] += 1
    elif c[i] == "I":
      count[8] += 1
    elif c[i] == "J":
      count[9] += 1
    elif c[i] == "K":
      count[10] += 1
    elif c[i] == "L":
      count[11] += 1
    elif c[i] == "M":
      count[12] += 1
    elif c[i] == "N":
      count[13] += 1
    elif c[i] == "O":
      count[14] += 1
    elif c[i] == "P":
      count[15] += 1
    elif c[i] == "Q":
      count[16] += 1
    elif c[i] == "R":
      count[17] += 1
    elif c[i] == "S":
      count[18] += 1
    elif c[i] == "T":
      count[19] += 1
    elif c[i] == "U":
      count[20] += 1
    elif c[i] == "V":
      count[21] += 1
    elif c[i] == "W":
      count[22] += 1
    elif c[i] == "X":
      count[23] += 1
    elif c[i] == "Y":
      count[24] += 1
    elif c[i] == "Z":
      count[25] += 1
    
    count_sorted = sorted(count)
    if count_sorted[-1]-count_sorted[-2] > n-1-i:
      a = i+1
      break
  count_sorted = sorted(count)
  if count_sorted[-1] == count_sorted[-2]:
    print("TIE")
  else:
    for i in range(len(count)):
      if count_sorted[-1] == count[i]:
        print(alphab[i]+ " " + str(a))

Solution (Python):
while True:
  n = int(input())
  if n == 0:
    break
  else:
    votes = [0] * 26
    for i, v in enumerate(map(lambda x:ord(x)-65, input().split())):
      votes[v] += 1
      l = sorted(votes, reverse=True)
      if l[0] > l[1] + (n - i - 1):
        print(chr(votes.index(l[0])+65) + ' ' + str(i + 1))
        break
    else:
      print('TIE')

Solution (Python):



from collections import Counter

def Look_for_the_Winner(n,lst):
    dic=Counter()
    loop_count=0
    flg=0
    for i in lst:
        n-=1
        loop_count+=1
        
        dic[i]+=1
        if len(dic)==1:
            if dic.most_common()[0][1]>n:
                print(dic.most_common()[0][0]+" "+str(loop_count))
                flg=1
                break
        else:
            if dic.most_common()[0][1]>dic.most_common()[1][1]+n:
                print(dic.most_common()[0][0]+" "+str(loop_count))
                flg=1
                break
    if flg==0 :        
        print("TIE")

while True:
    n=int(input())
    if n==0:
        break
    c=list(map(str,input().split()))
    Look_for_the_Winner(n,c)

Solution (Python):
printedlater = []
while True:
    n = int(input())
    if (n == 0): 
        break
    c = [x for x in input().split()]
    voteNum = {}
    for cand in list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
        voteNum[cand] = 0
    while True:
        if (len(c) == 0):
            voteMax = max(voteNum.values())
            winners = [x for x in voteNum.keys() if voteNum[x] == voteMax]
            if (len(winners) == 1):
                printedlater.append(winners[0] + " " + str(n))
            else:
                printedlater.append("TIE")
            break
        voteNum[c.pop(0)] += 1
        vote2ndMax, voteMax = sorted(voteNum.values())[-2:]
        if voteMax - vote2ndMax > len(c):
            printedlater.append([x for x in voteNum.keys() if voteNum[x] == voteMax][0] + " " + str(n - len(c)))
            break
for line in printedlater:
    print(line)

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    c = list(input().split())
    hyou = [0] * 26
    isTie = True
    for i in range(0,n):
        hyou[ord(c[i]) - ord('A')] += 1
        ma1,ma2 = 0,0
        mai1,mai2 = 0,0
        for j in range(0,26):
            if ma2 < hyou[j]:
                ma2 = hyou[j]
                mai2 = j
            if ma1 < ma2:
                ma1,ma2 = ma2,ma1
                mai1,mai2 = mai2,mai1
        if ma2 + n - i - 1 < ma1:
            isTie = False
            print(chr(mai1 + ord('A')),i + 1)
            break
    if isTie:
        print("TIE")

Solution (Python):
while True:
        n = int(input())
        if n == 0:
            break
        a = input().split()
        candidate = [["A",0],["B",0],["C",0],["D",0],["E",0],["F",0],["G",0],["H",0],["I",0],["J",0],["K",0],["L",0],["M",0],["N",0],["O",0],["P",0],["Q",0],["R",0],["S",0],["T",0],["U",0],["V",0],["W",0],["X",0],["Y",0],["Z",0]]
        for i in range(n):
            for c in candidate:
                if a[i] == c[0]:
                    c[1] += 1
                    break
            candidate.sort(key = lambda x:x[1],reverse =True)
            if candidate[0][1] > candidate[1][1] + n-(i+1):
                print(candidate[0][0],i+1)
                break
        else:
            print('TIE')

Solution (Python):
import collections
while True:
    c = int(input())
    if c == 0:
        break
    n = list(map(str, input().split()))
    count = collections.Counter(n)
    rank = count.most_common()
    canditate1 = rank[0][0]
    vote1 = rank[0][1]
    if len(count) == 1:
        answer = int(c / 2) + 1
        print(canditate1, answer)
    elif vote1 == rank[1][1]:
        print("TIE")
    else:
        number = 0
        answer = 0
        while True:
            if len(collections.Counter(n[0:answer]).most_common()) < 2:
                if number > c / 2:
                    break
            else:
                if number > c - answer + collections.Counter(n[0:answer]).most_common()[1][1]:
                    break
            answer += 1
            if n[answer - 1] == canditate1:
                number += 1
        print(canditate1, int(answer))

Solution (Python):
from collections import defaultdict

while True:
    n = int(input())
    if n == 0:
        break
    
    c = input().split()
    d = defaultdict(int)
    d["hoge"] = 0
    flag = False
    for i in range(n):
        d[c[i]] += 1
        ranking = sorted(d.items(), key=lambda x: x[1], reverse=True)
        if ranking[0][1] > ranking[1][1] + (n - 1 - i):
            print(ranking[0][0] + " " + str(i + 1))
            flag = True
            break
    if not flag:
        print("TIE")

Solution (Python):
from collections import Counter
while 334:
    N=int(input())
    if N==0:break
    Hyoes = input().split()
    C=dict([])
    for t in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        C[t]=0
    curtop=["A",0]
    for hyo,c in enumerate(Hyoes,1):
        C[c] += 1
        if C[c]>curtop[1]:
            curtop=[c,C[c]]
        D=sorted(C.values(),reverse=True)
        if D[0]>D[1]+N-hyo:
            print(curtop[0],hyo)
            break
        if hyo==N:
            print("TIE")

Solution (Python):
import sys
from collections import Counter, defaultdict
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

ans = []
while 1:
	n = INT()
	if n == 0:
		break
	c = input().split()

	cnt = Counter(c)
	tmp = cnt.most_common()
	if len(tmp) == 1:
		ans.append("{} {}".format(tmp[0][0], n//2+1))
	elif tmp[0][1] == tmp[1][1]:  
		ans.append("TIE")
	else:  
		count = defaultdict(int)
		count["hoge"] += 1
		for i in range(n):
			count[c[i]] += 1
			max_ = max(count.values())
			if max_ > n//2:  
				ans.append("{} {}".format(tmp[0][0], i+1))
				break
			for j in count:  
				
				if j != tmp[0][0] and count[j] + (n-i-1) >= max_:
					break
			else:  
				ans.append("{} {}".format(tmp[0][0], i+1))
				break
			
for x in ans:
	print(x)

Solution (Python):
from copy import copy
alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while True:
    n = int(input())
    if n == 0:
        break
    c = list(input().split())
    
    N = n
    V = [0 for i in range(26)]
    ans = 0
    for d in range(n):
        V[alp.find(c[d])] += 1
        N-=1
        T = copy(V)
        T.sort(reverse=True)
        if T[0]>T[1]+N:
            ans = d+1
            break
    if ans==0:
        print("TIE")
    else:
        print(alp[V.index(max(V))],ans)

Solution (Python):
"当選者を探せ！"

while True:
    flag = True
    n = int(input())
    if n == 0:
        break
    C = list(map(str, input().split()))
    if n == 1:
        print(C[0], 1)
        flag = False

    if flag:
        candidates = {}

        for i, c in enumerate(C, start=1):
            if c in candidates:
                candidates[c] += 1
            else:
                candidates[c] = 1
            
            candidates_list = sorted(candidates.items(), key=lambda x: x[1], reverse=True)
            
            if len(candidates) > 1:
                if candidates_list[0][1] > (candidates_list[1][1]+n-i):
                    print(candidates_list[0][0], i)
                    flag = False
                    break
            if len(candidates) == 1 and candidates_list[0][1] >= (n//2+1):
                print(candidates_list[0][0], n//2+1)
                flag = False
                break

            candidates = dict(candidates_list)

        if flag:
            candidates_list = sorted(candidates.items(), key=lambda x: x[1], reverse=True)
            if len(candidates_list) != 1:
                if candidates_list[0][1] > candidates_list[1][1]:
                    print(print(candidates_list[0][0], candidates_list[0][1]))
                    flag = False
            elif len(candidates_list) == 1:
                print(candidates_list[0][0], n//2+1)
                flag = False
            if flag:
                print('TIE')

Solution (Python):
from collections import defaultdict
def main(n):
    S = list(input().split())
    d = defaultdict(int)
    d[0] = 0
    for num,s in enumerate(S):
        d[s] += 1
        di = sorted(d.items(), key=lambda x: x[1], reverse = True)
        if di[0][1] > di[1][1] + n - num - 1:
            print(di[0][0], num + 1)
            return
    print("TIE")
    return

while 1:
    n = int(input())
    if n == 0:
        break
    main(n)

Solution (Python):
ans_list = []

while True:
    n = int(input())
    if n == 0:
        break
    C = input().split()
    al = [0]*26
    ans = "TIE"
    for i, c in enumerate(C):
        al[ord(c)-65] += 1
        tmp = sorted(al,reverse=True)
        one = tmp[0]
        two = tmp[1]
        remain = n - i - 1
        if one > two + remain:
            win = chr(al.index(one) + 65)
            ans = "{} {}".format(win, i+1)
            break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Solution (Python):
while True:
  n = int(input())
  if n == 0: break
  c = input().split()
  cnt = [0]*26
  for i in range(n):
    num = ord(c[i])-ord('A')
    cnt[num] += 1
    end = False
    for j in range(26):
      win = True
      for k in range(26):
        if k == j: continue
        mx = cnt[k]+(n-1-i)
        if mx >= cnt[j]:
          win = False
      if win:
        print(chr(j+ord('A')),i+1)
        end = True
        break
    if end:
      break      
  else:
    print('TIE')

Solution (Python):
while True:
    n=int(input())
    if n==0:break
    l=list(map(str,input().split()))
    d=dict()
    for i in range(26):
        d[chr(i+ord("A"))]=0
    for i in range(n):
        d[l[i]]+=1
        a=max(d.values())
        l2=sorted(list(d.values()),reverse=True)
        b=l2[1]
        if a-b>n-i-1:
            k=i+1
            break
    ans=0
    for i in range(26):
        if d[chr(i+ord("A"))]==a:
            if ans==0:
                ans=chr(i+ord("A"))
            else:
                ans=-1
                break
    if ans==-1:
        print("TIE")
    else:
        print(ans,k)

Solution (Python):
while True:
    vote_n = int(input())
    if vote_n == 0:
        break
    vote_lst = [v for v in input().split()]
    
    vote_cnt = {}
    for i, v in enumerate(vote_lst):
        if not v in vote_cnt:
            vote_cnt[v] = 1
        else:
            vote_cnt[v] += 1
        
        first = 0
        second = 0
        first_key = None
        for k in vote_cnt:
            if first < vote_cnt[k]:
                second = first
                first = vote_cnt[k]
                first_key = k
            elif second < vote_cnt[k]:
                second = vote_cnt[k]
        
        if first - second > vote_n - (i + 1):
            print(first_key, i + 1)
            break
    if first == second:    
        print('TIE')

Solution (Python):
import sys


from inspect import currentframe


def pri(*args):
    names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))


def solve(n, c):
    flat = ord("A")
    vote_count = [[i, 0] for i in range(26)]
    for i in range(n):
        vote_str = c[i]
        vote_count[ord(vote_str) - flat][1] += 1

        vote_count.sort(key=lambda x: x[1])
        if vote_count[-1][1] > vote_count[-2][1] + (n - i - 1):
            print(chr(vote_count[-1][0] + ord("A")) + " " + str(i+1))
            return
        vote_count.sort()
    print("TIE")
    return


if __name__ == '__main__':
    while True:
        n_input = int(input())
        if n_input == 0:
            break
        c_imput = list(map(str, input().split()))

        solve(n_input, c_imput)

Solution (Python):

from collections import Counter
while True:
    n = int(input())
    if n == 0:
        break
    c = input().split()
    cnt = Counter()

    for i, x in enumerate(c):
        cnt[x] += 1
        m1 = ('', 0)
        m2 = ('', 0)
        for k, v in cnt.items():
            if m1[1] < v:
                m1 = (k, v)
        for k, v in cnt.items():
            if k != m1[0] and m2[1] < v:
                m2 = (k, v)
        if m1[1] - m2[1] >= n - i:
            print(m1[0], i + 1)
            break
    else:
        print('TIE')

Solution (Python):
from collections import defaultdict



import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    if N == 0:
        exit()
    votes = input().split()
    remain = N
    d = dict()
    for a in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
        d[a] = 0
    for v in votes:
        d[v] += 1
        remain -= 1
        
        
        max_key = max((v, k) for (k, v) in d.items())[1]
        if all(val+remain < d[max_key] for key, val in d.items() if key != max_key):
            print(max_key, N-remain)
            return
    print("TIE")


while True:
    solve()