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

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


def calc_yz(target, limit):
    yz_list = []
    for y in range(limit + 1):
        z = target - y
        if 0 <= z <= limit:
            yz_list.append([y, z])
    return yz_list


def calc_xyz(target, limit):
    xyz_list = []
    for x in range(limit + 1):
        yz_sum = target - x
        if yz_sum < 0:
            continue
        yz_list = calc_yz(yz_sum, limit)
        for yz in yz_list:
            xyz_list.append([x] + yz)
    return xyz_list


print(len(calc_xyz(s, k)))


### FIXED CODE ###

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


def calc_xyz(target, limit):
    cnt = 0
    for x in range(min(limit, target) + 1):
        yz_sum = target - x
        for y in range(min(limit, yz_sum) + 1):
            if 0 <= target - x - y <= limit:
                cnt += 1
    return cnt


print(calc_xyz(s, k))
### BUGGY CODE ###

mod = 10**9 + 7

def solve(n, A, index):
    if n == 1:
        s = 0
        for i in range(index, len(A)):
            s += A[i][1]
        # print(index, A[index:], s)
        return s
    ans = 0
    for i in range(index, len(A)):
        a = A[i]
        ans = (ans + a[1] * solve(n - 1, A, i + 1)) % mod
    return ans

def main():
    N = int(input())
    S = input()
    num_chars = 0
    A = {}
    for s in S:
        if s not in A:
            A[s] = 0
            num_chars += 1
        A[s] += 1
    # print(num_chars, A)
    B = [(a, A[a]) for a in A]

    ans = 0
    for i in range(num_chars):
        ans = (ans + solve(i + 1, B, 0)) % mod
        # print(ans)
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

mod = 10**9 + 7

def main():
    N = int(input())
    S = input()
    num_chars = 0
    A = {}
    for s in S:
        if s not in A:
            A[s] = 0
            num_chars += 1
        A[s] += 1
    # print(num_chars, A)
    B = [(a, A[a]) for a in A]

    ans = 1
    for b in B:
        ans = (ans * (b[1] + 1)) % mod
    print(ans - 1)

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

n,k=map(int,input().split())
a=[int(o) for o in input().split()]
prod=1
for i in range(k):
    prod*=a[i]
for i in range(k,n):
    prev=prod
    prod//=a[i-k]
    prod*=a[i]
    if prod>prev: print("Yes")
    else: print("No")


### FIXED CODE ###

from sys import stdin, stdout 
n,k=map(int,input().split())
a=[int(o) for o in input().split()]
prod=1
for i in range(k,n):
    prev=a[i-k]
    if a[i]>prev: stdout.write("Yes\n")
    else: stdout.write("No\n")
### BUGGY CODE ###

import numpy as np

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

cost = np.zeros(n)

for i in range(1,n):
    left = max(0,i-k)
    tmp = min(cost[left:i]+abs(h[i]-h[left:i]))
    cost[i] = tmp

print(int(cost[-1]))


### FIXED CODE ###

import numpy as np

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

cost = np.zeros(n)


for i in range(1,n):
    left = max(0,i-k)
    cost[i] = (cost[left:i]+abs(h[i]-h[left:i])).min()
     

print(int(cost[-1]))
### BUGGY CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7


def main():
    L = list(input())

    def power(a, n):
        x = 1
        while n:
            if n & 1:
                x = x * a % MOD
            n >>= 1
            a = a * a % MOD
        return x

    def cnt(s):
        if len(s) == 1:
            if s[0] == "1":
                return 3
            else:
                return 1
        if s[0] == "0":
            return cnt(s[1:]) % MOD
        else:
            return (cnt(s[1:]) * 2) % MOD + pow(3, len(s) - 1)

    answer = cnt(L) % MOD

    print(answer)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import queue


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7


def main():
    L = list(input())

    pow = [0] * (len(L) + 1)
    pow[0] = 1
    for i in range(1, len(L) + 1):
        pow[i] = pow[i - 1] * 3 % MOD
    N = len(L)
    if L[-1] == "0":
        answer = 1
    else:
        answer = 3
    for i in range(1, N):
        if L[N - i - 1] == "1":
            answer = answer * 2 + pow[i]
            answer %= MOD
        else:
            continue
    print(answer)


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

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

def operation(x, k):
    return abs(x - k)

while True:
    nn = operation(n, k)
    if nn >= n:
        ans = n
        break
    else:
        n = nn

print(ans)

### FIXED CODE ###

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

d = n // k
ans = min(abs(n - k * d), abs(n - k * (d + 1)))

print(ans)
### BUGGY CODE ###

n = int(input())
l = [int(x) for x in input().split()]
MOD = 1000000007
ans = 0
for d in range(60):
    ones = 0
    for a in l:
        if a >> d & 1:
            ones += 1
    zeroes = n - ones
    ans += pow(2, d, MOD) * ones % MOD * zeroes % MOD
ans %= MOD
print(ans)


### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
MOD = 1000000007
ans = 0
for digit in range(60):
    ones = 0
    for num in a:
        if num >> digit & 1:
            ones += 1
    zeroes = n - ones  # Zeros?
    ans = (ans + ones * zeroes * pow(2, digit, MOD)) % MOD

print(ans)
### BUGGY CODE ###

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

dist = []
for i in range(N-K+1):
    a = 0
    tmp = x[i:i+K]
    mini, maxi = tmp[0], tmp[-1]
    if (mini >= 0 and maxi >= 0):
        a = tmp[-1]
    elif (mini < 0 and maxi < 0):
        a = abs(tmp[0])
    if mini < 0 and maxi >= 0:
        a = abs(tmp[0]) + tmp[-1] + min(abs(tmp[0]), tmp[-1])
    dist.append(a)

print(min(dist))

### FIXED CODE ###

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

dist = []
for i in range(N-K+1): 
    l, r = x[i], x[i+K-1]
    t = min(abs(l)+abs(l-r), abs(r)+abs(r-l))
    dist.append(t)

print(min(dist))
### BUGGY CODE ###

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
a.sort()
dp = [10 ** 18 for i in range(n)]
dp[0] = 0
for l, r, c in a:
    for i in range(l - 1, r):
        dp[i] = min(dp[i], dp[l - 1] + c)
if dp[-1] == 10 ** 18:
    print(-1)
else:
    print(dp[-1])


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(m)]
    a.sort()
    INF = 10 ** 18
    dp = [INF for i in range(n)]
    dp[0] = 0
    for l, r, c in a:
        if dp[l - 1] == INF:
            print(-1)
            return None
        tp = dp[l - 1] + c
        for i in range(r - 1, l - 1, -1):
            if dp[i] == INF:
                dp[i] = tp
            elif tp < dp[i]:
                dp[i] = tp
            else:
                break
    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


main()
### BUGGY CODE ###

import math
from itertools import permutations

D, G = map(int, input().split(' '))
questions = [tuple(map(int, input().split(' '))) for _ in range(D)]

min_answer = 1000

for question_ids in permutations(range(D)):
    score = G
    answer = 0
    for question_id in question_ids:
        n, bonus = questions[question_id]
        point = 100 * (question_id + 1)
        n_ans = min(n, math.ceil(score / point))
        answer += n_ans
        score -= n_ans * point
        if n_ans == n:
            score -= bonus
        if score <= 0:
            min_answer = min(min_answer, answer)
            break

print(min_answer)


### FIXED CODE ###

from itertools import product

D, G = map(int, input().split(' '))
questions = [tuple(map(int, input().split(' '))) for _ in range(D)]
questions = [(100 * index, n, bonus) for index, (n, bonus) in enumerate(questions, start=1)]

min_answer = 1000

for bits in product((True, False), repeat=D):
    not_complete = []
    score = G
    answered = 0
    for index, bit in enumerate(bits):
        if not bit:
            not_complete.append(index)
            continue

        point, n, bonus = questions[index]
        score -= point * n + bonus
        answered += n

    if not_complete:
        index = max(not_complete)
        point, n, _ = questions[index]
        while score > 0 and n > 1:
            score -= point
            n -= 1
            answered += 1

    if score <= 0:
        min_answer = min(min_answer, answered)

print(min_answer)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Oct  7 22:06:12 2018
ABC073D
@author: maezawa
"""
import itertools as itr
import sys
#input = sys.stdin.readline

n, m, r = list(map(int, input().split()))
rarray = list(map(int, input().split()))
adjmatrix = [[10**10]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
    adjmatrix[i][i] = 0
    
for i in range(m):
    a, b, c = list(map(int, input().split()))
    if adjmatrix[a][b] > c:
        adjmatrix[a][b] = c
        adjmatrix[b][a] = c

#print(abc)

# Warshall-Floyd Algorithm
for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            adjmatrix[i][j] = min([adjmatrix[i][j],
                      adjmatrix[i][k] + adjmatrix[k][j]])
            #adjmatrix[j][i] = adjmatrix[i][j]
        
#print(*adjmatrix, sep='\n')
    
# search for ri to rj
mincnt = 10*10
for route in itr.permutations(rarray):
    cnt = 0
    for i in range(len(rarray)-1):
        cnt += adjmatrix[route[i]][route[i+1]]
    if cnt < mincnt:
        mincnt = cnt

print(mincnt)
        
        

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Oct  8 10:17:39 2018

@author: maezawa
"""

import math
from itertools import permutations

#フロイド・ワーシャル
def warshall_floyd(glath):
	
	for k in range(len(glath)):
		for i in range(len(glath)):
			for j in range(len(glath[i])):
				if glath[i][j] > glath[i][k] + glath[k][j]:
                                   glath[i][j] = glath[i][k] + glath[k][j]
                                   glath[j][i] = glath[i][k] + glath[k][j]				
	return glath

N, M ,R= [int(x) for x in str(input()).split()]  #グラフの大きさ 
r=[int(x) for x in str(input()).split()]
graph=[[float("inf")]*N for i in range(N)]


for i in range(M):
	a,b,c=[int(x) for x in str(input()).split()]
	#if a in r and b in r:
	graph[a-1][b-1]=c
	graph[b-1][a-1]=c

#all_cost=warshall_floyd(select_graph)
all_cost=warshall_floyd(graph)


max_count=float("inf")
for i in permutations(r):
        cost=0
        for j in range(len(i)-1):                
                cost+= all_cost[i[j]-1][i[j+1]-1]       
        max_count=min(max_count,cost)

print(max_count)
### BUGGY CODE ###

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

print(max([(sum(p[i:i+K])+K)/2 for i in range(N-K+1)]))

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
  
# 「和の期待値」は「期待値の和」なので、先に期待値を求める
for i in range(N):
  p[i] = (1+p[i])/2

# 累積和
S = [0]*N
S[0] = p[0]
for i in range(N-1):
  S[i+1] = S[i] + p[i+1]

ans = S[K-1]
for i in range(N-K):
  ans = max(ans, S[i+K] - S[i])

print(ans)
### BUGGY CODE ###

s = list(input())
q = int(input())
f = False #さかさま
for i in range(q):
    x = list(input().split())
    if x[0]=='1':
        f = not f
    else:
        if f:
            if x[1]=='1': s = s+[x[2]]
            else: s = [x[2]]+s
        else:
            if x[1]=='1': s = [x[2]]+s
            else: s = s+[x[2]]
if f: s.reverse()
print(''.join(s))

### FIXED CODE ###

s = list(input())
q = int(input())
a = []
f = False #さかさま
for i in range(q):
    x = list(input().split())
    if x[0]=='1':
        f = not f
    else:
        if f:
            if x[1]=='1': s.append(x[2])
            else: a.append(x[2])
        else:
            if x[1]=='1': a.append(x[2])
            else: s.append(x[2])
a.reverse()
s = a+s
if f:s.reverse()
print(''.join(s))
### BUGGY CODE ###

n,q = list(map(int,input().split()))
s = list(input())
num = list()
for i in range(0,q):
    num.append(list(map(int,input().split())))
check = list()
for i in range(0,n-1):
    if s[i] == "A" and s[i+1] == "C":
        check.append(i+1)
count = list()
for i in range(0,q):
    for k in check:
        if num[i][0] <= k and num[i][1] > k:
            count.append(k)
    print(len(count))
    count = list()

### FIXED CODE ###

n,q = list(map(int,input().split()))
s = list(input())
num = list()
check = [0]*n
for i in range(1,n):
        if s[i-1] == "A" and s[i] == "C":
                check[i] = check[i-1]+1
        else:
                check[i] = check[i-1]
ans = 0
for i in range(0,q):
        num = list(map(int,input().split()))
        ans = check[num[1]-1]-check[num[0]-1]
        print(ans)
### BUGGY CODE ###

#C - Sum of product of pairs
N = int(input())
A = list(map(int,input().split()))
SUM = 0
MOD = 1000000007
for i in range(N-1):
    for j in range(i+1,N):
            SUM = (SUM + (A[i] * A[j] % MOD) ) % MOD

# 出力
print(SUM)



### FIXED CODE ###

#C - Sum of product of pairs
N = int(input())
A = list(map(int,input().split()))
SUM = 0
jsum= 0
MOD = 1000000007
for j in range(N):
    jsum = (jsum + A[j]) % MOD

for i in range(N-1):
    jsum = (jsum - A[i]) % MOD
    SUM = ( SUM + (jsum * A[i] % MOD ) ) % MOD

# 出力
print(SUM)
### BUGGY CODE ###

N, Q = input().split()
S = input()
for i in range(int(Q)):
    str_l, str_r = input().split()
    l =	int(str_l)
    r =	int(str_r)
    count = 0
    for j in range(r - l):
        if 'AC' == S[j+l-1:j+l+1]:
            count += 1
    print(count)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

for i in range(Q):
    l, r = map(int, input().split())
    l = l - 1
    r = r - 1
    print(AC_appearance[r] - AC_appearance[l])
### BUGGY CODE ###

N = input()
L = list(map(int,input().split()))
A = []
for a in L:
  if (a not in A):
    A.append(a)
J = []
for i in range(len(A)):
  J.append(L.count(A[i]-1)+L.count(A[i])+L.count(A[i]+1))
print(max(J))

### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(1000000)
M = [0]*((10**5)+1)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)
### BUGGY CODE ###

n, k ,q  =map(int, input().split())

lis = []
for _ in range(q):
    lis.append(int(input()))
    
ori = k - q
for i in range(n):
    if ori + lis.count(i+1) > 0:
        print("Yes")
    else:
        print("No")



### FIXED CODE ###

n, k ,q  =map(int, input().split())

lis = [k-q] * n
for _ in range(q):
    tmp = int(input())
    lis[tmp - 1] += 1

for i in lis:
    if i > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Sep  1 21:55:48 2019

@author: Yamazaki Kenichi
"""


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

T = [0 for i in range(N)]
today = [True for i in range(N)]
yesterday = [i for i in range(N)]

ans = 0
counta = 0
while counta < N:
    today = [True for i in range(N)]
    today_p = []
    for i in yesterday:
        if today[i]:
            vs = A[i][T[i]] - 1
            if A[vs][T[vs]] == i + 1 and today[vs]:
                T[i] += 1
                T[vs] += 1
                if T[i] == N - 1:
                    T[i] = 0
                    counta += 1
                if T[vs] == N - 1:
                    T[vs] = 0 
                    counta += 1
                today[i], today[vs] = False, False
                today_p.extend([i,vs])
    yesterday = today_p
#        print(i,vs,today,T)
    if len(today_p) == 0:
        ans = -1
        break
    ans += 1
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Sep  1 21:55:48 2019

@author: Yamazaki Kenichi
"""


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

T = [0 for i in range(N)]
today = [True for i in range(N)]
yesterday = [i for i in range(N)]

ans = 0
counta = 0
while counta < N:
    today = set([])
    today_p = []
    for i in yesterday:
        if not i in today:
            vs = A[i][T[i]] - 1
            if A[vs][T[vs]] == i + 1 and not vs in today:
                T[i] += 1
                T[vs] += 1
                if T[i] == N - 1:
                    T[i] = 0
                    counta += 1
                if T[vs] == N - 1:
                    T[vs] = 0 
                    counta += 1
                today.add(i)
                today.add(vs)
                today_p.extend([i,vs])
    yesterday = today_p
#        print(i,vs,today,T)
    if len(today_p) == 0:
        ans = -1
        break
    ans += 1
print(ans)
### BUGGY CODE ###

import collections

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

c = collections.Counter(a)
sum = 0

if len(c) <= k:
    print("0")
    exit(0)

for i in range(0, k):
    sum = sum + c.most_common()[i][1]

print(max(len(a)-sum, 0))

### FIXED CODE ###

import collections

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

c = collections.Counter(a)
b = list(sorted(c.values(), reverse=True))
sum = 0

if len(c) <= k:
    print("0")
    exit(0)

for i in range(0, k):
    sum = sum + b[i]

print(max(len(a)-sum, 0))
### BUGGY CODE ###

import itertools
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
com=list(itertools.combinations(h,k))
#a=10**9
gap=[]
for i in range(len(com)):
    b=abs(max(com[i])-min(com[i]))
    gap.append(b)

a=min(gap)    
print(a)

### FIXED CODE ###

n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
#for i in range(n-k+1):
print(min(h[i+k-1]-h[i] for i in range(n-k+1)))
### BUGGY CODE ###

if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    two_factor = 1

    for d in range(60):
        even, odd = 0, 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % MOD * two_factor % MOD
        res = (res + add) % MOD
        two_factor = two_factor * 2 % MOD

    print(res)


### FIXED CODE ###

if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    two_factor = 1

    for d in range(60):
        even, odd = 0, 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % MOD * two_factor % MOD
        res = (res + add) % MOD
        two_factor = two_factor * 2 % MOD

    print(res)
### BUGGY CODE ###

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab.sort()
px = [list(map(int, input().split())) for i in range(q)]
p = [0 for i in range(n)]
for i in px:
  p[i[0] - 1] += i[1]
s = ""
for i in ab:
  p[i[1]-1] += p[i[0]-1]
print(" ".join(map(str, p)))

### FIXED CODE ###

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab.sort()
p = [0]*n
for i in range(q):
  a, b = map(int, input().split())
  p[a - 1] += b
s = ""
for i in ab:
  p[i[1]-1] += p[i[0]-1]
print(*p)
### BUGGY CODE ###

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

for i in range(n):
    b = a.pop(0)
    if (b in a) is True:
        print("NO")
        x = 1
        break

if x == 0:
    print("YES")


### FIXED CODE ###

n = int(input())
a = list(int(x) for x in input().split())
x = 0
 
a.sort()
for i in range(n-1):
    if a[-1] - a[-2] == 0:
        print("NO")
        x = 1
        break
    a.pop()
 
if x == 0:
    print("YES")
### BUGGY CODE ###

from bisect import bisect_left
N = int(input())
A = list(int(input()) for _ in range(N))
INF = 10 ** 9 + 1
V = [False for i in range(N)]
nv = 0
cnt = 0
while nv < N:
    dp = [INF]
    for i, a in enumerate(A):
        if V[i]:
            continue
        if a > dp[-1]:
            dp.append(a)
        else:
            j = bisect_left(dp, a)
            dp[j] = a
    nv += len(dp)
    dp.append(INF)
    m = len(dp)
    for i in range(N-1, -1, -1):
        if V[i]:
            continue
        if dp[m-1] <= A[i] < dp[m]:
            V[i] = True
            m -= 1
    cnt += 1

print(cnt)


### FIXED CODE ###

from bisect import bisect_right
N = int(input())
A = list(int(input()) for _ in range(N))
INF = 10 ** 9 + 1

dp = [INF]
for a in A:
    if -a >= dp[-1]:
        dp.append(-a)
    else:
        j = bisect_right(dp, -a)
        dp[j] = -a

print(len(dp))
### BUGGY CODE ###

# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

N,M=map(int, input().split())
A=np.array([i for i in range(N+1)[1::]])

for _ in range(M):
    L,R=map(int, input().split())
    tmp=np.array([i for i in range(R+1)[L::]])
    A = np.intersect1d(A,tmp)

print(len(A))

### FIXED CODE ###

# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

N,M=map(int, input().split())
A=np.array([i for i in range(N+1)[1::]])


minimum = 1
maximum = N

for _ in range(M):
    L,R=map(int, input().split())

    if(R < minimum or maximum < L):
        print(0)
        exit()

    if(minimum < L):
        minimum = L
    if(R < maximum):
        maximum = R

print(maximum - minimum + 1)
### BUGGY CODE ###

S = input()
Q = int(input())
flag = 0   #"1" represents inversion
for i in range(Q):
    quary = list(map(str, input().split()))
    if quary[0] == "1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        if flag == 1:
            if quary[1] == "1":
                S = S+quary[2]
            else:
                S = quary[2]+S
        else:
            if quary[1] == "1":
                S = quary[2]+S
            else:
                S = S+quary[2]
if flag == 1:
    S = S[::-1]
print(S)

### FIXED CODE ###

S = input()
Q = int(input())
flag = 0   #"1" represents inversion
head = ""
tail = ""
for i in range(Q):
    quary = list(map(str, input().split()))
    if quary[0] == "1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        if flag == 1:
            if quary[1] == "1":
                tail = tail+quary[2]
            else:
                head = quary[2]+head
        else:
            if quary[1] == "1":
                head = quary[2]+head
            else:
                tail = tail+quary[2]
S = head+S+tail
if flag == 1:
    S = S[::-1]
print(S)
### BUGGY CODE ###

N,K,Q=map(int,input().split())
B=[K]*N
def minu(n):
  return n-1
for i in range(Q):
  A=int(input())
  if A==1:
    B[1:]=map(minu,B[1:])
  elif A==N:
    B[:-2]=map(minu,B[:-2])
  else:
    B[:A-1]=map(minu,B[:A-1])
    B[A:]=map(minu,B[A:])
for i in range(N):
  if B[i]>0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

N,K,Q=map(int,input().split())
B=[0]*N
def minu(n):
  return n-1
for i in range(Q):
  A=int(input())
  B[A-1]+=1
for i in range(N):
  if B[i]>Q-K:
    print("Yes")
  else:
    print("No")