human
Solve in Python:
# Task
 IONU Satellite Imaging, Inc. records and stores very large images using run length encoding. You are to write a program that reads a compressed image, finds the edges in the image, as described below, and outputs another compressed image of the detected edges.
 
 A simple edge detection algorithm sets an output pixel's value to be the maximum absolute value of the differences between it and all its surrounding pixels in the input image. Consider the input image below:

 ![](http://media.openjudge.cn/images/1009_1.jpg)

 The upper left pixel in the output image is the maximum of the values |15-15|,|15-100|, and |15-100|, which is 85. The pixel in the 4th row, 2nd column is computed as the maximum of |175-100|, |175-100|, |175-100|, |175-175|, |175-25|, |175-175|,|175-175|, and |175-25|, which is 150.
 
 Images contain 2 to 1,000,000,000 (10^9) pixels. All images are encoded using run length encoding (RLE). This is a sequence of pairs, containing pixel value (0-255) and run length (1-10^9). Input images have at most 1,000 of these pairs. Successive pairs have different pixel values. All lines in an image contain the same number of pixels.
  
 For the iamge as the example above, the RLE encoding string is `"7 15 4 100 15 25 2 175 2 25 5 175 2 25 5"`
 
 ```
 Each image starts with the width, in pixels(means the first number 7)
 This is followed by the RLE pairs(two number is a pair).
 7      ----> image width
 15 4   ----> a pair(color value + number of pixel)
 100 15       ...........ALL.......................
 25 2         ..........THESE......................
 175 2        ...........ARE.......................
 25 5         ..........PAIRS......................
 175 2        ...........LIKE......................
 25 5         ..........ABOVE......................
 ```
 
 Your task is to calculate the result by using the edge detection algorithm above. Returns a encoding string in the same format as the input string.
 
# Exaple

 `Please see examples in the example test block.`
 
# Input/Output

 -...
 Write me a Python code to calculate the result by using the edge detection algorithm above?
assistant
#Here is Python code to calculate the result by using the edge detection algorithm above.

def edge_detection(image):
    image = [int(v) for v in image.split(' ')]
    width = image[0]
    map,line,flat = [],[],[]
    rest,f = width,1
    current,result = ['',width],['']
    def apply(value):
        if current[0] == value:
            current[1] += 1
        else:
            result[0] += ' ' + str(current[0]) + ' ' + str(current[1])
            current[0] = value
            current[1] = 1
    def diff(R,C,r,c):
        r += R
        c += C
        return abs(flat[R][C] - flat[r][c]) if 0 <= r < len(flat) and 0 <= c < width else 0
    while f < len(image):
        line.append([image[f],min(rest,image[1 + f])])
        if image[1 + f] < rest:
            rest -= image[1 + f]
            f += 2
        else:
            image[1 + f] -= rest
            if image[1 + f] < 3 * width:
                if image[1 + f] < 1: f += 2
                map.append(line)
                line = []
                rest = width
            else:
                map.append(line)
                map.append([[image[f],width]])
                map.append([[image[f],width,image[1 + f] // width - 2]])
                map.append([[image[f],width]])
                line = []
                image[1 + f] %= width
                rest = width - image[1 + f]
                if image[1 + f]: line.append(image[f:2 + f])
                f += 2
    for v in map:
        t = f = 0
        line = []
        flat.append(line)
        for _ in range(width):
            line.append(v[f][0])
            t += 1
            if v[f][1] <= t: t,f = 0,1 + f
    for r,row in enumerate(map):
        if 2 < len(row[0]):
            apply(0)
            current[1] += width * row[0][2] - 1
        else:
            for f in range(width): apply(max(diff(r,f,-1,0),diff(r,f,-1,1),diff(r,f,0,1),diff(r,f,1,1),
                diff(r,f,1,0),diff(r,f,1,-1),diff(r,f,0,-1),diff(r,f,-1,-1)))
    apply(None)
    return result[0][2:]