Harryxun/stf_run huggingface dataset:
Menagerien = int(input())
s = input()
a = "SS"
ct=1
while ct<7:    
    for i in range(n-1):
        p=a[i]
        q="A"
        if a[i]=="S":
            q="W"
        else:
            q="S"
        if a[i+1]=="S":
            if s[i+1] == "o":
                a=a+a[i]
            else:
                a=a+q
        else:
            if s[i+1] == "o":
                 a=a+q
            else:
                a=a+a[i]
    if a[0]==a[n]:
        if a[0]=="S" and s[0]=="o" and a[n-1]==a[1]:
            print(a[0:n])
            break
        elif a[0]=="S" and s[0] !="o" and a[n-1]!=a[1]:         
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] =="o" and a[n-1]!=a[1]: 
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] !="o" and a[n-1]==a[1]: 
            print(a[0:n])
            break
        else:
            ct=ct+1
        if ct==2:
            a="SW"
        elif ct==3:
            a="WS"
        elif ct==4:
            a="WW"
        else:
            print(-1)
            break
    else:
        ct=ct+1
        if ct==2:
            a="SW"
        elif ct==3:
            a="WS"
        elif ct==4:
            a="WW"
        else:
            print(-1)
            break

### FIXED CODE ###

n = int(input())
s = input()
a = "SS"
ct=1
while ct<7:    
    for i in range(n-1):
        p=a[i]
        q="A"
        if a[i]=="S":
            q="W"
        else:
            q="S"
        if a[i+1]=="S":
            if s[i+1] == "o":
                a=a+a[i]
            else:
                a=a+q
        else:
            if s[i+1] == "o":
                 a=a+q
            else:
                a=a+a[i]
    if a[0]==a[n]:
        if a[0]=="S" and s[0]=="o" and a[n-1]==a[1]:
            print(a[0:n])
            break
        elif a[0]=="S" and s[0] !="o" and a[n-1]!=a[1]:         
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] =="o" and a[n-1]!=a[1]: 
            print(a[0:n])
            break
        elif a[0]=="W" and s[0] !="o" and a[n-1]==a[1]: 
            print(a[0:n])
            break
        else:
            ct=ct+1
            if ct==2:
                a="SW"
            elif ct==3:
                a="WS"
            elif ct==4:
                a="WW"
            else:
                print(-1)
                break
    else:
        ct=ct+1
        if ct==2:
            a="SW"
        elif ct==3:
            a="WS"
        elif ct==4:
            a="WW"
        else:
            print(-1)
            break
N = int(input())
result = 0
for i in range(N**0.5):
  if i**2 <= N:
    result = i
  else:
    None
print(result)

### FIXED CODE ###

N = int(input())
result = 0
for i in range(int(N**0.5)+1):
  if i**2 <= N:
    result = i
  else:
    None
print(result**2)
#l=list(map(int, input().split()))
a,b=map(int, input().split())
#l=list(map(int, input().split()))
#n = int(input())
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def cf(x1,x2):
    cf =[]
    cf.append(1)
    for i in range(2, min(x1,x2)+1):
        if x1 %i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

ans = 1
temp1 = divisor(a)
temp2 = divisor(b)
hoge = []
if len(temp1) < len(temp2):
    hoge = temp1
    hoge2 = temp2
else:
    hoge = temp2
    hoge2 = temp1

temp = []
for i in hoge:
    if i in hoge2:
        temp.append(i)

#print (temp)
for i in temp:
    if is_prime(i):
        ans += 1

print (ans)



### FIXED CODE ###

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

if (n%2==0):
    ans = n//2/n
else:
    ans = (n//2+1)/n

print(ans)
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def main():
    n,m = mi()
    tree = [set() for _ in range(n)]
    for i in range(m):
        s,t = mi()
        tree[s-1].append(t-1)
    dp = [0]*n
    dpl = [0]*n
    for i in range(n-1):
        dpl[i] = len(tree[i])
    for i in reversed(range(n-1)):
        for k in tree[i]:
            dp[i] += dp[k] 
        dp[i] /= dpl[i]
        dp[i] += 1
    ans = dp[0]
    
    def func(ss,tt):
        tmp = 0
        for l in tree[ss]:
            if l == tt:
                continue
            tmp += dp[l]
        tmp = tmp/(dpl[ss] -1) + 1
        if tmp > dp[ss]:
            return dp[0]
        else:
            dp[ss] = tmp
        
        for a in reversed(range(ss)):
            tmp = 0
            for b in tree[a]:
                tmp += dp[b]
            dp[a] = tmp/dpl[a] + 1
        
        return dp[0]
    
    for i in range(n-1):
        if len(tree[i]) == 1:
            continue
        for k in tree[i]:
            ans = min(ans,func(i,k))
    print(ans)

main()

### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m = mi()
tree = [[] for _ in range(n)]
for i in range(m):
    s,t = mi()
    tree[s-1].append(t-1)
dp = [0]*n
for i in reversed(range(n-1)):
    size = len(tree[i])
    for k in tree[i]:
        dp[i] += dp[k] 
    dp[i] /= size
    dp[i] += 1
ans = dp[0]

def func(ss,tt):
    tmp = 0
    for l in tree[ss]:
        if l == tt:
            continue
        tmp += dp[l]
    tmp = tmp/(len(tree[ss])-1) + 1
    if tmp > dp[ss]:
        return dp[0]
    else:
        dp[ss] = tmp
    
    for a in reversed(range(ss)):
        tmp = 0
        for b in tree[a]:
            tmp += dp[b]
        dp[a] = tmp/len(tree[a]) + 1
    
    return dp[0]

for i in range(n-1):
    if len(tree[i]) == 1:
        continue
    for k in tree[i]:
        ans = min(ans,func(i,k))
print(ans)
N,M,K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

S = [0]

Sum = 0


for i in range(N):
  K = K - A[i]
  if K >= 0:
    Sum += 1
  else:
    K = K + A[i]
    break
S.append(Sum)

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if Sum == 0:
      break
    while(K<0):
      i = i - 1
      K = K + A[i]
      Sum = Sum - 1
    Sum += 1
  S.append(Sum)
print(max(S))

### FIXED CODE ###

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

S = [0]

Sum = 0


for i in range(N):
  K = K - A[i]
  if K >= 0:
    Sum += 1
  else:
    K = K + A[i]
    break
else:
  i = N
S.append(Sum)

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if i == 0:
      break
    for k in range(i):
      K = K + A[i-k-1]
      
      Sum = Sum - 1
      if K >= 0:
        i = i-k-1
        break
    else:
      i = 0
      continue
    if K >= 0:
      Sum += 1
    
  S.append(Sum)
 
print(max(S))
N = int(input())
for i in range(N//4 +2):
  for j in range(N//7 + 2):
	if 4*i + 7*j == N:
	  print("Yes")
	  break
  else:
    continue
else:
  print("No")


### FIXED CODE ###

N = int(input())
fmax = int(N/4)+1
smax = int(N/7)+1
for i in range(fmax+1):
  for j in range(smax+1):
    if (4*i+7*j) == N:
      print('Yes')
      exit()
print('No')
s=input()
def check(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
             if s[-5:]=="dream" or s[-5:]=="erase":
                    return check(s[:-5])
             elif s[-7:]=="dreamer":
                    return check(s[:-7])
             elif s[-6:]=="eraser":
                    return check(s[:-6]) 
                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
        else:
            return False

if check(s):
    print("Yes")
else:
    print("No")

        


### FIXED CODE ###

s=input()
length=len(s)

s=s[::-1]

s=s+"WWWWWWW"

index=0
flag=True
while index<length:
    if s[index]=="m" and s[index+1]=="a" and s[index+2]=="e" and s[index+3]=="r" and s[index+4]=="d":
        index+=5
    elif s[index]=="e" and s[index+1]=="s" and s[index+2]=="a" and s[index+3]=="r" and s[index+4]=="e":
        index+=5   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="m" and s[index+3]=="a" and s[index+4]=="e" and s[index+5]=="r" and s[index+6]=="d":
        index+=7   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="s" and s[index+3]=="a" and s[index+4]=="r" and s[index+5]=="e":
        index+=6
    else:
        flag=False
        break
if flag:
    print("YES")
else:
    print("NO")
N, K = map(int, input().split())
 
calc = 0
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp <= K - 1:
    tmp*=2
    cnt+=1
  calc += (1/N) * (1/(2*cnt))

print(calc)

### FIXED CODE ###

N, K = map(int, input().split())
 
calc = 0
for i in range(1, N+1):
  tmp = i
  cnt = 0
  while tmp <= K - 1:
    tmp*=2
    cnt+=1
  calc += (1/N) * (1/(2**cnt))

print(calc)
print(int(input())*int(input()))

### FIXED CODE ###

print(int(input())**2)
#!usr/bin/env python
# -*- coding: utf-8 -*-
X , Y= int(input()), int(input())
print("{}".format(X + Y // 2))

### FIXED CODE ###

#!usr/bin/env python
# -*- coding: utf-8 -*-
X , Y= map(int,input().split())
print("{}".format(X + Y // 2))
a = input()
b = input()

area = int(a) * int(b)
length = 2 * int(a) + 2 * int(b)

print(area length)

### FIXED CODE ###

a,b = list(map(int,input().split()))

area = a*b
length = 2 * (a+b)

print(area,end=" ")
print(length)
n = int(input())
l = list(map(int, input().split()))
x=[]
ans, count, q, xx = 0, 1, "<", 0
for i in range(n+1):
    if q=='<':
        if l[count]<=l[count-1]:
            count+=1
            continue
        else:
            if xx==0:
                q=">"
                xx+=1
                continue
            else:
                ans+=1
                q=">"
                continue
    if q=='>':
        if l[count]>=l[count-1]:
            count+=1
            continue
        else:
            ans+=1
            q="<"
            continue
print(ans+1)

### FIXED CODE ###

num = int(input())
l = list(map(int, input().split()))
count = 1
var = var2 = 0
c = l[0]
for i in l[1:]:
    if c < i:
        var = 1
    elif c > i:
        var2 = 1
    if var == 1 and var2 == 1:
        count += 1
        var = var2 = 0
    c = i
print(count)
# AGC028
from fractions import gcd


def main():
    n, m = tuple(map(int, input().rstrip().split()))
    S, T = tuple(input().rstrip() for _ in range(2))
    l = n // gcd(n, m) * m
    x = [""] * l
    for i in range(n):  # place S in x
        j = (l // n) * i
        x[j] = S[i]

    for i in range(m):  # check T adapts to x or not
        j = (l // m) * i
        if x[j] not in ("", T[i]):
            print(-1)
            break
    else:
        print(l)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# AGC028
from fractions import gcd


def main():
    n, m = tuple(map(int, input().rstrip().split()))
    S, T = tuple(input().rstrip() for _ in range(2))
    l = n // gcd(n, m) * m
    x = {}
    for i in range(n):  # place S in x
        j = (l // n) * i
        x[j] = S[i]
    for i in range(m):  # check T adapts to x or not
        j = (l // m) * i
        if j in x and x[j] != T[i]:
            print(-1)
            break
    else:
        print(l)


if __name__ == "__main__":
    main()
N = int(input())
A = list(map(int, input().split()))
 
A.sort()
rslt = a[0]

for a in A[1:]:
  result *= a
  if rslt > 10**18:
    print(-1)
    exit()
print(rslt)

### FIXED CODE ###

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

limit = 10 ** 18
A.sort()
result = A[0]
for a in A[1:]:
    result *= a
    if result > limit:
        print(-1)
        exit()
print(result)
N = input()
N =int(N)
s = input()
t = input()

for i in range(N):
    q = s[-(i+1):]
    r = t[:i+1]
    if q == r :
        x = q
        y =i+1
print(s[:N-y]+t)

### FIXED CODE ###

N = input()
N =int(N)
s = input()
t = input()
y = 0
for i in range(N):
    q = s[-(i+1):]
    r = t[:i+1]
    if q == r :
        x = q
        y =i+1
print(N*2-y)
s = input()
print(s.[1::2])

### FIXED CODE ###

s = input()
print(s[::2])
import sys
for line in sys.stdin.readlines():
    a="NA"
    for i in xrange(10):
        exp,ans=line.strip().replace("X",str(i)).split("=")
        if eval(exp)==int(ans):
            a=i
    print a

### FIXED CODE ###

import sys
for line in sys.stdin.readlines():
    exp = line.strip()
    ans = "NA"
    # 1<=X<10
    for i in xrange(1,10):
        filled_exp = exp.replace("X",str(i))
        left,right = filled_exp.split("=")
        a,b = left.split("+")
        if int(a)+int(b) == int(right):
            ans = i
    # X==0
    filled_exp = exp.replace("X","0")
    left,right = filled_exp.split("=")
    a,b = left.split("+")
    if not any([(s[0]=="0" and len(s)>1)  for s in (a,b,right)]):
        if int(a)+int(b) == int(right):
            ans = 0
    print ans
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = input()
a = list(int(i) for i in input().split())

lcm = lcm_list(a) - 1

out = 0
for i in a:
    out += lcm%i
print(out)


### FIXED CODE ###

n = int(input())
a = list(int(i) for i in input().split())

print(sum(a)-n)
# -*- coding: utf-8 -*-
# 157b
a = []
b = []
check_list = [False] * 9
for _ in range(3);
  a.extend(list(map(int, input().split())))
n = int(input())
for _ in range(n);
  b.append(int(input()))

for _b in b:
  if _b in a:
    check_list[a.index(_b)] = True

if check_list[0] and check_list[1] and check_list[2]\
  or check_list[3] and check_list[4] and check_list[5]\
  or check_list[6] and check_list[7] and check_list[8]\
  or check_list[0] and check_list[3] and check_list[6]\
  or check_list[1] and check_list[4] and check_list[7]\
  or check_list[2] and check_list[5] and check_list[8]\
  or check_list[0] and check_list[4] and check_list[8]\
  or check_list[2] and check_list[4] and check_list[6]:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

a = []
a.extend(map(int, input().split()))
a.extend(map(int, input().split()))
a.extend(map(int, input().split()))
n = int(input())
b = []

for i in range(n):
  b.append(int(input()))

#print(a, b)

for i in range(len(b)):
  a = [0 if mas == b[i] else mas for mas in a]

if a[0] == 0 and a[1] == 0 and a[2] == 0\
   or a[3] == 0 and a[4] == 0 and a[5] == 0\
   or a[6] == 0 and a[7] == 0 and a[8] == 0\
   or a[0] == 0 and a[3] == 0 and a[6] == 0\
   or a[1] == 0 and a[4] == 0 and a[7] == 0\
   or a[2] == 0 and a[5] == 0 and a[8] == 0\
   or a[0] == 0 and a[4] == 0 and a[8] == 0\
   or a[2] == 0 and a[4] == 0 and a[6] == 0:
  print('Yes')
else:
  print('No')
L = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]

def is_prime_2(n):
  a = int(n ** 0.5)
  for i in L:
    if i > a:return True
    if n % i == 0:return False
  return True

def prime_count(n):
  result = 0
  if n >= 2:result+=1
  for i in range(3,n+1,2):
    if is_prime_2(i):result+=1
  return result

while 1:
  n=input()
  if not n:break
  print(prime_count(int(n)))

### FIXED CODE ###

import sys
import time

MAX = 999999

def is_prime(n):
  if n == 2:return True
  if n % 2 == 0:return False
  for i in range(3,int(n**0.5)+1,2):
    if n % i == 0:return False
  return True

def prime_list(n):
  return ([2] if n > 1 else []) + [i for i in range(3,n+1,2) if is_prime(i)]

L = prime_list(int(MAX**0.5))

def is_prime_2(n):
  a = int(n ** 0.5)
  for i in L:
    if i > a:return True
    if n % i == 0:return False
  return True

def prime_count(n):
  result = 0
  if n >= 2:result+=1
  for i in range(3,n+1,2):
    if is_prime_2(i):result+=1
  return result

def prime_list2(n):
  return ([2] if n > 1 else []) + [i for i in range(3,n+1,2) if is_prime_2(i)]

L2 = prime_list2(MAX)

def prime_count_2(n):
  for i,v in enumerate(L2):
    if v > n:return i
  return len(L2)

for n in sys.stdin:
  print(prime_count_2(int(n)))
def insert(x,a):
    a.insert(0,x)
    return a
def delete(x,a):
    a.remove(x)
    return a
def deletefirst(a):
    del a[0]
    return a
def deletelast(a):
    del a[-1]
    return a
n=input()
a=[]
for i in xrange(n):
    s=raw_input().split()
    if s[0]=="insert":
        insert(s[1],a)
    elif s[0]=="delete":
        delete(s[1],a)
    elif s[0]=="deleteFirst":
        deletefirst(a)
    else:
        deletelast(a)
print(" ".join(a))

### FIXED CODE ###

from collections import deque
def insert(x,a):
    a.appendleft(x)
def delete(x,a):
    if x in a:
        a.remove(x)
    else:
        return
def deletefirst(a):
    a.popleft()
def deletelast(a):
    a.pop()
n=input()
a=deque()
for i in xrange(n):
    s=raw_input().split()
    if s[0]=="insert":
        insert(s[1],a)
    elif s[0]=="delete":
        delete(s[1],a)
    elif s[0]=="deleteFirst":
        deletefirst(a)
    else:
        deletelast(a)
print(" ".join(a))
import sys

list_1 = input().split(" ")
list_2 = list(map(int, list_1))

w = list_2[0]
h = list_2[1]
x = list_2[2]
y = list_2[3]
r = list_2[4]

if !(abs(x - r) < abs(w) and abs(x + r) < abs(w)):
    print("NO")
    sys.exit()

if !(abs(y - r) < abs(h) and abs(y + r) < abs(h)):
    print("NO")
    sys.exit()

print("YES")

### FIXED CODE ###

import sys

input_list = input().split(" ")
input_list = list(map(int, input_list))

w = input_list[0]
h = input_list[1]
x = input_list[2]
y = input_list[3]
r = input_list[4]

if 0 <= x - r and x + r <= w:
    if 0 <= y - r and y + r <= h:
        print("Yes")
        sys.exit()

print("No")
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N = int(readline())
m = map(int,read().split())
AB = zip(m,m)
 
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
dist = [-1] * (N+1)
stack = [1]
dist[1] = 0
while stack:
    v = stack.pop()
    for w in graph[v]:
        if dist[w] == -1:
            dist[w] = dist[v] + 1
            stack.append(w)
 
ev = [i for i,x in enumerate(dist) if x % 2 == 0 and i > 0]
od = [i for i,x in enumerate(dist) if x % 2 == 1 and i > 0]
 
def make_perm(N, ev, od, x0, x1, x2, y0, y1, y2):
    assert len(ev) == x0 + x1 + x2
    assert len(od) == y0 + y1 + y2
    P = [0] * (N+1)
    for i in ev:
        if x0:
            P[i] = (x0 + y0) * 3
            x0 -= 1
            continue
        if x1:
            P[i] = (x1 + y1) * 3 - 2
            x1 -= 1
            continue
        if x2:
            P[i] = (x2 + y2) * 3 - 1
            x2 -= 1
            continue
    for i in od:
        if y0:
            P[i] = (x0 + y0) * 3
            y0 -= 1
            continue
        if y1:
            P[i] = (x1 + y1) * 3 - 2
            y1 -= 1
            continue
        if y2:
            P[i] = (x2 + y2) * 3 - 1
            y2 -= 1
            continue
    return P[1:]
 
def solve(N, ev, od):
    x0 = N // 3
    x1 = (N+2) // 3
    x2 = (N+1) // 3
    perm = [0] * (N+1)
    LE = len(ev)
    LO = len(od)
    if LE <= x0:
        return make_perm(N, ev, od, LE, 0, 0, x0-LE, x1, x2)
    if LO <= x0:
        return make_perm(N, ev, od, x0-LO, x1, x2, LO, 0, 0)
    if LE == x1:
        return make_perm(N, ev, od, 0, x1, 0, x0, 0, x2)
    if LO == x1:
        return make_perm(N, ev, od, x0, 0, x2, 0, x1, 0)
    # どちらも x1 よりたくさんある
    return make_perm(N, ev, od, LE-x1, x1, 0, LO-x2, 0, x2)
 
P = solve(N, ev, od)
print(' '.join(map(str, P)))

### FIXED CODE ###

data =["hi","hihi","hihihi","hihihihi","hihihihihi"]
line = input()
if line in data:
  print("Yes")
else:
  print("No")
N = int(input())
A = [int(a) for a in input().split()] + [0] * 2
X = [[-10**10] * (N+1) for _ in range(N+1)]
X[A[0]][A[1]] = 0
ans = 0
ma = 0
MA = [-10**10] * (N+1)
MA[A[0]] = MA[A[1]] = 0
for i in range(N):
    B = A[i*3+2:i*3+5]
    cnt = len(set(B))
    if cnt == 1:
        ans += 1
    elif cnt == 2:
        a1 = B[0]^B[1]^B[2]
        a2 = (sum(B) - a1) // 2
        X[a1], X[a1][a2], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, X[a1][j], X[j][a1]) for j in range(N+1)], max(X[a1][a2], X[a2][a2] + 1, ma), max(ma, X[a2][a2], X[a1][a1] + 1)
        ma = max(ma, X[a2][a2], max(X[a1]))
        MA = [max(MA[j], X[a1][j]) for j in range(N+1)]
        MA[a1] = max(MA[a1], max(X[a1]))
        MA[a2] = max(MA[a2], X[a2][a2])
    else:
        a, b, c = B
        X[a][b], X[a][c], X[b][c] = max(X[a][b], ma, X[c][c] + 1), max(X[a][c], ma, X[b][b] + 1), max(X[b][c], ma, X[a][a] + 1)
        X[a], X[b], X[c] = [max(A[a][j], MA[j]) for j in range(N+1)], [max(A[b][j], MA[j]) for j in range(N+1)], [max(A[c][j], MA[j]) for j in range(N+1)]
        MA[a] = max(MA[a], X[a][b], X[a][c])
        MA[b] = max(MA[b], X[a][b], X[b][c])
        MA[c] = max(MA[c], X[a][c], X[b][c])
        ma = max(ma, X[a][b], X[a][c], X[b][c])

print(ans + max(ma, max(max(x) for x in X)))

### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()] + [0] * 2
X = [[-10**10] * (N+1) for _ in range(N+1)]
X[A[0]][A[1]] = 0
ans = 0
ma = 0
MA = [-10**10] * (N+1)
MA[A[0]] = MA[A[1]] = 0
for i in range(N):
    B = A[i*3+2:i*3+5]
    cnt = len(set(B))
    if cnt == 1:
        ans += 1
    elif cnt == 2:
        a1 = B[0]^B[1]^B[2]
        a2 = (sum(B) - a1) // 2
        # 
        # X[a1], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, X[a1][j], X[j][a1]) for j in range(N+1)], max(ma, X[a2][a2], X[a1][a1] + 1)
        # X[a1], X[a1][a2], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, X[a1][j], X[j][a1]) for j in range(N+1)], max(X[a1][a2], X[a2][a2] + 1, ma), max(ma, X[a2][a2], X[a1][a1] + 1)
        X[a1], X[a1][a2], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, MA[j]) for j in range(N+1)], max(X[a1][a2], X[a2][a2] + 1, ma), max(ma, X[a2][a2], X[a1][a1] + 1)
        #
        X[a2] = [max(X[a2][j], MA[j]) for j in range(N+1)]
        MA = [max(MA[j], X[a1][j], X[a2][j]) for j in range(N+1)]
        MA[a1] = max(MA[a1], max(X[a1]), X[a2][a1])
        MA[a2] = max(MA[a2], X[a1][a2], X[a2][a2])
        ma = max(ma, MA[a1], MA[a2])
    else:
        a, b, c = B
        X[a][b], X[a][c], X[b][c] = max(X[a][b], ma, X[c][c] + 1), max(X[a][c], ma, X[b][b] + 1), max(X[b][c], ma, X[a][a] + 1)
        X[a] = [max(X[a][j], MA[j]) for j in range(N+1)]
        X[b] = [max(X[b][j], MA[j]) for j in range(N+1)]
        X[c] = [max(X[c][j], MA[j]) for j in range(N+1)]
        MA[a] = max(MA[a], max(X[a]))
        MA[b] = max(MA[b], X[a][b], max(X[b]))
        MA[c] = max(MA[c], X[a][c], X[b][c], max(X[c]))
        MA = [max(MA[j], X[a][j], X[b][j], X[c][j]) for j in range(N+1)]
        ma = max(ma, MA[a], MA[b], MA[c])

print(ans + max(ma, max(max(x) for x in X)))
s = raw_input()
n = int(raw_input())

head = []
sub = 0

for i, v in enumerate(s):
    if v == 'S':
        head.append(i)

    if v == 'T' and head:
        head.pop(0)
        sub += 2

print(len(s) - sub)

### FIXED CODE ###

ipt = raw_input()
l = ""
for s in ipt:
    if not l:
        l += s
    elif l[-1]+s == "ST":
        l = l[:-1]
    else:
        l += s
print len(l)
_ = input()
u = list(map(int,input().split())).sort()
print(u[-1] - u[0])

### FIXED CODE ###

_ = input()
k = input()
u = list(map(int,k.split()))
u.sort()
print(u[-1] - u[0])