CodeEff/ECCO huggingface dataset:
# Original solution
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(eval(input()))
    mod=10**9+7
    C=[int(eval(input()))for _ in range(n)]
    places=[[] for _ in range(2*10**5+1)]
    for i in range(n):
        places[C[i]].append(i)
    dp=[0]*(n+1)
    dp[0]=1
    for i in range(1,n+1):
        dp[i]=(dp[i]+dp[i-1])%mod
        color=C[i-1]
        it=places[color].index(i-1)
        if it>0:
            j=places[color][it-1]
            if i-1-j>1:
                dp[i]=(dp[i]+dp[j+1])%mod
    print((dp[-1]))


if __name__=='__main__':
    main()

# Optimized solution
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(eval(input()))
    mod=10**9+7
    stone=[0]*(2*10**5+1)
    stone_last_pos=[-1]*(2*10**5+1)
    dp=[0]*(n+1)
    dp[0]=1
    for i in range(1,n+1):
        c=int(eval(input()))
        place=stone_last_pos[c]
        if place==i-1 or place==-1:
            dp[i]=dp[i-1]
        else:
            dp[i]=(dp[i-1]+dp[place])%mod
        stone_last_pos[c]=i
    print((dp[n]))


if __name__=='__main__':
    main()
# Original solution
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(eval(input()))
    mod=10**9+7
    stone=[0]*(2*10**5+1)
    stone_last_pos=[-1]*(2*10**5+1)
    dp=[0]*(n+1)
    dp[0]=1
    for i in range(1,n+1):
        c=int(eval(input()))
        place=stone_last_pos[c]
        if place==i-1 or place==-1:
            dp[i]=dp[i-1]
        else:
            dp[i]=(dp[i-1]+dp[place])%mod
        stone_last_pos[c]=i
    print((dp[n]))


if __name__=='__main__':
    main()

# Optimized solution
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(eval(input()))
    mod=10**9+7
    stone_last_pos=[-1]*(2*10**5+1)
    dp=[0]*(n+1)
    dp[0]=1
    for i in range(1,n+1):
        c=int(eval(input()))
        place=stone_last_pos[c]
        if place==i-1 or place==-1:
            dp[i]=dp[i-1]
        else:
            dp[i]=(dp[i-1]+dp[place])%mod
        stone_last_pos[c]=i
    print((dp[n]))


if __name__=='__main__':
    main()
# Original solution
n = int(eval(input()))
c = [int(eval(input())) for _ in range(n)]

dp = [0] * n
last_dic = {}
for i in range(n):
    if c[i] in list(last_dic.keys()) and i - last_dic[c[i]] >= 2:
        dp[i] = 1 + sum(dp[:last_dic[c[i]]+1])
    last_dic[c[i]] = i
print((1+sum(dp)))

# Optimized solution
n = int(eval(input()))
c = [int(eval(input())) for _ in range(n)]
m = 10**9+7

dp = [-1] * n
dp[0] = 1
last_dic = {}
for i in range(n):
    if c[i] in list(last_dic.keys()) and i - last_dic[c[i]] >= 2:
        dp[i] = (dp[i-1] + dp[last_dic[c[i]]]) % m
    elif i:
        dp[i] = dp[i-1]
    last_dic[c[i]] = i
print((dp[-1]))
# Original solution
n = int(eval(input()))

dp = [1 for i in range(0,n+1)]
c = list()
c.append(-1)
for i in range(1,n+1):
    c.append(int(eval(input())))

for i in range(2,n+1):
    for j in reversed(list(range(1,i))):
        if c[i-1] != c[i] == c[j] != c[j-1]:
            dp[i] = dp[i-1]+dp[j]
            break
    else:
        dp[i] = dp[i-1]
print((dp[-1]))

# Optimized solution
n = int(eval(input()))

dp = [1 for i in range(0,n+1)]
c = list()
c.append(-1)
d = {}
for i in range(1,n+1):
    c.append(int(eval(input())))

for i in range(1,n+1):
    if c[i] in d:
        j = d[c[i]]
        d[c[i]] = i
        if c[i-1] != c[i]:
            dp[i] = dp[i-1]+dp[j]
            continue
    else:
        d[c[i]] = i
    dp[i] = dp[i-1]
print((dp[-1]%(10**9+7)))
# Original solution
n = int(eval(input()))
c = [int(eval(input())) for _ in range(n)]
mod = 10 ** 9 + 7
MAX = 2 * 10 ** 5

cc = []
prev = 0
for e in c:
    if e != prev:
        cc.append(e)
        prev = e

ln = len(cc)

dp = [0] * (ln + 1)
dp[0] = 1
acc = [0] * (MAX + 1)

for i, e in enumerate(cc, 1):
    dp[i] = dp[i-1] + acc[e]
    dp[i] %= mod

    acc[e] += dp[i-1]
    acc[e] %= mod

print((dp[ln]))


# Optimized solution
n = int(eval(input()))
c = [int(eval(input())) for _ in range(n)]
mod = 10 ** 9 + 7
MAX = 2 * 10 ** 5

cc = []
prev = 0
for e in c:
    if e != prev:
        cc.append(e)
        prev = e

ln = len(cc)

dp_prev = 1
acc = [0] * (MAX + 1)

for i, e in enumerate(cc, 1):
    dp_now = dp_prev + acc[e]
    dp_now %= mod

    acc[e] += dp_prev
    acc[e] %= mod

    dp_prev = dp_now

print(dp_now)
# Original solution
N = int(eval(input()))
C = [0] * N
mod = 10 ** 9 + 7
dic = [ [ ] for _ in range(2*(10**5)+1)]
for i in range(N):
    C[i] = int(eval(input()))
    if i > 0 and C[i] == C[i-1]:
        continue
    dic[C[i]].append(i)

dp = [0] * N
dp[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1] % mod
    if C[i] == C[i-1]:
        continue
    for prev in dic[C[i]]:
        if prev < i:
            if prev > 0:
                dp[i] += dp[prev-1]
            else:
                dp[i] += 1
        dp[i] %= mod

print((dp[N-1] % mod))

# Optimized solution
N = int(eval(input()))
C = [0] * N
mod = 10 ** 9 + 7
dic = [-1]*(2*(10**5)+1)
prevIdx = [0] * N
for i in range(N):
    C[i] = int(eval(input()))
    if i > 0 and C[i] == C[i-1]:
        continue
    prevIdx[i] = dic[C[i]]
    dic[C[i]] = i

dp = [0] * N
dp[0] = 1
acc = [0] * N
acc[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1] % mod
    if C[i] == C[i-1] or prevIdx[i] == -1:
        acc[i] = dp[i-1]
        continue
    
    dp[i] += acc[prevIdx[i]]
    acc[i] = acc[prevIdx[i]] + dp[i-1]
    acc[i] %= mod
    dp[i] %= mod

print((dp[N-1] % mod))
# Original solution
N = int(eval(input()))
C = []
tmp_b = -1
for _ in range(N):
  tmp_n = int(eval(input()))
  if tmp_n != tmp_b:
    C.append(tmp_n)
    tmp_b = tmp_n

SUM = 1
DP_dict = {}

for c in C:
  if c not in list(DP_dict.keys()):
    DP_dict[c] = SUM
  else:
    SUM += DP_dict[c]
    DP_dict[c] = SUM

print((SUM % (10**9+7)))

# Optimized solution
N = int(eval(input()))
C = [int(eval(input())) for _ in range(N)]
C = [x for (x,y) in zip(C[:-1], C[1:]) if x!=y] + [C[-1]]

SUM = 1
DP_dict = {}

for c in C:
  if c in list(DP_dict.keys()):
    SUM += DP_dict[c]
  DP_dict[c] = SUM

print((SUM % (10**9+7)))
# Original solution
n=int(eval(input()))
c=[int(eval(input())) for _ in range(n)]
x=[c[0]]
for i in range(1,n):
    if c[i]!=c[i-1]:
        x.append(c[i])
#print(x)

dp=[0 for _ in range(n)]
res=[[] for _ in range(max(x)+1)]
res[x[0]].append(0)
for i in range(1,len(x)):
    if len(res[x[i]])>0:
        if res[x[i]][-1]==0:#左端スタートで１つ目の場合
            dp[i]=dp[i-1]+1
        else:
            dp[i]=dp[i-1]+len(res[x[i]])
            for t in res[x[i]]:
                if t>0:
                    dp[i]+=dp[t-1]
    else:
        dp[i]=dp[i-1]
    res[x[i]].append(i)
#print(dp)
print(((dp[len(x)-1]+1)%(10**9+7)))
#print(res)

# Optimized solution
n=int(eval(input()))
c=[int(eval(input())) for _ in range(n)]
x=[c[0]]
for i in range(1,n):
    if c[i]!=c[i-1]:
        x.append(c[i])
#print(x)

dp=[0 for _ in range(n)]
res=[[] for _ in range(max(x)+1)]
res[x[0]].append(0)
res2=[0 for _ in range(max(x)+1)]
for i in range(1,len(x)):
    if len(res[x[i]])>0:
        if res[x[i]][-1]==0:#左端スタートで１つ目の場合
            dp[i]=dp[i-1]+1
        else:
            dp[i]=dp[i-1]+len(res[x[i]])+res2[x[i]]
            #print(res2[x[i]])
    else:
        dp[i]=dp[i-1]
    res[x[i]].append(i)
    res2[x[i]]+=dp[i-1]
    #print(dp,res2)
print(((dp[len(x)-1]+1)%(10**9+7)))
#print(res)
# Original solution
import sys
from collections import defaultdict
from itertools import groupby

read = sys.stdin.read

N, *C = list(map(int, read().split()))
C = [i for i, _ in groupby(C)]
mod = 10 ** 9 + 7
cnt = defaultdict(int)
dp = 1
for idx, i in enumerate(C):
    prev = dp
    dp = (cnt[i] + dp) % mod
    cnt[i] = (cnt[i] + prev) % mod

print(dp)


# Optimized solution
import sys
from collections import defaultdict
from itertools import groupby

read = sys.stdin.read

N, *C = list(map(int, read().split()))
C = [i for i, _ in groupby(C)]
mod = 10 ** 9 + 7
cnt = defaultdict(int)
dp = 1
for i in C:
    prev = dp
    dp = (cnt[i] + dp) % mod
    cnt[i] = (cnt[i] + prev) % mod

print(dp)
# Original solution
n = int(eval(input()))
z = []
pre = 0
for _ in range(n):
    i = int(eval(input()))
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
place = [[] for _ in range(2 * 10 ** 5)]
for i in range(n):
    dp[i+1] = dp[i]
    for p in place[z[i] - 1]:
        dp[i+1] += dp[p]
    place[z[i] - 1].append(i)
    dp[i+1] %= 10 ** 9 + 7
print((dp[n]))

# Optimized solution
n = int(eval(input()))
z = []
pre = 0
for _ in range(n):
    i = int(eval(input()))
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
dpp = [0] * 2 * 10 ** 5
for i in range(n):
    dp[i+1] = dp[i] + dpp[z[i]-1]
    dpp[z[i]-1] += dp[i]
    dp[i+1] %= 10 ** 9 + 7
print((dp[n]))
# Original solution
from collections import defaultdict
N = int(eval(input()))
tmp = [int(eval(input())) for _ in range(N)]
mod = 10 ** 9 + 7
C = []
for c in tmp:
    if not C:
        C.append(c)
        continue
    if C[-1] != c:
        C.append(c)
N = len(C)

last = defaultdict(int)
ans = 1

for c in C:
    ans += last[c]
    ans %= mod
    last[c] = ans

print(ans)


# Optimized solution
import sys
input = sys.stdin.readline

N = int(eval(input()))
C = [int(eval(input())) for _ in range(N)]
mod = 10 ** 9 + 7

newC = []
while C:
    c = C.pop()
    if not newC or newC[-1] != c:
        newC.append(c)
N = len(newC)

seen = [0] * (2*10 ** 5 + 10)
dp = [0] * (N + 1)
dp[0] = 1
seen[newC[0]] = 1

for i, c in enumerate(newC[1:], start=1):
    cnt = seen[c]
    seen[c] = (seen[c] + dp[i - 1]) % mod
    dp[i] = (dp[i - 1] + cnt) % mod

ans = dp[N - 1]
print(ans)
# Original solution
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

if dice1.is_same(dice2):
    print('Yes')
else:
    print('No')

# Optimized solution
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return 'Yes'
        return 'No'


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

print((dice1.is_same(dice2)))
# Original solution
class Dice:

    def __init__(self):
        # 初期値がない場合
        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        # 初期値が指定される場合
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        
        
def main():
    import random

    t1,s1,e1,w1,n1,b1 = list(map(int, input().split()))
    t2,s2,e2,w2,n2,b2 = list(map(int, input().split()))

    dice1 = Dice(t1,s1,e1,w1,n1,b1)
    dice2 = Dice(t2,s2,e2,w2,n2,b2)

    flag = 0

    for _ in range(10000):

        if (dice1.t, dice1.s, dice1.e, dice1.w, dice1.n, dice1.b) == (dice2.t, dice2.s, dice2.e, dice2.w, dice2.n, dice2.b):
            flag = 1
            break
        else:
            seed = random.randint(0, 3)
            dice2.rot(seed)

    if flag == 1:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()



# Optimized solution
f = list(map(int, input().split()))
s = list(map(int, input().split()))
yes = 0

for _ in range(4):
    s[0],s[2],s[5],s[3] = s[2],s[5],s[3],s[0]
    for _ in range(4):
        s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
        if f == s:
            yes = 1

for _ in range(4):
    s[0],s[1],s[5],s[4] = s[1],s[5],s[4],s[0]
    for _ in range(4):
        s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
        if f == s:
            yes = 1

if yes == 1:
    print('Yes')
else:
    print('No')
# Original solution
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = z[-1:] + z[:-1]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')

# Optimized solution
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = [z[2], z[0], z[1]]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')
# Original solution
class Dice():

    def __init__(self, label):
        self.label = label

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num


def main():
    f = [int(x) for x in input().split()]
    s = [int(x) for x in input().split()]
    dice = Dice(f)
    labels = []
    for i in range(6):
        if i < 4:
            dice.north()
        elif i == 4:
            dice.east()
            dice.south()
        elif i == 5:
            dice.south()
            dice.south()
        for j in range(4):
            dice.west()
            labels.append(dice.label)
    if s in labels:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

# Optimized solution
class Dice():

    def __init__(self, label):
        self.label = label

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def rotate(self):
        self.change([1, 4, 2, 5, 3, 6])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num

    def is_same_dice(self, another_dice):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                if self.label == another_dice:
                    return True
        return False


def main():
    f = [int(x) for x in input().split()]
    s = [int(x) for x in input().split()]

    if Dice(f).is_same_dice(s):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
# Original solution
#coding:utf-8
#1_11_C 2015.4.20
class Dice:
    def __init__(self,ary):
        self.top , self.south , self.east , self.west , self.north ,self.bottom = ary

    def roll_n(self):
        self.top , self.south , self.bottom , self.north = self.south , self.bottom , self.north , self.top

    def roll_e(self):
        self.top , self.west , self.bottom , self.east = self.west , self.bottom , self.east , self.top

    def twist(self):
        self.north , self.west , self.south , self.east = self.east , self.north , self.west , self.south

dice1 = Dice(input().split())
dice2 = Dice(input().split())

while dice1.top != dice2.top or dice1.south != dice2.south:
    if dice1.top == dice2.top:
        while dice1.south != dice2.south:
            dice1.twist()
    elif dice1.south == dice2.south:
        while dice1.top != dice2.top:
            dice1.roll_e()
    else:
        dice1.roll_n()

if dice1.top == dice2.top and dice1.north == dice2.north and dice1.south == dice2.south and dice1.east == dice2.east and dice1.west == dice2.west and dice1.bottom == dice2.bottom:
    print('Yes')
else:
    print('No')

# Optimized solution
#coding:utf-8
#1_11_C

class Dice:
    def __init__(self, ary):
        self.top, self.south, self.east, self.west, self.north, self.bottom = ary

    def roll_n(self):
        self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom

    def roll_e(self):
        self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom

    def twist(self):
        self.north, self.east, self.south, self.west = self.west, self.north, self.east, self.south

    def isEqual(self, dice):
        if self.top == dice.top and self.south == dice.south and self.east == dice.east and self.west == dice.west and self.north == dice.north and self.bottom == dice.bottom:
            return True
        else:
            return False

dice1 = Dice(list(map(int,input().split())))
dice2 = Dice(list(map(int,input().split())))

flag = False

for i in range(6):
    if i % 2 == 0:
        dice1.roll_n()
    else:
        dice1.roll_e()

    for j in range(4):
        if dice1.isEqual(dice2):
            flag = True
            break
        else:
            dice1.twist()

    if flag:
        break

if flag:
    print('Yes')
else:
    print('No')
# Original solution
while True:
    n = int(input())
    if n == 0:
        break
    R = sorted([list(map(int,input().split())) for _ in range(n)],
                key = lambda x:sum(60*m+s for m,s in zip(x[1::2],x[2::2])))
    print("\n".join(map(str,[R[0][0],R[1][0],R[-2][0]])))

# Optimized solution
while True:
    n = eval(input())
    if n == 0:
        break
    R = sorted([list(map(int,input().split())) for _ in range(n)],
                key = lambda x:sum(60*m+s for m,s in zip(x[1::2],x[2::2])))
    print("\n".join(map(str,[R[0][0],R[1][0],R[-2][0]])))
# Original solution
while 1:
  n = eval(input())
  if n==0: break
  d = [0]*n
  for i in range(n):
    x = list(map(int, input().split()))
    d[i]=[sum(x[1::2])*60+sum(x[2::2]),x[0]]
  d = sorted(d)
  print(d[0][1])
  print(d[1][1])
  print(d[-2][1])

# Optimized solution
while 1:
  n = eval(input())
  if n==0: break
  D = [0]*n
  for j in range(n):
    a,b,c,d,e,f,g,h,i = list(map(int, input().split()))
    D[j] = [(b+d+f+h)*60 + c+e+g+i, a]
  D = sorted(D)
  print(D[0][1])
  print(D[1][1])
  print(D[-2][1])
# Original solution
while 1:
  n = eval(input())
  if n==0: break
  D = [0]*n
  for j in range(n):
    a,b,c,d,e,f,g,h,i = list(map(int, input().split()))
    D[j] = [(b+d+f+h)*60 + c+e+g+i, a]
  D = sorted(D)
  print(D[0][1])
  print(D[1][1])
  print(D[-2][1])

# Optimized solution
while 1:
  n = eval(input())
  if n==0: break
  D = {}
  for j in range(n):
    a,b,c,d,e,f,g,h,i = list(map(int, input().split()))
    D[(b+d+f+h)*60 + c+e+g+i] = a
  A = sorted(D)
  for i in [0,1,-2]: print(D[A[i]])
# Original solution
N,M = list(map(int,input().split()))
t = M * 1900 + (N-M) * 100
ac_rate = 1 / (2**M)
rate = 1.0
ans = 0.0
for n in range(1,1000000):
    ans += rate * ac_rate * t * n
    rate *= (1 - ac_rate)
print((round(ans)))


# Optimized solution
N,M = list(map(int,input().split()))

p = 2**M
ans = p * (1900*M + 100*(N-M))
print(ans)
# Original solution
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(N)]
inva = [[0] * M for _ in range(N)]
for i in range(N):
  for j in range(M):
    inva[i][a[i][j] - 1] = j
dp = [N * M] * M
t = [0] * N
vis = set()
#print(inva)
for i in range(M):
  x = 0
  y = 0
  for j in range(M):
    z = 0
    for k in range(N):
      z += inva[k][j] == t[k]
    if z > y:
      y = z
      x = j
  dp[i] = y
  vis.add(x)
  for k in range(N):
    w = M
    for j in range(M):
      if j in vis: continue
      w = min(w, inva[k][j])
    t[k] = w
print((min(dp)))

# Optimized solution
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(N)]
t = [0] * (M + 1)
p = [0] * N
s = set()
res = float("inf")
for _ in range(M):
  t = [0] * (M + 1)
  for i in range(N): t[a[i][p[i]]] += 1
  x = 0
  y = 0
  for j in range(1, M + 1):
    if y < t[j]:
      x = j
      y = t[j]
  s.add(x)
  for i in range(N):
    while a[i][p[i]] in s:
      p[i] += 1
      if p[i] >= M:
        break
  if max(p) >= M: break
  res = min(res, max(t))
  #print(t, p)
print((min(res, N)))