broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(frames, exc, parents):
    def is_sub(t, target):
        while t is not None:
            if t == target:
                return True
            t = parents.get(t)
        return False
    unwound = 0
    for depth, frame in enumerate(reversed(frames)):
        if depth == 0:
            pc = frame['pc']
        else:
            pc = frame['ret'] - (5 if frame['via'] in ('invokeinterface', 'invokedynamic') else 3)
        for start, end, handler, catch in frame['table']:
            if start <= pc < end and (catch is None or is_sub(exc, catch)):
                return {'handler': handler, 'unwound': unwound, 'stack': frame['stack'] + [exc]}
        unwound += 1
    return {'handler': None, 'unwound': unwound, 'stack': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('range end is exclusive',
   ([{'pc': 20, 'stack': [1, 2], 'table': [[10, 20, 100, 'IOException'], [20, 30, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 10, 'stack': [1, 2], 'table': [[10, 15, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 17, 'stack': [1, 2], 'table': [[10, 30, 100, 'Exception'], [15, 20, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 11, 'stack': [1, 2], 'table': [[10, 19, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 11, 'stack': [1, 2], 'table': [[10, 19, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 12, 'stack': [1, 2], 'table': [[10, 19, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 12, 'stack': [1, 2], 'table': [[10, 19, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 23, 'stack': [1], 'table': [[20, 23, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [1, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 25, 'stack': [1], 'table': [[20, 25, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [1, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 13, 'stack': [], 'table': [[15, 19, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [1, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 30, 'stack': [2, 2], 'table': [[20, 30, 100, 'IOException'], [30, 40, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 20, 'stack': [2, 2], 'table': [[20, 25, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 27, 'stack': [2, 2], 'table': [[20, 40, 100, 'Exception'], [25, 30, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 21, 'stack': [2, 2], 'table': [[20, 29, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 21, 'stack': [2, 2], 'table': [[20, 29, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 22, 'stack': [2, 2], 'table': [[20, 29, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 22, 'stack': [2, 2], 'table': [[20, 29, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 33, 'stack': [1], 'table': [[30, 33, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [2, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 35, 'stack': [1], 'table': [[30, 35, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [2, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 23, 'stack': [], 'table': [[25, 29, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [2, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 40, 'stack': [3, 2], 'table': [[30, 40, 100, 'IOException'], [40, 50, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 30, 'stack': [3, 2], 'table': [[30, 35, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 37, 'stack': [3, 2], 'table': [[30, 50, 100, 'Exception'], [35, 40, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 31, 'stack': [3, 2], 'table': [[30, 39, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 31, 'stack': [3, 2], 'table': [[30, 39, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 32, 'stack': [3, 2], 'table': [[30, 39, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 32, 'stack': [3, 2], 'table': [[30, 39, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 43, 'stack': [1], 'table': [[40, 43, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [3, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 45, 'stack': [1], 'table': [[40, 45, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [3, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 33, 'stack': [], 'table': [[35, 39, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [3, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 50, 'stack': [4, 2], 'table': [[40, 50, 100, 'IOException'], [50, 60, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 40, 'stack': [4, 2], 'table': [[40, 45, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 47, 'stack': [4, 2], 'table': [[40, 60, 100, 'Exception'], [45, 50, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 41, 'stack': [4, 2], 'table': [[40, 49, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 41, 'stack': [4, 2], 'table': [[40, 49, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 42, 'stack': [4, 2], 'table': [[40, 49, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 42, 'stack': [4, 2], 'table': [[40, 49, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 53, 'stack': [1], 'table': [[50, 53, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [4, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 55, 'stack': [1], 'table': [[50, 55, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [4, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 43, 'stack': [], 'table': [[45, 49, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [4, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 60, 'stack': [5, 2], 'table': [[50, 60, 100, 'IOException'], [60, 70, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 50, 'stack': [5, 2], 'table': [[50, 55, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 57, 'stack': [5, 2], 'table': [[50, 70, 100, 'Exception'], [55, 60, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 51, 'stack': [5, 2], 'table': [[50, 59, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 51, 'stack': [5, 2], 'table': [[50, 59, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 52, 'stack': [5, 2], 'table': [[50, 59, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 52, 'stack': [5, 2], 'table': [[50, 59, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 63, 'stack': [1], 'table': [[60, 63, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [5, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 65, 'stack': [1], 'table': [[60, 65, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [5, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 53, 'stack': [], 'table': [[55, 59, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [5, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(frames, exc, parents):
    def is_sub(t, target):
        while t is not None:
            if t == target:
                return True
            t = parents.get(t)
        return False
    unwound = 0
    for depth, frame in enumerate(reversed(frames)):
        if depth == 0:
            pc = frame['pc']
        else:
            pc = frame['ret'] - (5 if frame['via'] in ('invokeinterface', 'invokedynamic') else 3)
        for start, end, handler, catch in frame['table']:
            if start <= pc < end and (catch is None or is_sub(exc, catch)):
                return {'handler': handler, 'unwound': unwound, 'stack': [exc] if unwound else frame['stack'] + [exc]}
        unwound += 1
    return {'handler': None, 'unwound': unwound, 'stack': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('range end is exclusive',
   ([{'pc': 20, 'stack': [1, 2], 'table': [[10, 20, 100, 'IOException'], [20, 30, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 10, 'stack': [1, 2], 'table': [[10, 15, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 17, 'stack': [1, 2], 'table': [[10, 30, 100, 'Exception'], [15, 20, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 11, 'stack': [1, 2], 'table': [[10, 19, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 11, 'stack': [1, 2], 'table': [[10, 19, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 12, 'stack': [1, 2], 'table': [[10, 19, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 12, 'stack': [1, 2], 'table': [[10, 19, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 23, 'stack': [1], 'table': [[20, 23, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [1, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 25, 'stack': [1], 'table': [[20, 25, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [1, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 13, 'stack': [], 'table': [[15, 19, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [1, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 30, 'stack': [2, 2], 'table': [[20, 30, 100, 'IOException'], [30, 40, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 20, 'stack': [2, 2], 'table': [[20, 25, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 27, 'stack': [2, 2], 'table': [[20, 40, 100, 'Exception'], [25, 30, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 21, 'stack': [2, 2], 'table': [[20, 29, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 21, 'stack': [2, 2], 'table': [[20, 29, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 22, 'stack': [2, 2], 'table': [[20, 29, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 22, 'stack': [2, 2], 'table': [[20, 29, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 33, 'stack': [1], 'table': [[30, 33, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [2, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 35, 'stack': [1], 'table': [[30, 35, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [2, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 23, 'stack': [], 'table': [[25, 29, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [2, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 40, 'stack': [3, 2], 'table': [[30, 40, 100, 'IOException'], [40, 50, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 30, 'stack': [3, 2], 'table': [[30, 35, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 37, 'stack': [3, 2], 'table': [[30, 50, 100, 'Exception'], [35, 40, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 31, 'stack': [3, 2], 'table': [[30, 39, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 31, 'stack': [3, 2], 'table': [[30, 39, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 32, 'stack': [3, 2], 'table': [[30, 39, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 32, 'stack': [3, 2], 'table': [[30, 39, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 43, 'stack': [1], 'table': [[40, 43, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [3, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 45, 'stack': [1], 'table': [[40, 45, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [3, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 33, 'stack': [], 'table': [[35, 39, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [3, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 50, 'stack': [4, 2], 'table': [[40, 50, 100, 'IOException'], [50, 60, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 40, 'stack': [4, 2], 'table': [[40, 45, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 47, 'stack': [4, 2], 'table': [[40, 60, 100, 'Exception'], [45, 50, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 41, 'stack': [4, 2], 'table': [[40, 49, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 41, 'stack': [4, 2], 'table': [[40, 49, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 42, 'stack': [4, 2], 'table': [[40, 49, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 42, 'stack': [4, 2], 'table': [[40, 49, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 53, 'stack': [1], 'table': [[50, 53, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [4, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 55, 'stack': [1], 'table': [[50, 55, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [4, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 43, 'stack': [], 'table': [[45, 49, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [4, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})],
 [('range end is exclusive',
   ([{'pc': 60, 'stack': [5, 2], 'table': [[50, 60, 100, 'IOException'], [60, 70, 200, 'IOException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 200, 'stack': ['IOException'], 'unwound': 0}),
  ('range start is inclusive',
   ([{'pc': 50, 'stack': [5, 2], 'table': [[50, 55, 300, 'Exception']]}],
    'ArithmeticException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 300, 'stack': ['ArithmeticException'], 'unwound': 0}),
  ('regression: first matching entry in table order wins',
   ([{'pc': 57, 'stack': [5, 2], 'table': [[50, 70, 100, 'Exception'], [55, 60, 200, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 100, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('subclass instance caught by superclass handler',
   ([{'pc': 51, 'stack': [5, 2], 'table': [[50, 59, 150, 'IOException']]}],
    'FileNotFoundException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 150, 'stack': ['FileNotFoundException'], 'unwound': 0}),
  ('superclass instance not caught by subclass handler',
   ([{'pc': 51, 'stack': [5, 2], 'table': [[50, 59, 150, 'FileNotFoundException']]}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('any-type entry catches errors',
   ([{'pc': 52, 'stack': [5, 2], 'table': [[50, 59, 400, None]]}],
    'StackOverflowError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 400, 'stack': ['StackOverflowError'], 'unwound': 0}),
  ('Exception handler does not catch Error',
   ([{'pc': 52, 'stack': [5, 2], 'table': [[50, 59, 410, 'Exception']]}],
    'AssertionError',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 1}),
  ('caller frame after 3-byte invoke',
   ([{'ret': 63, 'stack': [1], 'table': [[60, 63, 500, 'Exception']], 'via': 'invokestatic'},
     {'pc': 3, 'stack': [5, 2], 'table': []}],
    'RuntimeException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 500, 'stack': ['RuntimeException'], 'unwound': 1}),
  ('caller frame after 5-byte invokeinterface',
   ([{'ret': 65, 'stack': [1], 'table': [[60, 65, 600, None]], 'via': 'invokeinterface'},
     {'pc': 3, 'stack': [5, 2], 'table': []}],
    'IOException',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': 600, 'stack': ['IOException'], 'unwound': 1}),
  ('control: uncaught through two frames',
   ([{'ret': 53, 'stack': [], 'table': [[55, 59, 1, None]], 'via': 'invokevirtual'},
     {'pc': 4, 'stack': [5, 2], 'table': [[0, 3, 2, None]]}],
    'Error',
    {'ArithmeticException': 'RuntimeException',
     'AssertionError': 'Error',
     'Error': 'Throwable',
     'Exception': 'Throwable',
     'FileNotFoundException': 'IOException',
     'IOException': 'Exception',
     'RuntimeException': 'Exception',
     'StackOverflowError': 'VirtualMachineError',
     'VirtualMachineError': 'Error'}),
   {'handler': None, 'stack': [], 'unwound': 2})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Handlers see leftover operands beneath the exception and stack-depth verification assumptions break.

frames are ordered outermost first; the innermost frame carries the faulting pc, every caller carries the return address "ret" and the invoke opcode "via" (invokeinterface and invokedynamic are 5 bytes, other invokes 3), and the lookup pc is the invoke's own address. Each table entry [start, end, handler, type] covers start <= pc < end; entries are tried in table order; type None catches anything, otherwise the thrown type or any ancestor (parents map) must equal it. Return handler, number of frames unwound and the operand stack at the handler (cleared, then the exception pushed).

split: open-access


prompt:
Lines that move backwards (loops, decorators) jump forward by hundreds.

Delta-encoded line table: each pair [addr_delta, line_delta] advances the bytecode address by addr_delta two-byte code units and the line by line_delta, a byte to be read as signed (values >= 128 mean value - 256). A decoded delta of -128 marks "no line" (None) at that address and does not move the running line. Offset 0 implicitly maps to first. A byte offset q maps to the last entry whose address is <= q (later entries at the same address win). Return the line for each query.

split: open-access


prompt:
Instructions that stay on the same line report no line, while true markers subtract 128.

Delta-encoded line table: each pair [addr_delta, line_delta] advances the bytecode address by addr_delta two-byte code units and the line by line_delta, a byte to be read as signed (values >= 128 mean value - 256). A decoded delta of -128 marks "no line" (None) at that address and does not move the running line. Offset 0 implicitly maps to first. A byte offset q maps to the last entry whose address is <= q (later entries at the same address win). Return the line for each query.

split: open-access


prompt:
The first instruction of each line is attributed to the line before it; offset 0 wraps to the last line.

Delta-encoded line table: each pair [addr_delta, line_delta] advances the bytecode address by addr_delta two-byte code units and the line by line_delta, a byte to be read as signed (values >= 128 mean value - 256). A decoded delta of -128 marks "no line" (None) at that address and does not move the running line. Offset 0 implicitly maps to first. A byte offset q maps to the last entry whose address is <= q (later entries at the same address win). Return the line for each query.

split: open-access


prompt:
Every line after an artificial no-line instruction is 128 lower than it should be.

Delta-encoded line table: each pair [addr_delta, line_delta] advances the bytecode address by addr_delta two-byte code units and the line by line_delta, a byte to be read as signed (values >= 128 mean value - 256). A decoded delta of -128 marks "no line" (None) at that address and does not move the running line. Offset 0 implicitly maps to first. A byte offset q maps to the last entry whose address is <= q (later entries at the same address win). Return the line for each query.

split: open-access


prompt:
Line boundaries land at half the correct byte offsets.

Delta-encoded line table: each pair [addr_delta, line_delta] advances the bytecode address by addr_delta two-byte code units and the line by line_delta, a byte to be read as signed (values >= 128 mean value - 256). A decoded delta of -128 marks "no line" (None) at that address and does not move the running line. Offset 0 implicitly maps to first. A byte offset q maps to the last entry whose address is <= q (later entries at the same address win). Return the line for each query.

split: open-access


prompt:
Instructions before the first table entry report the last line of the function.

Delta-encoded line table: each pair [addr_delta, line_delta] advances the bytecode address by addr_delta two-byte code units and the line by line_delta, a byte to be read as signed (values >= 128 mean value - 256). A decoded delta of -128 marks "no line" (None) at that address and does not move the running line. Offset 0 implicitly maps to first. A byte offset q maps to the last entry whose address is <= q (later entries at the same address win). Return the line for each query.

split: open-access