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


 -...
from itertools import chain


def parse_ascii(image_ascii):
    """ Parses the input string

    Returns a 3-tuple:
        - :width: - the width in pixels of the image
        - :height: - the height in pixels of the image
        - List of pairs (pixel_value, run_length)
            run_length is the number of successive pixels with the same value when scanning
            the row, including the following rows

    Assumes with no check:
        :run_length: > 0 for all cases
        Successive pairs have different :pixel_value:
        The sum of all pixels is a multiple of :width:

    >>> parse_ascii("3 43 4 24 2")
    (3, 2, [(43, 4), (24, 2)])
    """
    values = [int(v) for v in image_ascii.split()]
    width = values[0]
    pixel_runs = list(zip(values[1::2], values[2::2]))
    height = sum(values[2::2]) // width
    return width, height, pixel_runs


def get_intervals(pixel_runs):
    """ Denominates the pixel runs with an absolute position

    Given the pairs (pixel_value, run_length), returns triplets (start, end, pixel_value)

    The pixel positions are numbered successively starting with the first row from left
    to right and then the following rows. :start: and :end: are given as such positions.
    :start: points to the first pixel of the run with :pixel_value:
    :end: points to the position after the the pixel ending the run

    >>> list(get_intervals([(34,4),(98,5),(12,40)]))
    [(0, 4, 34), (4, 9, 98), (9, 49, 12)]
    """
    pos = 0
    for (pixel_value, run_length) in pixel_runs:
        yield (pos, pos + run_length, pixel_value)
        pos += run_length


def get_shifted_intervals(intervals, offset, width, height):
    """ Shifts the intervals, and corrects for end of row

    Returns the intervals (start, end, pixel_value) with the variables :start: and :end:
    shifted :offset: positions.

    If :offset: is positive, fills the first positions with a new (0, :offset:, None) interval,
    and removes the intervals and interval parts correspoding to the last :offset:...