f | import sys | f | import sys |
| import ast | | import ast |
| | | |
n | class FloorDivTransformer(ast.NodeTransformer): | n | class X(ast.NodeTransformer): |
| | | |
t | def visit_BinOp(self, node): | t | def visit_BinOp(self, n): |
| self.generic_visit(node) | | self.generic_visit(n) |
| if isinstance(node.op, ast.FloorDiv): | | if isinstance(n.op, ast.FloorDiv): |
| return ast.copy_location(ast.Call(func=ast.Name(id='floor_di | | return ast.copy_location(ast.Call(func=ast.Name(id='y', ctx= |
| v', ctx=ast.Load()), args=[node.left, node.right], keywords=[]), node) | | ast.Load()), args=[n.left, n.right], keywords=[]), n) |
| return node | | return n |
| input_code = sys.stdin.read() | | i = sys.stdin.read() |
| tree = ast.parse(input_code) | | t = ast.parse(i) |
| transformer = FloorDivTransformer() | | x = X() |
| tree = transformer.visit(tree) | | t = x.visit(t) |
| ast.fix_missing_locations(tree) | | ast.fix_missing_locations(t) |
| floor_div_code = '\ndef floor_div(a, b):\n if isinstance(a, int):\n | | y_code = '\ndef y(a, b):\n if isinstance(a, int):\n return a / |
| return a // b\n elif isinstance(a, (list, tuple, str)):\n | | / b\n elif isinstance(a, (list, tuple, str)):\n return a[: len |
| return a[: len(a) // b]\n else:\n raise TypeError("Unsupport | | (a) // b]\n' |
| ed type for floor_div")\n' | | |
| floor_div_ast = ast.parse(floor_div_code) | | y_ast = ast.parse(y_code) |
| tree.body = floor_div_ast.body + tree.body | | t.body = y_ast.body + t.body |
| exec(compile(tree, filename='<ast>', mode='exec')) | | exec(compile(t, filename='<ast>', mode='exec')) |