Harryxun/stf_run huggingface dataset:
import Math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = Math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2)
	s = x[2]+x[5]
	r = Math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

### FIXED CODE ###

import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = (x[0]-x[3])**2 + (x[1]-x[4])**2
	d = math.sqrt(d)
	d = math.fabs(d)
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if d > s:
		answers.append(0)
	elif d == s:
		answers.append(1)
	elif d < s:
		if d < r:
			if x[2] > x[5]:
				answers.append(2)
			else:
				answers.append(-2)
		elif d >= r:
			answers.append(1)
for val in answers:
	print val
n = int(input())
t = {i:{} for i in range(n)}
ans = [-1]*n
for _ in range(n-1):
    u, v, w = map(int, input().split())
    t[u-1][v-1] = w
    t[v-1][u-1] = w

def dfs(x):
    for y in t[x]:
        del t[y][x]
        ans[y] = ans[x] if t[x][y] % 2 == 0 else 1-ans[x]
        dfs(y)

ans[0] = 0
dfs(0)
for i in range(n):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

n = int(input())
t = {i:{} for i in range(n)}
ans = [-1]*n
for _ in range(n-1):
    u, v, w = map(int, input().split())
    t[u-1][v-1] = w
    t[v-1][u-1] = w

def dfs(x):
    for y in t[x]:
        del t[y][x]
        ans[y] = ans[x] if t[x][y] % 2 == 0 else 1-ans[x]
        if len(t[y]) > 0:
            dfs(y)

ans[0] = 0
dfs(0)
for i in range(n):
    print(ans[i])
n, m = map( int, input().split() )
connect = []

for _ in range( n+1 ):
    connect.append( [ 0 ] * ( n+1 ) )

for _ in range( m ):
    a, b = map( int, input().split() )
    connect[ a ][ b ] = 1
    connect[ b ][ a ] = 1

guide = [ 0 ] * ( n+1 )
path = [ 0, 0 ] + [ m+1 ] * ( n-1 )

def solve( a ): # aに隣接したやつのguideをaにする．またそれのpathをpath[a]+1にする．
    print( "calc " + str(a) )
    for b in range( 1, n+1 ):
        if connect[a][b] == 1 and path[a] + 1 < path[b]:
            print( "update " + str(b) )
            path[b] = path[a] + 1
            guide[b] = a
            solve(b)

solve( 1 )

print( guide, path )
if 0 not in guide[2:]:
    print( "Yes" )
    for i in range( 2, n+1 ):
        print( guide[i] )
else:
    print( "No" )

### FIXED CODE ###

####以下カンニング####
n, m = map( int, input().split() )
connect = {}

for _ in range( m ):
    a, b = map( int, input().split() )
    try:
        connect[ a ].append( b )
    except KeyError:
        connect[ a ] = [ b ]
    try:
        connect[ b ].append( a )
    except KeyError:
        connect[ b ] = [ a ]

queue = [ 1 ]
guide = [ -1 ] * ( n+1 )
visited = [ False ] * ( n+1 )

while queue:
    x = queue.pop(0)
    for y in connect[ x ]:
        if visited[ y ] == False:
            queue.append( y )
            guide[ y ] = x
            visited[ y ] = True

print( "Yes" )
for x in range( 2, n+1 ):
    print( guide[x] )
# input
N = int(input())
A = []

#list
for i in range(N):
    n = int(input())
    A.append(n)

#max
for i in range(N):
    A_=A[:i]
    A__=A[i+1:]
    print(max(A_+A__))

### FIXED CODE ###

r = int(input())
print(3*r**2)
from math import ceil

s, k = input(), int(input())

ans = []
a = ord('z') + 1
for i in s:
    if k == 0:
        break
    elif a - ord(i) <= k:
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k
if ans[-1] >= a:
    ans[-1] -= ceil((ans[-1] - (a - 1)) / 26)
print(*map(chr, ans), sep='')


### FIXED CODE ###

s, k = input(), int(input())

ans = []
a = ord('z') + 1
for i in s:
    if k == 0:
        ans.append(ord(i))
    elif a - ord(i) <= k and i != 'a':
        k -= a - ord(i)
        ans.append(ord('a'))
    else:
        ans.append(ord(i))
ans[-1] += k % 26
if ans[-1] >= a:
    ans[-1] -= 26
print(*map(chr, ans), sep='')
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rnk=[0]*(n+1)

    def Find_Root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        if x==y:
            return
        elif self.rnk[x]>self.rnk[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y]+=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

h,w=map(int,input().split())
g=[list(input()) for _ in range(h)]
uf=UnionFind(h*w)
dyx=[(1,0),(-1,0),(0,1),(0,-1)]
for i in range(h):
    for j in range(w):
        if g[i][j]==".":
            continue
        p=i*w+j
        for dy,dx in dyx:
            y=i+dy
            x=j+dx
            if 0<=y<h and 0<=x<w:
                if g[y][x]==".":
                    np=y*w+x
                    uf.Unite(p,np)

rt=[0]*(h*w)
for i in range(h*w):
    rt[i]=uf.Find_Root(i)

m=min(rt)
rt=list(map(lambda x:x-m, rt))
m=max(rt)
a=[[0,0] for _ in range(m+1)]
for i in range(h*w):
    y=i//w
    x=i%w
    if g[y][x]=="#":
        a[rt[i]][0]+=1
    else:
        a[rt[i]][1]+=1
ans=0
for i,j in a:
    ans+=i*j

print(ans)


### FIXED CODE ###

n=int(input())
h=int(input())
w=int(input())
print((n-h+1)*(n-w+1))
import bisect
x=int(input())
a=[i*111 for i in range(1,9)]
print(a[bisect.bisect_left(a,x)])


### FIXED CODE ###

import bisect
x=int(input())
a=[i*111 for i in range(1,10)]
print(a[bisect.bisect_left(a,x)])
#n桁のるんるん数のrisutoを求める
import sys

sys.setrecursionlimit(10**9)
def runrun(n):
    if n == 1:
        return [['1','2','3','4','5','6','7','8','9']]
    else:
        li = runrun(n-1)
        li2 = []
        for i in range(len(li[n-2])):
            p = int(li[n-2][i][-1])
            if p == 0:
                li2.append(li[n-2][i]+'0')
                li2.append(li[n-2][i]+'1')
            elif p == 9:
                li2.append(li[n-2][i]+str(8))
                li2.append(li[n-2][i]+'9')
            else:
                li2.append(li[n-2][i]+str(p-1))
                li2.append(li[n-2][i]+str(p))
                li2.append(li[n-2][i]+str(p+1))
        li2 =[li2]
        li.extend(li2)
        return li
    


x = int(input())
t = True
k=1
b = 0
while t:
    
    a = runrun(k)
    #k桁までに何個るんるん数があるか数えるもの
    for i in range(len(a)):
        b+=(len(a[i])-1)
        #k桁ということが確定したあと以下の処理を行う
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k-1)
            c = 0
            for i in range(len(tmp)):
                c+=len(tmp[i])
            s = a[k-1][x-c-1]
            print(int(s))
    else:
        b += 1
        k += 1
        

### FIXED CODE ###

#n桁のるんるん数のrisutoを求める
import sys

sys.setrecursionlimit(10**9)

def runrun(n):
    if n == 1:
        return [['1','2','3','4','5','6','7','8','9']]
    else:
        li = runrun(n-1)
        li2 = []
        for i in range(len(li[n-2])):
            p = int(li[n-2][i][-1])
            if p == 0:
                li2.append(li[n-2][i]+'0')
                li2.append(li[n-2][i]+'1')
            elif p == 9:
                li2.append(li[n-2][i]+str(8))
                li2.append(li[n-2][i]+'9')
            else:
                li2.append(li[n-2][i]+str(p-1))
                li2.append(li[n-2][i]+str(p))
                li2.append(li[n-2][i]+str(p+1))
        li2 =[li2]
        li.extend(li2)
        return li
    


x = int(input())
t = True
k=1
b = 0
while t:
    a = runrun(k)
    b = 0
    #k桁までに何個るんるん数があるか数えるもの
    for i in range(len(a)):
        b+=(len(a[i]))
        #k桁ということが確定したあと以下の処理を行う
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k-1)
            c = 0
#まずk-1桁までのるんるん数の数を数える
            for i in range(len(tmp)):
                c += (len(tmp[i]))
            s = a[k-1][x-c-1]
            print(int(s))
    else:
        k += 1
def main():
  n=int(input())
  a=sorted(map(int,input().split()))
  tf=[1]*n
  n=n-1
#r=[]
#print(n)
#print(a)
  #notdiv=True
  firstyn=0
  for i in range(n,-1,-1):
  #print(i)
  #notdiv=True
    if tf[i] ==0:
      continue
    for j in range(i):
    #print(a[j])
      if a[i]%a[j] == 0:
        tf[i]=0
      break
  if a[0] % a[1]==0:
    print(sum(tf)-1)
  else:
    print(sum(tf))
main()

### FIXED CODE ###

def main():
  n=int(input())
  a=sorted(map(int,input().split()))
  maxa=a[-1]+1
  tf=[False]*maxa
  r=0
  n-=1
  for i in range(n):
    a_i=a[i]
    if tf[a_i] ==False:
      for j in range(a_i,maxa,a_i):
        tf[j]=True
      if a_i < a[i+1]:
        #print(a_i)
        r+=1
  if tf[-1] ==False:
    r+=1
  print(r)
main()
N,K,R,S,P = map(int,input().split())
T = str(input())
i = 0
point = 0
for i in range(N):
  if T[i] == "r" and T[K] != "p":
    point += P
  elif T[i] == "s" and T[K] != "r":
    point += R
  elif T[i] == "p" and T[K] != "s":
    point += S
  else:
    break
  i += 1
print(point)

### FIXED CODE ###

N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = str(input())
i = 0
point = 0
L = [""]*N
for i in range(N):
  if T[i] == "r": 
    if i >= K and L[i-K] == "p":
      pass
    else:
      point += P
      L[i] = "p"
  elif T[i] == "s":
    if i >= K and L[i-K] == "r":
      pass
    else:
      point += R
      L[i] = "r"
  elif T[i] == "p":
    if i >= K and L[i-K] == "s":
      pass
    else:
      point += S
      L[i] = "s"
  else:
    break
print(point)
n,m,r=map(int,input().split())

ans=3000000000

def permu(ju,now,su,co):
    if now==0:
        global ans
        ans=min(ans,su)
        return
    else:
        for i in range(r):
            if ju[i]:
                ju[i]=False
                su+=dp[co][rute[i]-1]
                permu(ju,now-1,su,rute[i]-1)
                ju[i]=True
                su-=dp[co][rute[i]-1]
    return

rute=list(map(int,input().split()))
dp=[[30000000 for i in range(n)] for i in range(n)]
for i in range(n):
    dp[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    dp[a-1][b-1]=c
    dp[b-1][a-1]=c
for i in range(n):
    for j in range(n):
        for k in range(n):
            dp[j][k]=min(dp[j][i]+dp[i][k],dp[j][k])


ju=[True for i in range(r)]
for i in range(r):
    ju[i]=False
    permu(ju,r-1,0,rute[i]-1)
    ju[i]=True
print(ans)

### FIXED CODE ###

n=int(input())
if n%10==9 or n//10==9:
  print('Yes')
else:
  print('No')
a, b = map(int, input().split())

la = ''
lb = ''

for i in range(b):
    la += a
    lb += b

if a <= b:
    print(la)
else:
    print(lb)



### FIXED CODE ###

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

la = ''
lb = ''

for i in range(b):
    la += str(a)

for i in range(a):
    lb += str(b)

if a <= b:
    print(la)
else:
    print(lb)
n = input()
s0 = input()
for i in range(1, n):
    s = input()
    if s < s0:
        s0 = s
print s0

### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(raw_input())
print min(s)
arr = ['SAT','FRI','TUR','WED','TUE', 'MON','SUN']
s = input()
print(arr.index(s) + 1)

### FIXED CODE ###

arr = ['SAT','FRI','THU','WED','TUE', 'MON','SUN']
s = input()
print(arr.index(s) + 1)
import copy
import numpy as np
from math import factorial

def num_choice_2(N):
    if N > 1:
        return factorial(N) // (factorial(N - 2)* 2)
    else:
        return 0

N = int(input())
A = [int(x) for x in input().split()]

nums = np.zeros(N, dtype=int)
for a_i in A:
    nums[a_i - 1] += 1

for i in range(N):
    nums[A[i] - 1] -= 1
    ans = np.sum([num_choice_2(x) for x in tmp_nums])
    nums[A[i] - 1] += 1
    print(ans)

### FIXED CODE ###

def n_c_2(n):
    if n < 1:
        return 0
    else:
        return n * (n - 1) // 2

N = int(input())
A = [int(x) for x in input().split()]

n_balls = [0 for _ in A]
for a_i in A:
    n_balls[a_i - 1] += 1

n_combinations = [n_c_2(n) for n in n_balls]
total_combinations = sum(n_combinations)

for i, a_i in enumerate(A):
    diff = n_c_2(n_balls[a_i - 1]) - n_c_2(n_balls[a_i - 1] - 1)
    print(total_combinations - diff)
ex = ["+", "-", "*"]
while True:
    a, b, c, d = map(int, raw_input().split())
    if a == 0 and c == 0:
        break
    for i in ex:
        for j in ex:
            for k in ex:
                if eval( (((a k b) j c) i d)) == 10:
                    print "(((",a,k,b,")",j,c,")",i,d,")"
                    flag = 1
                    break
    if flag == 1:
        break
    for i in ex:
        for j in ex:
            for k in ex:
                if eval( ((a k b) i (c j d)) ) == 10: 
                    print "((",a,k,b,")",i,"(",c,j,d,"))"
                    flag = 1
                    break
    if flag = 1:
        break
    else:
        print 0

### FIXED CODE ###

op = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == "0" and c == "0":
        break
    n = [0,1,2,3]
    q = [a,b,c,d]
    flag = 0
    for ii in n:
        m = [0,1,2,3]
        m.remove(ii)
        for jj in m:
            l = [0,1,2,3]
            l.remove(ii);l.remove(jj)
            for kk in l:
                o = [0,1,2,3]
                o.remove(ii);o.remove(jj);o.remove(kk)
                for ll in o:
                    for i in op:
                        for j in op:
                            for k in op:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == 10:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == 10:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag == 0:
        print 0
import numpy as np
import scipy.sparse.csgraph as graph

N = int(input())
G = np.array([list(map(int, input().split())) for i in range(N)], dtype = 'int64')

G2 = graph.floyd_warshall(G, directed=False)

if np.any(G != G2):
    print(-1)
else:
    c = [2*10**9]*N
    d = np.diag(c)
    G += d
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            two = np.min(G[i]+G[j])
            if two != G[i,j]:
                ans += G[i,j]

print(ans)


### FIXED CODE ###

import numpy as np
import scipy.sparse.csgraph as graph

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

G2 = graph.floyd_warshall(G, directed=False)

if np.any(G != G2):
    print(-1)
    exit()
else:
    c = [2*10**9]*N
    d = np.diag(c)
    G += d
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            two = np.min(G[i]+G[j])
            if two != G[i,j]:
                ans += G[i,j]

print(ans)
def find(tab, a):
    if tab[0][a]==-1:
        return a
    tab[0][a] = find(tab, tab[0][a])
    return tab[0][a]

def union(tab, a, b):
    p1, p2 = find(tab, a), find(tab, b)
    if p1 != p2:
        tab[0][p1] = p2
        tab[1][p2] += tab[1][p1]

def size(tab, a):
    return tab[1][a]

N, M = [int(a) for a in input().split(" ")]
ABs = [[int(a) for a in input().split(" ")] for i in range(M)]
tab = [[-1]*N, [1]*N]
arr = []

for a, b in reversed(ABs):
    a, b = a-1, b-1
    pa, pb = find(tab, a), find(tab, b)
    na, nb = size(tab, pa), size(tab, pb)
    if pa!=pb:
        dn = ((na+nb)*(na+nb-1)//2)-(na*(na-1)//2)-(nb*(nb-1)//2)
        arr.append(dn)
        try:
            union(tab, a, b)
        except:
            pass
    else:
        arr.append(0)

acc = 0
for cp in reversed(arr):
    acc += cp
    print(acc)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def find(tab, a):
    if tab[0][a]==a:
        return a
    tab[0][a] = find(tab, tab[0][a])
    return tab[0][a]

def union(tab, a, b):
    p1, p2 = (find(tab, a), find(tab, b))
    if p1 != p2:
        tab[0][p1] = p2
        tab[1][p2] += tab[1][p1]

def size(tab, a):
    return tab[1][a]

N, M = [int(a) for a in input().split(" ")]
ABs = [[int(a) for a in input().split(" ")] for i in range(M)]
tab = [[i for i in range(N)], [1 for i in range(N)]]
arr = []

for a, b in reversed(ABs):
        a, b = (a-1, b-1)
        pa, pb = (find(tab, a), find(tab, b))
        na, nb = (size(tab, pa), size(tab, pb))
        if pa!=pb:
            dn = ((na+nb)*(na+nb-1)//2)-(na*(na-1)//2)-(nb*(nb-1)//2)
            arr.append(dn)
            union(tab, a, b)
        else:
            arr.append(0)

acc = 0
for cp in reversed(arr):
    acc += cp
    print(acc)
s,t = input().split()
a = 0
for i in range(len(t)):
    if s[i] == t[i]:
        a = a + 1
    else:
        a = a + 0
print(a)

### FIXED CODE ###

s,t = input(), input()
a = 0
for i in range(len(s)):
    if s[i]!=t[i]:
        a = a + 1
print(a)
from collections import Counter
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]
ct = Counter()
for i in range(len(P)):
  x1, y1 = P[i]
  for j in range(i+1, len(P)):
    x2, y2 = P[j]
    dx, dy = x2-x1, y2-y1
    if dx < 0:
      dx, dy = -dx, -dy
    ct[(dx, dy)] += 1

print(N - ct.most_common(1)[0][1])

### FIXED CODE ###

from collections import Counter
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]
P.sort()
if N == 1:
  print(1)
  exit()

ct = Counter()
for i in range(len(P)):
  x1, y1 = P[i]
  for j in range(i+1, len(P)):
    x2, y2 = P[j]
    dx, dy = x2-x1, y2-y1
    if dx < 0:
      dx, dy = -dx, -dy
    ct[(dx, dy)] += 1

print(N - ct.most_common(1)[0][1])
n = int(input())
a = map(int,input().split())
b =1

for i in range(n):
  b *= a[i]

if b >= 10**18:
  print(-1)
else:
  print(b)

### FIXED CODE ###

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

if 0 in a:
  b=0
for i in range(n):
  b *= a[i]
  if b>10**18:
    b=-1
    break
  else:
    continue
print(b)
import math
N, X, T = input()
S = math.ceil(N/X)
Ans = S * T
print(Ans)

### FIXED CODE ###

import math
N, X, T = map(int, input().split())
S = math.ceil(N/X)
Ans = S * T
print(Ans)
S = input()
for i in range(S):
  S[i] = "x"
print(S)

### FIXED CODE ###

S = str(input())
S = "x"*len(S)
print(S)
from bisect import *
n = input()
dp = [n+1]*(n+1)
dp[0] = -1
for i in xrange(n):
    a = input()
    idx = bisect(dp, a-1)
    dp[idx] = min(a, dp[idx])
print bisect(dp, n)-1

### FIXED CODE ###

from bisect import *
import sys

def solve(N, A):
    INF = 10**10

    dp = [INF]*(N+1)
    dp[0] = -1
    for a in A:
        idx = bisect(dp, a-1)
        dp[idx] = min(a, dp[idx])
    return max(i for i in range(N+1) if dp[i] < INF)

N, *A = map(int, sys.stdin.read().split())
sys.stdout.write("%d\n" % solve(N, A))
num =input()
lst = num.split()
curtain = lst(1) * 2
ans = lst(0) - curtain

if(ans <= 0):
 print("0")
else:
 print(ans)


### FIXED CODE ###

num =input()
lst = num.split()
curtain = int(lst[1]) * 2
ans = int(lst[0]) - curtain

if(ans <= 0):
 print("0")
else:
 print("{}".format(ans))
H = int(input())

g = int(H / 2)
ans = 0
if g == 0:
    print(1)
else:
    n = 0
    while True:
        if 2 ** (n + 1) < H:
            n += 1
        elif 2 ** (n + 1) >= H:
            n += 1
            break
    for i in range(n + 1):
        ans = ans + (2 ** i)
print(ans)

### FIXED CODE ###


H, A = map(int, input().split())

count = 0
while H > 0:
    H = H - A
    count += 1
print(count)
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

if (min_num == len(lst)):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst))


### FIXED CODE ###

A, B = map(int, input().split())
if (B % A == 0):
  print(A + B)
else:
  print(B - A)
K = int(input())
S = input()

if (len(S) <= K):
  print(S)
else:
  S = S[0:K] + "..."
  print(S)


### FIXED CODE ###

i = int(input())
s = i % 10
if s in [2, 4, 5, 7, 9]:
  print("hon")
elif s in [0, 1, 6, 8]:
  print("pon")
else:
  print("bon")
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i range(M):
  L[i],R[i]=map(int,input().split())

def prison(N,M,L,R):
    count=0
    for n in range(N):
        num_of_truth=0
        for l,r in zip(L,R):
            if l<=(n+1)<=r:
                num_of_truth+=1
        if num_of_truth==M:
            count+=1
    return count

print(prison(N,M,L,R))

### FIXED CODE ###

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

L=[0]*M
R=[0]*M

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

def prison(N,M,L,R):
  max_val=min(R)
  min_val=max(L)
  num=max_val-min_val+1
  if num<=0:
    num=0
  return(num)

print(prison(N,M,L,R))
N=input()
S=input()
K=input()
C=S[K-1]
S_=''
for c in S:
  if c == C:
    S_+=c
  else:
    S_+="*"
print(S_)

### FIXED CODE ###

N=int(input())
S=input()
K=int(input())
C=S[K-1]
S_=''
for c in S:
  if c == C:
    S_+=c
  else:
    S_+="*"
print(S_)
s = list(input())
t = list(input())

if len(t) > len(s):
    print('UNRESTORABLE')
    exit()

lis = []
flag = 0
for i in range(len(s)):
    if s[i] == t[0]:
        for j in range(i+1, i+len(t)-1):
            if s[j] == '?' or s[j] == t[j-i]:
                flag = 1
            else:
                flag = 0
                break
    
    if flag:
        lis.append(i)
        flag = 0

if len(lis) == 0:
    print('UNRESTORABLE')
    exit()

tmp = max(lis)
s[tmp:tmp+len(t)+1] = t

for k in range(len(s)):
    if s[k] == '?':
        s[k] = 'a'


print(''.join(s))

### FIXED CODE ###

s = input()
t = input()

if len(t) > len(s):
    print('UNRESTORABLE')
    exit()

s = s[::-1]
t = t[::-1]

for i in range(len(s) - len(t) + 1):
    j = 0
    while True:
        if j == len(t):
            ans = s[:i] + t + s[i+len(t):]
            print(ans[::-1].replace('?', 'a', len(ans)))
            exit()
        if t[j] == s[i+j] or s[i+j] == '?':
            j += 1
        else:
            break
print("UNRESTORABLE")
def main():
  import bisect
  import sys
  from itertools import accumulate
  input = sys.stdin.readline
  def hsnum(x):
    num = 0
    for i in a:
      y = x-i
      num += n-bisect.bisect_left(a,y)
    return num
  n,m = map(int, input().split())
  a = list(map(int, input().split()))
  a.sort()
  suma = [0]+list(accumulate(a))
  lx = 0
  rx = 2*10**5+2
  error = 0
  while lx+1 < rx:
    mx = (lx+rx)//2
    if hsnum(mx) < m:
      rx = mx
    elif hsnum(mx) > m:
      lx = mx + 1
    else:
      lx = mx
      break
  if hsnum(lx)>m:
    lx += 1
  error = hsnum(lx)-m
  ans = 0
  for i in a:
    rema = lx - i
    j = bisect.bisect_left(a,rema)
    ans += (n-j)*i-suma[j]
  ans += suma[n]*n
  print(ans-error*lx)
if __name__ == "__main__":
    main()

### FIXED CODE ###

s,t=input().split()
print(t+s)
[N, X, Y] = input().split()
N = int(N)
X = int(X)
Y = int(Y)
dist_list = []

for i in range(N):
    for j in range(i+1, N):
        a = j - i
        b = abs(i+1 - X) + abs(j+1 -Y) + 1
        if a > b:
            dist_list.append(b)
        else:
            dist_list.append(a)

for k in range(N-1):
    print(dist_list.count(k+1))



### FIXED CODE ###

S = input()

if S[2] == S[3] and S[4] == S[5]:
    print("Yes")
else:
    print("No")
chrs=string.ascii_lowercase
nx={c:d for c,d in zip(chrs,chrs[1:])}
print(nx(input())

### FIXED CODE ###

import string
chrs=string.ascii_lowercase
nx={c:d for c,d in zip(chrs,chrs[1:])}
print(nx[input()])
A_1 = int(input())
A_2 = int(input())
A_3 = int(input())

list = [A_1, A_2, A_3]
new_list = sorted(list)
print(new_list[2] - new_list[0])

### FIXED CODE ###

A_1, A_2, A_3 = (int(x) for x in input().split())
list = [A_1, A_2, A_3]
new_list = sorted(list)
print(new_list[2] - new_list[0])