Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class BIT:
    def __init__(self, n):
        # 0-indexed
        self.size = n
        self.tree = [0] * (n+1)
 
    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s
    
    # 区間和の取得 [l, r)
    def get(self, l, r=None):
        # 引数が1つなら一点の値を取得
        if r is None: r = l+1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    # 値の追加：添字, 値
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

# 1からnまでの等差数列の和
def get_sum(n): return (1+n)*n//2

N, K = MAP()
A = LIST()

bit = BIT(N+1)
org = 0
for i in range(N-1, -1, -1):
    bit.add(A[i], 1)
    # 自分より右にある、自分より小さな数の個数
    org += bit.sum(A[i]-1)

ans = (org*K + org*get_sum(K-1)) % MOD
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class BIT:
    def __init__(self, n):
        # 0-indexed
        self.size = n
        self.tree = [0] * (n+1)
 
    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s
    
    # 区間和の取得 [l, r)
    def get(self, l, r=None):
        # 引数が1つなら一点の値を取得
        if r is None: r = l+1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    # 値の追加：添字, 値
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

# 1からnまでの等差数列の和
def get_sum(n): return (1+n)*n//2

N, K = MAP()
A = LIST()
M = max(A)

bit = BIT(M+1)
org = 0
for i in range(N-1, -1, -1):
    bit.add(A[i], 1)
    # 自分より右にある、自分より小さな数の個数
    org += bit.sum(A[i]-1)
bit = BIT(M+1)
org2 = 0
for i in range(N):
    bit.add(A[i], 1)
    # 自分より左にある、自分より小さな数の個数
    org2 += bit.sum(A[i]-1)

ans = (org*K+(org+org2)*get_sum(K-1)) % MOD
print(ans)
import sys
from itertools import combinations
import bisect
import math
import numpy as np
n = int(input())
l_ls = [int(i) for i in sys.stdin.readline().split()]
l_ls.sort()
l_dict = { i : j for i, j in enumerate(l_ls)}
_sum_ls = []
cnt = 0
count_ls = np.zeros(2*10**3, dtype=np.int64)
for l in l_ls:
    count_ls[:l+1] += 1
for combi in combinations(l_ls, 2):
    ind = count_ls[combi[0] + combi[1]]
    cnt += ind
"""
for combi in combinations(l_ls, 2):
    count_ls[combi[0] + combi[1]:] += 1
    #bisect.insort_left(_sum_ls, combi[0] + combi[1])
len_sum_ls = len(_sum_ls)
for l in l_ls:
    #ind = bisect.bisect_right(_sum_ls, l)
    ind = count_ls[l]
    cnt += ind
"""

print(int(math.factorial(n) / math.factorial(3) / math.factorial(n-3)) - cnt)

### FIXED CODE ###

import sys
from itertools import combinations
import bisect
import math
n = int(input())
l_ls = [int(i) for i in sys.stdin.readline().split()]
l_ls.sort()
cnt = 0
for a, b in combinations(l_ls, 2):
    _sum = a + b
    ind = bisect.bisect_left(l_ls, _sum)
    cnt += n - ind
print(int(math.factorial(n) // math.factorial(3) // math.factorial(n-3)) - cnt)
N,K=map(int,input().split())
print(N%(N//K))


### FIXED CODE ###

N,K=map(int,input().split())
print(1 if N%K!=0 else 0)
import sys

input = sys.stdin.readline

n_k = list(map(int, input().split()))
n = n_k[0]
k = n_k[1]
a = list(map(int, input().split()))
a_pos = list(filter(lambda v: v >= 0, a))
a_neg = list(filter(lambda v: v < 0, a))

a_pos.sort(reverse=True)
a_neg.sort()

mod = 10**9+7

ans = 1
if n == k:
    for a_i in a:
        ans = ans * a_i % mod
elif len(a_pos) == 0 and k % 2 == 1:
    for i in reversed(range(len(a_neg) - k, len(a_neg))):
        ans = ans * a_neg[i] % mod
else:
    i_p = 0
    i_n = 0
    i = 0
    while i < k:
        if i_p < k and (i == k - 1 or i_n+1 >= len(a_neg) or a_pos[i_p] * (a_pos[i_p+1] if i_p+1 < len(a_pos) else 1) > a_neg[i_n] * a_neg[i_n+1]):
            ans = ans * a_pos[i_p] % mod
            i_p += 1
            i += 1
        else:
            ans = ans * a_neg[i_n] % mod * a_neg[i_n+1] % mod
            i_n += 2
            i += 2
print(ans)

### FIXED CODE ###

import sys

input = sys.stdin.readline

n_k = list(map(int, input().split()))
n = n_k[0]
k = n_k[1]
a = list(map(int, input().split()))
a_pos = list(filter(lambda v: v >= 0, a))
a_neg = list(filter(lambda v: v < 0, a))

a_pos.sort(reverse=True)
a_neg.sort()

mod = 10**9+7

ans = 1
if n == k:
    for a_i in a:
        ans = ans * a_i % mod
elif len(a_pos) == 0 and k % 2 == 1:
    for i in reversed(range(len(a_neg) - k, len(a_neg))):
        ans = ans * a_neg[i] % mod
else:
    i_p = 0
    i_n = 0
    i = 0
    while i < k:
        if i_p < len(a_pos) and (i == k - 1 or i_n+1 >= len(a_neg) or a_pos[i_p] * (a_pos[i_p+1] if i_p+1 < len(a_pos) else 1) > a_neg[i_n] * a_neg[i_n+1]):
            ans = ans * a_pos[i_p] % mod
            i_p += 1
            i += 1
        else:
            ans = ans * a_neg[i_n] % mod * a_neg[i_n+1] % mod
            i_n += 2
            i += 2
print(ans)
a, b=map(int, input())
if a%2==1 and b%2==1:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a, b=map(int, input().split())
if a%2==1 and b%2==1:
  print("Yes")
else:
  print("No")
#!/usr/bin/env python3
import sys

N=0
M=0

def next_num(x):
    if int(x[-1]) < M:
        return x[:-1] + [int(x[-1]) + 1]
    elif int(x[-1]) == M:
        oya = next_num(x[:-1])
        return oya + [oya[-1]]


def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    start = ['1' for i in range(N)]
    current = start
    ans = 0
    while True:
        result = 0
        for a_, b_, c_, d_ in zip(a, b, c, d):
            if int(current[b_]) - int(current[a_]) == c_:
                result += d_
        if result > ans:
            ans = result
        if current[0] == M:
            break
        current = next_num(current)
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    global N, M
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens)) - 1
        b[i] = int(next(tokens)) - 1
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

N=0
M=0

def next_num(x):
    if int(x[-1]) < M:
        return x[:-1] + [str(int(x[-1]) + 1)]
    elif int(x[-1]) == M:
        oya = next_num(x[:-1])
        return oya + [oya[-1]]


def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    start = ['1' for i in range(N)]
    current = start
    ans = 0
    while True:
        result = 0
        for a_, b_, c_, d_ in zip(a, b, c, d):
            if int(current[b_]) - int(current[a_]) == c_:
                result += d_
        if result > ans:
            ans = result
        if current[0] == str(M):
            break
        current = next_num(current)
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    global N, M
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens)) - 1
        b[i] = int(next(tokens)) - 1
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)

if __name__ == '__main__':
    main()
N, K = map(int, input().split())
S = input()

print(S[:K] + {'A': 'a', 'B': 'b', 'C': 'c'}[S[K]] + (S[K+1:] if K+1 < N else ''))


### FIXED CODE ###

N, K = map(int, input().split())
S = input()
K -= 1
print(S[:K] + {'A': 'a', 'B': 'b', 'C': 'c'}[S[K]] + (S[K+1:] if K+1 < N else ''))
from collections import Counter
n = 5
for _ in range(n):
  word = ''.join(sort(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(word_counter.values()) - n)

### FIXED CODE ###

from collections import Counter
n = int(input())
word_l = list()
for _ in range(n):
  word = ''.join(sorted(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(map(lambda x: sum(range(x)), word_counter.values()))))
from sys import stdin
from sys import math

def GCD(a,b):
    if(a%b==0):
        return b
    else:
        c = a%b
        return GCD(b,c)

def LCM(a,b):
    gcd = GCD(a,b)
    return a*b/gcd

for line in stdin:
    a,b = line.split(" ")
    a = int(a)
    b = int(b)
    gcd = GCD(a,b)
    lcm = math.floor(LCM(a,b))

    print(str(gcd)+" "+str(lcm))
    print()



### FIXED CODE ###

from sys import stdin
import math

def GCD(a,b):
    if(a%b==0):
        return b
    else:
        c = a%b
        return GCD(b,c)

def LCM(a,b):
    gcd = GCD(a,b)
    return int(a*b/gcd)

for line in stdin:
    a,b = line.split(" ")
    a = int(a)
    b = int(b)
    gcd = GCD(a,b)
    lcm = LCM(a,b)

    print(str(gcd)+" "+str(lcm))
A11, A12, A13 = input().split(' ')
A21, A22, A23 = input().split(' ')
A31, A32, A33 = input().split(' ')
A11 = int(A11)
A12 = int(A12)
A13 = int(A13)
A21 = int(A21)
A22 = int(A22)
A23 = int(A23)
A31 = int(A31)
A32 = int(A32)
A33 = int(A33)
N = int(input())
b = []
for i in range(N):
  bi = int(input())
  b.append(bi)
if A11 in b and A12 in b and A13 in b:
  print('Yes')
elif A21 in b and A22 in b and A23 in b:
  print('Yes')
elif A31 in b and A32 in b and A33 in b:
  print('Yes')
elif A11 in b and A21 in b and A31 in b:
  print('Yes')
elif A12 in band A22 in b and A32 in b:
  print('Yes')
elif A13 in b and A23 in b and A33 in b:
  print('Yes')
elif A11 in b and A22 in b and A33 in b:
  print('Yes')
elif A13 in b and A22 in b  and A31 in b:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

A11, A12, A13 = input().split(' ')
A21, A22, A23 = input().split(' ')
A31, A32, A33 = input().split(' ')
A11 = int(A11)
A12 = int(A12)
A13 = int(A13)
A21 = int(A21)
A22 = int(A22)
A23 = int(A23)
A31 = int(A31)
A32 = int(A32)
A33 = int(A33)
N = int(input())
b = []
for i in range(N):
  bi = int(input())
  b.append(bi)
if A11 in b and A12 in b and A13 in b:
  print('Yes')
elif A21 in b and A22 in b and A23 in b:
  print('Yes')
elif A31 in b and A32 in b and A33 in b:
  print('Yes')
elif A11 in b and A21 in b and A31 in b:
  print('Yes')
elif A12 in b and A22 in b and A32 in b:
  print('Yes')
elif A13 in b and A23 in b and A33 in b:
  print('Yes')
elif A11 in b and A22 in b and A33 in b:
  print('Yes')
elif A13 in b and A22 in b  and A31 in b:
  print('Yes')
else:
  print('No')
A, B = map(int, input().split())
cnt = 0
for n in range(A,B+1):
  n_str = str(n)
  n_len = len(n)
  is_kaibun = True
  for i in range(n_len//2):
    if n_str[i] != n_str[n_len-1-i]:
      is_kaibun = False
  if is_kaibun is True:
    cnt += 1
print(cnt)

# if n_str[0] == n_str[4] and n_str[1] == n_str[3]:
#   cnt += 1

### FIXED CODE ###

A, B = map(int, input().split())
cnt = 0
for n in range(A,B+1):
  n_str = str(n)
  n_len = len(n_str)
  is_kaibun = True
  for i in range(n_len//2):
    if n_str[i] != n_str[n_len-1-i]:
      is_kaibun = False
  if is_kaibun is True:
    cnt += 1
print(cnt)

# if n_str[0] == n_str[4] and n_str[1] == n_str[3]:
#   cnt += 1
X, Y, A, B, C = map(int,input().split())
listp = list(map(int, input().split()))
listq = list(map(int, input().split()))
listr = list(map(int, input().split()))

listp = sorted(listp, reverse=True)
listq = sorted(listq, reverse=True)
listr = sorted(listr, reverse=True)
listp = listp[:X]
listq = listq[:Y]

eat_noapple = []
oisisa = 0

for noapple in listr:
    if listp[-1] >= listq[-1] and listq[-1] < noapple:
        listq.pop(-1)
        eat_noapple.append(noapple)
    elif listp[-1] < listq[-1] and listp[-1] < noapple:
        listp.pop(-1)
        eat_noapple.append(noapple)
    else:
        break
try:
    for papple in listq:
        oisisa += papple
except:
    a = 0
try:
    for qapple in listp:
        oisisa += qapple
except:
    a = 0
try:
    for rapple in eat_noapple:
        oisisa += rapple
except:
    a = 0
print(oisisa)

### FIXED CODE ###

X, Y, A, B, C = map(int,input().split())
listp = list(map(int, input().split()))
listq = list(map(int, input().split()))
listr = list(map(int, input().split()))

listp = sorted(listp, reverse=True)
listq = sorted(listq, reverse=True)
listr = sorted(listr, reverse=True)
listp = listp[:X]
listq = listq[:Y]
listr = listr[:X+Y]
listp.insert(0, 1000000000000)
listq.insert(0, 1000000000000)


eat_noapple = []
oisisa = 0

for noapple in listr:
    if listp[-1] >= listq[-1] and listq[-1] < noapple:
        listq.pop(-1)
        eat_noapple.append(noapple)
    elif listp[-1] < listq[-1] and listp[-1] < noapple:
        listp.pop(-1)
        eat_noapple.append(noapple)
    else:
        break
listp.pop(0)
listq.pop(0)

try:
    for papple in listq:
        oisisa += papple
except:
    a = 0
try:
    for qapple in listp:
        oisisa += qapple
except:
    a = 0
try:
    for rapple in eat_noapple:
        oisisa += rapple
except:
    a = 0
print(oisisa)
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()

# a = [[0] * (w + 2)] * (h + 2)
s = [list(input()) for _ in range(h)]

dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
            # スルー
        num = 0
        for d in range(8):
            ni = i + dy[d]
            nj = j + dx[d]
            # niとnjで有効なのはsの定義域．
            # ni w 0 <= ni <= w - 1
            # nj h 0 <= nj <= h - 1
            
            if ni < 0 or w <= ni:
                continue
                # スルー
            if nj < 0 or h <= nj:
                continue
                # スールー
            if s[ni][nj] == "#":
                num += 1
            s[i][j] = str(num)
            # (num + "0")

for i in range(h):
    print("".join(s[i]))


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()

# a = [[0] * (w + 2)] * (h + 2)
s = [list(input()) for _ in range(h)]

dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
            # スルー
        num = 0
        for d in range(8):
            ni = i + dy[d]
            nj = j + dx[d]
            # niとnjで有効なのはsの定義域．
            # ni w 0 <= ni <= w - 1
            # nj h 0 <= nj <= h - 1
            
            if ni < 0 or h <= ni:
                continue
                # スルー
            if nj < 0 or w <= nj:
                continue
                # スールー
            if s[ni][nj] == "#":
                num += 1
        s[i][j] = str(num)
            # (num + "0")

for i in range(h):
    print("".join(s[i]))
m,k=map(int,input().split())
if k>=2**m-1:
  print(-1)
elif m==0:
  print(0,0)
elif m==1:
  if k==0:
    print(0,0,1,1)
  elif k==1:
    print(-1)
else:
  ris=[i for i in range(m)]
  ris.remove(k)
  print(ris+k+ris[::-1]+k)

### FIXED CODE ###

m,k=map(int,input().split())
if k>=2**m:
  print(-1)
elif m==0:
  print(0,0)
elif m==1:
  if k==0:
    print(0,0,1,1)
  elif k==1:
    print(-1)
else:
  ris=[str(i) for i in range(2**m)]
  ris.remove(str(k))
  l=" ".join(ris)
  r=" ".join(ris[::-1])
  print(l,str(k),r,str(k))
a, b = int (input().split())
c = a*b % 2
if c==0:
 print("Even")
else:
 print("Odd")


### FIXED CODE ###

a, b =map( int, input().split())
c = a*b % 2
if c==0 :
 print("Even")
else :
 print("Odd")
l,r = map(int,input().split())
ans = 2019
mod = 2019
 
for i in range(l,r):
  for j in range(i+1,r):
    ans = min(ans,(i*j)%mod)
    if ans == 0:
      print(0)
      exit()
print(ans)

### FIXED CODE ###

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

if N*A>B:
	print(B)
else:
	print (A*N)
N, Q = map(int, input().split())
S = input()
lr = [0] * Q
for i in range(Q):
  lr[i] = list(map(int, input().split()))

b, t = 0, [0]*N
for i in range(1, N):
  if S[i-1:i+1] == 'AC':
    t[i] += 1
  else: t[i] = t[i-1]

for i in range(Q):
  print(t[lr[i][1]] - t[lr[i][0]])

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
lr = [0] * Q
for i in range(Q):
  lr[i] = list(map(lambda x: int(x) - 1, input().split()))
 
b, t = 0, [0]*N
for i in range(1, N):
  if S[i-1] == 'A' and S[i] == 'C':
    t[i] = t[i-1] + 1
  else: t[i] = t[i-1]
 
for i in range(Q):
  print(t[lr[i][1]] - t[lr[i][0]])
N, M = map(int, input().split())

MOD = 1_000_000_007

if abs(N - M) > 1:
    print(0)
    exit(0)

dogs = 1
for i in range(1, N + 1):
    dogs *= i
    dogs %= MOD

monks = 1
for i in range(1, M + 1):
    monks *= i
    monks %= MOD

res = (dogs * monks) % MOD
if (N + M) % 2 == 0:
    res *= 2
    res %= MOD

print(res)


### FIXED CODE ###

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

MOD = 1000000007

if abs(N - M) > 1:
    print(0)
    exit(0)

dogs = 1
for i in range(1, N + 1):
    dogs *= i
    dogs %= MOD

monks = 1
for i in range(1, M + 1):
    monks *= i
    monks %= MOD

res = (dogs * monks) % MOD
if (N + M) % 2 == 0:
    res *= 2
    res %= MOD

print(res)
n, k = map(int, input().split())
s = str(input())
a = []
b = []

count = 1
for i in range(1, n):
    if s[i] == s[i-1]:
        count += 1
    else:
        if s[i-1] == "L":
            a.append(count)
        else:
            b.append(count)
        count = 1
if s[i] == "L":
    a.append(count)
else:
    b.append(count)
count = 1

a.sort(reverse=True)
b.sort(reverse=True)
ans1 = sum(a) - len(a)
ans2 = sum(b) - len(b)
for i in range(min(2*k, len(b))):
    ans1 += b[i]
if len(b) < 2*k:
    ans1 += 2*k - len(b)
ans1 = min(n-1, ans1)
for i in range(min(2*k, len(a))):
    ans2 += a[i]
if len(a) < 2*k:
    ans2 += 2*k - len(a)
ans2 = min(n-1, ans2)
print(max(ans1, ans2))


### FIXED CODE ###

n, k = map(int, input().split())
s = str(input())

lr = 0
rl = 0
for i in range(1, n):
    if s[i-1] == "L" and s[i] == "R":
        lr += 1
    if s[i-1] == "R" and s[i] == "L":
        rl += 1
ans = n - (lr + rl + 1) + (2 * min(min(lr, rl), k))

if k > min(lr, rl):
    if lr > rl and (s[0] == "L" or s[-1] == "R"):
        ans += 1
    if lr < rl and (s[0] == "R" or s[-1] == "L"):
        ans += 1
print(ans)
N = int(input())
S = list(input())
ans = 0
for i in range(N):
    if (S[i]=="A" and S[i+1]=="B" and S[i+2]=="C"):
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
ans = 0
for i in range(N-2):
    if (S[i]=="A" and S[i+1]=="B" and S[i+2]=="C"):
        ans += 1
print(ans)
n, k = map(int, input().split())
s = str(input())

count = 1
Nums_count = []
now = s[0]
start = 0
for i in range(1,n):
    if s[i] == str(now):
        count += 1
    else:
        Nums_count.append([start, count])
        now = s[i]
        start = i
        count = 1
    if i == n-1:
        Nums_count.append([start, count])
if len(s) == 1:
    Nums_count.append([0,1])

Nums_count_rui = [[-1, 0]]
for i in range(len(Nums_count)):
    Nums_count_rui.append([Nums_count[i][0],Nums_count[i][1]+Nums_count_rui[-1][1]])

# print(Nums_count_rui)
ans = 0
m = len(Nums_count_rui)

if s[0] == '0' and m <= 2*k:
    ans = n
elif s[0] == '1' and m <= 2*k+1:
    ans = n

for i in range(1,m+1):
    if s[Nums_count_rui[i][0]] == '0':
        if i+2*k-1 >= m:
            tot = Nums_count_rui[-1][1] - Nums_count_rui[i-1][1]
        else:
            tot = Nums_count_rui[i+2*k-1][1] - Nums_count_rui[i-1][1]
    else:
        if i+2*k >= m:
            tot = Nums_count_rui[-1][1] - Nums_count_rui[i-1][1]
        else:
            tot = Nums_count_rui[i+2*k][1] - Nums_count_rui[i-1][1]
    ans = max(tot, ans)
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
s = str(input())

count = 1
Nums_count = []
now = s[0]
start = 0
for i in range(1,n):
    if s[i] == str(now):
        count += 1
    else:
        Nums_count.append([start, count])
        now = s[i]
        start = i
        count = 1
    if i == n-1:
        Nums_count.append([start, count])
if len(s) == 1:
    Nums_count.append([0,1])

Nums_count_rui = [[-1, 0]]
for i in range(len(Nums_count)):
    Nums_count_rui.append([Nums_count[i][0],Nums_count[i][1]+Nums_count_rui[-1][1]])

# print(Nums_count_rui)
ans = 0
m = len(Nums_count_rui)

if s[0] == '0' and m <= 2*k:
    ans = n
elif s[0] == '1' and m <= 2*k+1:
    ans = n

for i in range(1,m):
    if s[Nums_count_rui[i][0]] == '0':
        if i+2*k-1 >= m:
            tot = Nums_count_rui[-1][1] - Nums_count_rui[i-1][1]
        else:
            tot = Nums_count_rui[i+2*k-1][1] - Nums_count_rui[i-1][1]
    else:
        if i+2*k >= m:
            tot = Nums_count_rui[-1][1] - Nums_count_rui[i-1][1]
        else:
            tot = Nums_count_rui[i+2*k][1] - Nums_count_rui[i-1][1]
    ans = max(tot, ans)
print(ans)
n = int(input())
cur = 0
best = 0
for _ in range(n):
  	a, b = input().split()
    if a == b:
        cur += 1
        best = max(best, cur)
    else:
      	cur = 0
if best >= 3:
  	print("Yes")
else:
  	print("No")

### FIXED CODE ###

n = int(input())
cur = 0
best = 0
for _ in range(n):
        a, b = input().split()
        if a == b:
                cur += 1
                best = max(best, cur)
        else:
                cur = 0
if best >= 3:
        print("Yes")
else:
        print("No")