Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
c = []
s = []
f = []

for i in range(N-1):
    _c, _s, _f = map(int, input().split())
    c.append(_c)
    s.append(_s)
    f.append(_f)


for i in range(N):
    sumTime = 0
    stationNumber = i
    #print("(●・▽・●)",stationNumber)
    while stationNumber < N - 1:
        #print("(●・▽・●)(●・▽・●)", stationNumber, sumTime)
        if sumTime <= s[stationNumber]:
            sumTime = s[stationNumber]

        if (sumTime - s[stationNumber]) % f[stationNumber] == 0:
            sumTime += c[stationNumber]
            stationNumber += 1
        else:
            sumTime += 1

    print(sumTime)

### FIXED CODE ###

N = int(input())
c = []
s = []
f = []

for i in range(N-1):
    _c, _s, _f = map(int, input().split())
    c.append(_c)
    s.append(_s)
    f.append(_f)


for i in range(N):
    sumTime = 0
    stationNumber = i
    #print("(●・▽・●)",stationNumber)
    while stationNumber < N - 1:
        #print("(●・▽・●)(●・▽・●)", stationNumber, sumTime)
        if sumTime <= s[stationNumber]:
            sumTime = s[stationNumber]

        if (sumTime - s[stationNumber]) % f[stationNumber] == 0:
            sumTime += c[stationNumber]
            stationNumber += 1
        else:
            sumTime += f[stationNumber] - (sumTime - s[stationNumber]) % f[stationNumber]

    print(sumTime)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def main():
    L,R = map(int,input().split())
    LR = R-L
    M = []
    if L <= 2019 <= R:
        print(0)
        exit()
    for i in range(LR):
        for j in range(LR):
            M.append(((L+i)*(L+1+j))%2019)
    print(min(M))
if __name__ == '__main__':
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
def main():
    L,R = map(int,input().split())
    LR = R-L
    M = []
    if L <= 2019 <= R:
        print(0)
        exit()
    for i in range(LR):
        for j in range(LR):
            M.append(((L+i)*(L+1+j))%2019)
            if ((L+i)*(L+1+j))%2019 == 0:
                print(0)
                exit()
    print(min(M))
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
S = list(input())
Vall = []
ans=[]

for V3 in range(10):
    for V2 in range(10):
        for V1 in range(10):
            Vall.append([V1, V2, V3])

for V in Vall:
    tmp = ''
    p = 0
    j = 0
    while j < 3:
        for i in range(p, N):
            if(V[j] == int(S[i])):
                p = 1+i
                tmp += S[i]
                j += 1
                break
        else:
            break
    if(len(tmp) == 3):
        ans.append(tmp)

print(len(set(ans)))

### FIXED CODE ###

N = int(input())
S = list(map(int,input()))
count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)
### BUGGY CODE ###

n, k= map(int, input().split())
count=0
for i in range(1, n+1):
    for j in range(1, n+1):
        for l in range(1, n+1):
            if (i+j)%k==0 and (j+l)%k==0 and (i+l)%k==0:
                count+=1
print(count)

### FIXED CODE ###

n, k = map(int, input().split())
if k % 2: print((n // k) ** 3)
else: print((n // k) ** 3 + ((n - k //2) // k + 1) ** 3)
### BUGGY CODE ###

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
result = True

for a in A:
    
    if(a[0] % 2 == 0):
        
        if(abs(a[1]) + abs(a[2]) in list(range(a[0] + 1))[0: : 2]):
            result = result and True
        
        else:
            result = False
    
    else:
        if(abs(a[1]) + abs(a[2]) in list(range(a[0] + 1))[1: : 2]):
            result = result and True
        
        else:
            result = False

print(('No', 'Yes')[result])

### FIXED CODE ###

N = int(input())
txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)]
result = True

for i in range(N):
    dt = txy[i + 1][0] - txy[i][0]
    dist = abs(txy[i + 1][1] - txy[i][1]) + abs(txy[i + 1][2] - txy[i][2])
    
    if(dist > dt): result = False
    if(dist % 2 != dt % 2): result = False

print(("No", "Yes")[result])
### BUGGY CODE ###

import heapq


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    prev = [0] * len(adj)
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])
    while q:
        min_dist, v_from = heapq.heappop(q)
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to in v_tos:
            if min_dist + v_to[1] < dist[v_to[0]]:
                dist[v_to[0]] = min_dist + v_to[1]
                prev[v_to[0]] = v_from
                heapq.heappush(q, [dist[v_to[0]], v_to[0]])
    return dist, prev


N, M = map(int, input().split())
adj = [[] for _ in range(2 * N + 1)]
for _ in range(M):
    A, B = map(int, input().split())
    adj[A].append([B, 1])
    adj[A].append([B + N, 1])

ans_best = []
len_ans = N+1
for start in range(1, N+1):
    ans = []
    dist, prev = dijkstra(adj, start)
    if dist[start + N] < 10 ** 10:
        k = start + N
        while k != start:
            k = prev[k]
            ans.append(k)
        if len(ans) < len_ans:
            ans_best = ans
            len_ans = len(ans)

if len_ans == N+1:
    print(-1)
else:
    print(len_ans)
    for a in ans_best:
        print(a)


### FIXED CODE ###

import heapq


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    prev = [0] * len(adj)
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])
    while q:
        min_dist, v_from = heapq.heappop(q)
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to in v_tos:
            if min_dist + v_to[1] < dist[v_to[0]]:
                dist[v_to[0]] = min_dist + v_to[1]
                prev[v_to[0]] = v_from
                heapq.heappush(q, [dist[v_to[0]], v_to[0]])
    return dist, prev


N, M = map(int, input().split())
adj = [[] for _ in range(2 * N + 1)]
flg = 1
see = [0] * (N + 1)
for _ in range(M):
    A, B = map(int, input().split())
    adj[A].append([B, 1])
    adj[A].append([B + N, 1])

ans_best = []
len_ans = N+1
for start in range(1, N+1):
    if flg == 0:
        if see[start] == 0:
            continue
    ans = []
    dist, prev = dijkstra(adj, start)
    if dist[start + N] < 10 ** 10:
        k = start + N
        while k != start:
            k = prev[k]
            ans.append(k)
        if len(ans) < len_ans:
            ans_best = ans
            len_ans = len(ans)
            if flg:
                for a in ans:
                    see[a] = 1
                flg = 0

if len_ans == N+1:
    print(-1)
else:
    print(len_ans)
    for a in ans_best:
        print(a)
### BUGGY CODE ###

#MSOL C 修正

N,K = map(int,input().split())
A = list(map(int,input().split()))
ynlist = []

def checker(i):
  l1 = A[i-K+1:i:]
  i1 = A[i-K]
  i2 = A[i]
  if i1 < i2:
    return "Yes"
  else:
    return "No"

for i in range(K,N):
  print(checker(i))

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K,N):
  if A[i-K] < A[i]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

for i in range(k):
    if len(h) == 0:
        print(0)
        exit()
    m = max(h)
    h.remove(m)

print(sum(h))

### FIXED CODE ###

n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

h = sorted(h)

if n <= k:
    print(0)
    exit()
print(sum(h[0:n-k]))
### BUGGY CODE ###

# C - Cat Snuke and a Voyage
def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(m)]

    for a, b in ab:
        if a == 1:
            for a1, b1 in ab:
                if b == a1 and b1 == n:
                    print('POSSIBLE')
                    exit()
    else:
        print('IMPOSSIBLE')

if __name__ ==  "__main__":
    main()

### FIXED CODE ###

# C - Cat Snuke and a Voyage
def main():
    n, m = map(int, input().split())
    li = [0]*200001

    for _ in range(m):
        a, b = map(int, input().split())
        if a == 1:
            if li[b] == 0:
                li[b] = 1
            else:
                print('POSSIBLE')
                exit()
        if b == n:
            if li[a] == 0:
                li[a] = 1
            else:
                print('POSSIBLE')
                exit()
    else:
        print('IMPOSSIBLE')

if __name__ ==  "__main__":
    main()
### BUGGY CODE ###

N,M=map(int,input().split())
A = [int(x) for x in input().split()]
length = len(A)
for i in range(M):
  b,c = map(int,input().split())
  A.extend(b*[c])
  A.sort(reverse = True)
  A = A[:length]
print(sum(A))

### FIXED CODE ###

read = input 
rn = lambda :map(int, read().split())
n,m = rn()
A = list(rn())
l = len(A)
d = {}
for x in A:
    if x not in d:
        d[x]=0
    d[x] += 1
for i in range(m):
    b, c = rn()
    if c not in d:
        d[c]=0
    d[c] += b
A = list(d.items())
A.sort(reverse=True)
ans = 0
cnt = l
# print(A)
for v, c in A:
    tmp = min(cnt, c)
    ans += tmp * v
    cnt -= tmp
print(ans)
### BUGGY CODE ###

a = int(input())
b= [int(x) for x in input().split()]
c = a
for s in range(a-1):
  d = b[s]
  for t in range(s+1,a):
    if b[t]==0:
      d = d ^ b[t]
      c += 1
    elif d & b[t]:
      break
    else:
      d = d ^ b[t]
      c += 1
print(c)

### FIXED CODE ###

N = int(input())
A= [int(x) for x in input().split()]
A.append(0)
count = N
s = 0
t = 1
xor = A[0]
while s < N - 1:
  while t < N:
    if not A[t] or not (xor & A[t]):
      xor ^= A[t]
      t += 1
    else:
      break
  count += t - s - 1
  while s < t:
    xor ^= A[s]
    s += 1
    if xor & A[t]:
      count += t - s - 1
      continue
    else:
      break
  if s == t:
    xor = A[s]
    t += 1
print(count)
### BUGGY CODE ###

import collections

N = int(input())
S = []
for i in range(N):
    S.append(collections.Counter(input()))

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        count += 1 if S[i]==S[j] else 0

print(count)

### FIXED CODE ###

N = int(input())
S = []

for i in range(N):
    s = input()
    S.append(''.join(sorted(s)))

S.sort()
count = 0
sw = 0
series = []
for i in range(1, len(S)):
    if S[i-1]==S[i]:
        sw = 1
        count += 1
    else:
        if sw==1:
            count += 1
            series.append(count)
            count = 0
            sw = 0
if sw==1:
    count += 1
series.append(count)

count = int(sum([c * (c-1)/2 for c in series]))

print(count)
### BUGGY CODE ###

import numpy as np
N,K = map(int, input().split())

A_list = [0]+list(map(int, input().split()))
A_np=np.array(A_list)
#print(A_np)

for j in range(K):
  new_A_np=np.array([0]*(N+1))
  for i in range(1,N+1):
    tmp_np=np.array([0]*(N+1))
    #print(A_np)
    mi=i-A_np[i]
    ma=i+A_np[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #print(mi,ma)
    tmp_np[mi:ma+1]=1
    #print(tmp_np)
    new_A_np+=tmp_np
  #print(new_A_np)
  A_np=new_A_np
  if sum(A_np[1:N+1])==N*N:
    break
    
for i in range(1,N+1):
  print(A_np[i],end=" ")

### FIXED CODE ###

import numpy as np
from numba import njit

N,K = map(int, input().split())

A_list = np.array([0]+list(map(int, input().split())))

@njit
def update(A_list):

  for j in range(min(K,46)):
    new_A=np.zeros(N+2,dtype=np.int64)
    for i in range(1,N+1):
      #print(new_A)
      mi=i-A_list[i]
      ma=i+A_list[i]
      if mi<0:
        mi=0
      if ma>N:
        ma=N
      #new_A[mi:ma+1]+=1
      new_A[mi]+=1
      new_A[ma+1]-=1

    A_list=np.cumsum(new_A)
    #if sum(A_list[1:N+1])==N*N:
    #  return(A_list)    
    #  break
      
  return(A_list)

A_list=update(A_list)
for i in range(1,N+1):
  print(A_list[i],end=" ")
### BUGGY CODE ###

H,W = map(int,input().split())
src = [list(map(int,input().split())) for i in range(H)]

dp = [[[0 for ex in range(W)] for sx in range(W)] for xy in range(H+W-1)]
dp[0][0][0] = src[0][0]
for xy in range(H+W-2):
    n = min(xy+1,H,W,H+W-xy-1)
    sx0 = max(0,xy-H+1)
    for sx in range(sx0, sx0+n):
        for ex in range(sx, sx0+n):
            sy,ey = xy-sx, xy-ex
            if sx < W-1 and ex < W-1:
                gain = src[sy][sx+1]
                if sx+1 != ex+1: gain += src[ey][ex+1]
                if dp[xy+1][sx+1][ex+1] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx+1][ex+1] = dp[xy][sx][ex] + gain
            if sx < W-1 and ey < H-1:
                gain = src[sy][sx+1]
                if sx+1 != ex: gain += src[ey+1][ex]
                if dp[xy+1][sx+1][ex] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx+1][ex] = dp[xy][sx][ex] + gain
            if sy < H-1 and ex < W-1:
                gain = src[sy+1][sx]
                if sx != ex+1: gain += src[ey][ex+1]
                if dp[xy+1][sx][ex+1] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx][ex+1] = dp[xy][sx][ex] + gain
            if sy < H-1 and ey < H-1:
                gain = src[sy+1][sx]
                if sx != ex: gain += src[ey+1][ex]
                if dp[xy+1][sx][ex] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx][ex] = dp[xy][sx][ex] + gain

print(dp[-1][-1][-1])

### FIXED CODE ###

H,W = map(int,input().split())
src = [list(map(int,input().split())) for i in range(H)]

dp = [[[0 for ex in range(W)] for sx in range(W)] for xy in range(H+W-1)]
dp[0][0][0] = src[0][0]
for xy in range(H+W-2):
    n = min(xy+1,H,W,H+W-xy-1)
    sx0 = max(0,xy-H+1)
    for sx in range(sx0, sx0+n):
        for ex in range(sx, sx0+n):
            sy,ey = xy-sx, xy-ex
            if sx < W-1 and ex < W-1:
                gain = src[sy][sx+1]
                if sx+1 != ex+1: gain += src[ey][ex+1]
                if dp[xy+1][sx+1][ex+1] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx+1][ex+1] = dp[xy][sx][ex] + gain
            if sx < W-1 and ey < H-1:
                gain = src[sy][sx+1]
                if sx+1 != ex: gain += src[ey+1][ex]
                if dp[xy+1][sx+1][ex] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx+1][ex] = dp[xy][sx][ex] + gain
            if sy < H-1 and ex < W-1:
                gain = src[sy+1][sx]
                if sx != ex+1: gain += src[ey][ex+1]
                if dp[xy+1][sx][ex+1] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx][ex+1] = dp[xy][sx][ex] + gain
            if sy < H-1 and ey < H-1:
                gain = src[sy+1][sx]
                if sx != ex: gain += src[ey+1][ex]
                if dp[xy+1][sx][ex] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx][ex] = dp[xy][sx][ex] + gain

print(dp[-1][-1][-1])
### BUGGY CODE ###

if __name__ == '__main__':
	K = int(input())
	dls = []
	d = 7 % K
	dls.append(d)
	c = 1
	if K % 2 == 0:
		c = -1
		d = 0
	while(d != 0):
		d = (d*10 + 7)%K
		if d in dls:
			c = -1
			break
		else:
			c += 1
	print(c)

### FIXED CODE ###

if __name__ == '__main__':
	K = int(input())
	dls = [0] * (K+1)
	d = 7 % K
	dls[d] = 1
	c = 1
	if K % 2 == 0:
		c = -1
		d = 0
	while(d != 0):
		d = (d*10 + 7)%K
		if dls[d] == 1:
			c = -1
			break
		else:
			dls[d] = 1
			c += 1
	print(c)
### BUGGY CODE ###

S = input()
initial_len_S = len(S)
len_S = 1e10
len_S_new = 1e10 - 1

while (len_S_new < len_S):
    len_S= len(S)
    S = S.replace("10", "").replace("01","")
    len_S_new = len(S)

print(initial_len_S - len_S)

### FIXED CODE ###

import re

S = input()

count_1 = len(re.findall('1', S))
count_0 = len(re.findall('0', S))

if(count_1 < count_0):
    print(2 * count_1)
else:
    print(2 * count_0)
### BUGGY CODE ###

import sys
inf = float('inf')

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def SSSP(n, Adj):
    d = [inf] * n
    p = [-1] * n
    checked = [False] * n
    d[0] = 0
    checked[0] = True
    u = 0

    for i in range(n - 1):
        for v, cost in Adj[u]:
            if d[u] + cost < d[v]:
                p[v] = u
                d[v] = d[u] + cost

        min_n = 0
        min_w = inf
        for v in range(n):
            if not checked[v] and d[v] < min_w:
                min_n = v
                min_w = d[v]

        u = min_n
        checked[u] = True

    return d

def solve():
    n = int(input())
    Adj = [[] for i in range(n)]

    for i in range(n):
        u, k, *line = [int(i) for i in input().split()]
        for j in range(k):
            Adj[u].append((line[2*j], line[2*j + 1]))

    # debug(Adj, locals())

    d = SSSP(n, Adj)

    for i in range(n):
        print(i, d[i])

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
import heapq
from collections import namedtuple
inf = float('inf')
Node = namedtuple('Node', 'd, no')

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def SSSP(n, Adj):
    d = [inf] * n
    p = [-1] * n
    checked = [False] * n
    d[0] = 0
    checked[0] = True
    heap = [Node(d[0], 0)]

    while heap:
        u = heapq.heappop(heap)

        if d[u.no] < u.d:
            continue

        checked[u.no] = True

        for v, cost in Adj[u.no]:
            if not checked[v] and d[u.no] + cost < d[v]:
                d[v] = d[u.no] + cost
                p[v] = u.no
                heapq.heappush(heap, Node(d[v], v))

    return d

def solve():
    n = int(input())
    Adj = [[] for i in range(n)]

    for i in range(n):
        u, k, *line = [int(i) for i in input().split()]
        for j in range(k):
            Adj[u].append((line[2*j], line[2*j + 1]))

    # debug(Adj, locals())

    d = SSSP(n, Adj)

    for i in range(n):
        print(i, d[i])

if __name__ == '__main__':
    solve()
### BUGGY CODE ###

s = [ord(i) for i in input()]
K = int(input())

ret = ''
for c in s[:-1] :
    if c == 97 :
        ret += 'a'
        continue
        
    if c + K > 122 :
        ret += 'a'
        K -= 123 - c
    else :
        ret += chr(c)
        
K %= 26
ret += chr((s[-1] + K - 97) % 26 + 97)
        
print(ret)

### FIXED CODE ###

s = [ord(i) for i in input()]
K = int(input())

ret = []
for c in s[:-1] :
    if c == 97 :
        ret.append('a')
        continue
        
    if c + K > 122 :
        ret.append('a')
        K -= 123 - c
    else :
        ret.append(chr(c))
        
K %= 26
ret.append(chr((s[-1] + K - 97) % 26 + 97))
        
print(''.join(ret))
### BUGGY CODE ###

import heapq
import math

def solve():
    N, K = map(int, input().split())
    A = list(map(lambda a: (-float(a), -int(a), 1), input().split()))
    heapq.heapify(A)
    for _ in range(K):
        a = heapq.heappop(A)
        heapq.heappush(A, (a[1] / (a[2] + 1.0), a[1], a[2]+1))

    ans = -heapq.heappop(A)[0]
    print(math.ceil(ans))

solve()

### FIXED CODE ###

import heapq
import math

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()), reverse=True)
    l = 0
    r = A[0]
    # (l, r]
    #print(A)
    #print("K=",K)
    while r - l> 1:
        m = (r + l) // 2
        cuts = 0
        for a in A:
            cuts += (a-1) // m
        #print(l, m,r, cuts)
        if cuts <= K:
            r = m
        else:
            l = m
    print(r)

solve()
### BUGGY CODE ###

n = int(input())

a = []

for i in range(n):
  word = list(input())
  word.sort()
  letters = []
  for j in word:
    if j not in letters:
      letters.append([j, 1])
    else:
      letters[len(letters) - 1][1] += 1
  a.append(letters)

cnt = 0

for i in range(n):
  for j in range(i+1, n):
    if a[i] == a[j]:
      cnt += 1

print(cnt)

### FIXED CODE ###

import collections

n = int(input())
abc = []

for i in range(n):
  a = list(input())
  a.sort()
  a = str(a)
  abc.append(a)

c = collections.Counter(abc)
cnt = 0

for i in c:
  num = c[i]
  if num != 1:
    cnt += num*(num-1) // 2
 
print(cnt)
### BUGGY CODE ###

import sys
import random

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def query(i):
    print(i)
    sys.stdout.flush()
    s = in_s()

    if s == 'Vacant':
        exit(0)
    elif s == 'Male':
        return 0
    elif s == 'Female':
        return 1


def main():

    N = in_n()

    min_i = 0
    max_i = N

    fm = query(0)
    pre = 0

    while max_i - min_i != 1:
        now_i = (min_i + max_i) // 2
        now_fm = query(now_i)

        if pre == 0:
            ti = min_i
        else:
            ti = max_i

        if abs(now_i - ti) % 2 == 0:
            if now_fm == fm:
                min_i = now_i
                pre = 0
            else:
                max_i = now_i
                pre = 1
        elif abs(now_i - ti) % 2 == 1:
            if now_fm == fm:
                max_i = now_i
                pre = 1
            else:
                min_i = now_i
                pre = 0

        fm = now_fm


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import random

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def query(i):
    print(i)
    sys.stdout.flush()
    s = in_s()

    if s == 'Vacant':
        exit(0)
    elif s == 'Male':
        return 0
    elif s == 'Female':
        return 1


def main():

    N = in_n()

    min_i = 0
    max_i = N

    min_fm = query(0)
    max_fm = min_fm

    while max_i - min_i != 1:
        now_i = (min_i + max_i) // 2
        now_fm = query(now_i)

        if abs(now_i - min_i) % 2 == 0 and now_fm != min_fm:
            max_i = now_i
            max_fm = now_fm
        elif abs(now_i - min_i) % 2 == 1 and now_fm == min_fm:
            max_i = now_i
            max_fm = now_fm
        elif abs(now_i - max_i) % 2 == 0 and now_fm != max_fm:
            min_i = now_i
            min_fm = now_fm
        elif abs(now_i - max_i) % 2 == 1 and now_fm == max_fm:
            min_i = now_i
            min_fm = now_fm


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import defaultdict, deque

N = int(input())
S = input()

strList = defaultdict(deque)

for left in range(N):
    sub = S[left]
    strList[sub].append(left)
    for right in range(left + 1, N):
        sub += S[right]
        strList[sub].append(left)

ans = 0
for sub, leftList in strList.items():
    leng = len(sub)
    if leftList[0] + leng <= leftList[-1]:
        ans = max(ans, leng)

print(ans)


### FIXED CODE ###

from collections import deque

N = int(input())
S = input()

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)