import numpy as np

arr = np.array([2, 1, 3, 1, 0, 2, 1, 3, 1])

result = ... # put solution in this variable

def g(arr):
    l = []
    for i in range(2 * (len(arr) // 5) + (len(arr) % 5) // 3 + 1):
        l.append(0)
    for i in range(len(arr)):
        idx = 2 * (i // 5) + (i % 5) // 3
        if i % 5 < 3:
            l[idx] += arr[i]
        elif i % 5 == 3:
            l[idx] = arr[i]
        else:
            l[idx] = (l[idx] + arr[i]) / 2
    return np.array(l)

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        l = []
        for i in range(2 * (len(arr) // 5) + (len(arr) % 5) // 3 + 1):
            l.append(0)
        for i in range(len(arr)):
            idx = 2 * (i // 5) + (i % 5) // 3
            if i % 5 < 3:
                l[idx] += arr[i]
            elif i % 5 == 3:
                l[idx] = arr[i]
            else:
                l[idx] = (l[idx] + arr[i]) / 2
        return np.array(l)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([2, 1, 3, 1, 0, 2, 1, 3, 1])
        if test_case_id == 2:
            arr = np.array([1, 9, 2, 6, 0, 8, 1, 7, 1])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame({'col1':[2, 1, 3, 1, 0, 2, 1, 3, 1]})

result = ... # put solution in this variable

def g(df):
    l = []
    for i in range(2*(len(df) // 5) + (len(df) % 5) // 3 + 1):
        l.append(0)
    for i in range(len(df)):
        idx = 2*(i // 5) + (i % 5) // 3
        if i % 5 < 3:
            l[idx] += df['col1'].iloc[i]
        elif i % 5 == 3:
            l[idx] = df['col1'].iloc[i]
        else:
            l[idx] = (l[idx] + df['col1'].iloc[i]) / 2
    return pd.DataFrame({'col1': l})

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        l = []
        for i in range(2 * (len(df) // 5) + (len(df) % 5) // 3 + 1):
            l.append(0)
        for i in range(len(df)):
            idx = 2 * (i // 5) + (i % 5) // 3
            if i % 5 < 3:
                l[idx] += df["col1"].iloc[i]
            elif i % 5 == 3:
                l[idx] = df["col1"].iloc[i]
            else:
                l[idx] = (l[idx] + df["col1"].iloc[i]) / 2
        return pd.DataFrame({"col1": l})

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"col1": [2, 1, 3, 1, 0, 2, 1, 3, 1]})
        if test_case_id == 2:
            df = pd.DataFrame({"col1": [1, 9, 2, 6, 0, 8, 1, 7, 1]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(arr):
    l = []
    for i in range(2 * (len(arr) // 5) + (len(arr) % 5) // 3 + 1):
        l.append(0)
    for i in reversed(range(len(arr))):
        idx = 2 * ((len(arr) - 1 - i) // 5) + ((len(arr) - 1 - i) % 5) // 3
        if (len(arr) - 1 - i) % 5 < 3:
            l[idx] += arr[i]
        elif (len(arr) - 1 - i) % 5 == 3:
            l[idx] = arr[i]
        else:
            l[idx] = (l[idx] + arr[i]) / 2
    return np.array(l)

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        l = []
        for i in range(2 * (len(arr) // 5) + (len(arr) % 5) // 3 + 1):
            l.append(0)
        for i in reversed(range(len(arr))):
            idx = 2 * ((len(arr) - 1 - i) // 5) + ((len(arr) - 1 - i) % 5) // 3
            if (len(arr) - 1 - i) % 5 < 3:
                l[idx] += arr[i]
            elif (len(arr) - 1 - i) % 5 == 3:
                l[idx] = arr[i]
            else:
                l[idx] = (l[idx] + arr[i]) / 2
        return np.array(l)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([2, 1, 3, 1, 0, 2, 1, 3, 1])
        if test_case_id == 2:
            arr = np.array([1, 9, 2, 6, 0, 8, 1, 7, 1])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    l = []
    for i in range(2*(len(df) // 5) + (len(df) % 5) // 3 + 1):
        l.append(0)
    for i in reversed(range(len(df))):
        idx = 2*((len(df)-1-i) // 5) + ((len(df)-1-i) % 5) // 3
        if (len(df)-1-i) % 5 < 3:
            l[idx] += df['col1'].iloc[i]
        elif (len(df)-1-i) % 5 == 3:
            l[idx] = df['col1'].iloc[i]
        else:
            l[idx] = (l[idx] + df['col1'].iloc[i]) / 2
    return pd.DataFrame({'col1': l})

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        l = []
        for i in range(2 * (len(df) // 5) + (len(df) % 5) // 3 + 1):
            l.append(0)
        for i in reversed(range(len(df))):
            idx = 2 * ((len(df) - 1 - i) // 5) + ((len(df) - 1 - i) % 5) // 3
            if (len(df) - 1 - i) % 5 < 3:
                l[idx] += df["col1"].iloc[i]
            elif (len(df) - 1 - i) % 5 == 3:
                l[idx] = df["col1"].iloc[i]
            else:
                l[idx] = (l[idx] + df["col1"].iloc[i]) / 2
        return pd.DataFrame({"col1": l})

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"col1": [2, 1, 3, 1, 0, 2, 1, 3, 1]})
        if test_case_id == 2:
            df = pd.DataFrame({"col1": [1, 9, 2, 6, 0, 8, 1, 7, 1]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

index = range(14)
data = [1, 0, 0, 2, 0, 4, 6, 8, 0, 0, 0, 0, 2, 1]
arr = np.array(data)

arr = ... # put solution in this variable

def g(arr):
    mask = arr == 0
    idx = np.where(~mask, np.arange(len(arr)), 0)
    np.maximum.accumulate(idx, out=idx)
    arr[mask] = arr[idx[mask]]
    return arr

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        mask = arr == 0
        idx = np.where(~mask, np.arange(len(arr)), 0)
        np.maximum.accumulate(idx, out=idx)
        arr[mask] = arr[idx[mask]]
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = [1, 0, 0, 2, 0, 4, 6, 8, 0, 0, 0, 0, 2, 1]
            arr = np.array(data)
        if test_case_id == 2:
            data = [1, 0, 0, 9, 0, 2, 6, 8, 0, 0, 0, 0, 1, 7]
            arr = np.array(data)
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

index = range(14)
data = [1, 0, 0, 2, 0, 4, 6, 8, 0, 0, 0, 0, 2, 1]
df = pd.DataFrame(data=data, index=index, columns=['A'])

import pandas as pd

index = range(14)
data = [1, 0, 0, 2, 0, 4, 6, 8, 0, 0, 0, 0, 2, 1]
df = pd.DataFrame(data=data, index=index, columns = ['A'])

df = ... # put solution in this variable

def g(df):
    df['A'].replace(to_replace=0, method='bfill', inplace=True)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["A"].replace(to_replace=0, method="bfill", inplace=True)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            index = range(14)
            data = [1, 0, 0, 2, 0, 4, 6, 8, 0, 0, 0, 0, 2, 1]
            df = pd.DataFrame(data=data, index=index, columns=["A"])
        if test_case_id == 2:
            index = range(14)
            data = [1, 0, 0, 9, 0, 2, 6, 8, 0, 0, 0, 0, 1, 7]
            df = pd.DataFrame(data=data, index=index, columns=["A"])
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([['year 7'], ['day2'], ['week 4'], ['month 8']])

arr = ... # put solution in this variable

def g(arr):
    time = np.array([x[0].strip('0123456789 ') for x in arr])
    number = np.array([x[0].strip('abcdefghijklmnopqrstuvwxyz ') for x in arr])
    time_days = np.array([365 if t == 'year' else 30 if t == 'month' else 7 if t == 'week' else 1 for t in time])
    return np.column_stack((arr, time, number, time_days))

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        time = np.array([x[0].strip('0123456789 ') for x in arr])
        number = np.array([x[0].strip('abcdefghijklmnopqrstuvwxyz ') for x in arr])
        time_days = np.array([365 if t == 'year' else 30 if t == 'month' else 7 if t == 'week' else 1 for t in time])
        return np.column_stack((arr, time, number, time_days))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([['year 7'], ['day2'], ['week 4'], ['month 8']])
        if test_case_id == 2:
            arr = np.array([['year 2'], ['day6'], ['week 8'], ['month 7']])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame({'duration': ['year 7', 'day2', 'week 4', 'month 8']},
                  index=list(range(1,5)))

df = ... # put solution in this variable

def g(df):
    df[['time', 'number']] = df.duration.str.extract(r'\s*(.*)(\d+)', expand=True)
    for i in df.index:
        df.loc[i, 'time'] = df.loc[i, 'time'].strip()
    df['time_days'] = df['time'].replace(['year', 'month', 'week', 'day'], [365, 30, 7, 1], regex=True)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df[["time", "number"]] = df.duration.str.extract(r"\s*(.*)(\d+)", expand=True)
        for i in df.index:
            df.loc[i, "time"] = df.loc[i, "time"].strip()
        df["time_days"] = df["time"].replace(
            ["year", "month", "week", "day"], [365, 30, 7, 1], regex=True
        )
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"duration": ["year 7", "day2", "week 4", "month 8"]},
                index=list(range(1, 5)),
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {"duration": ["year 2", "day6", "week 8", "month 7"]},
                index=list(range(1, 5)),
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(df1, df2, columns_check_list):
    mask = np.any(df1[:, columns_check_list] != df2[:, columns_check_list], axis=1)
    return mask

result = g(df1, df2, columns_check_list)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df1, df2, columns_check_list = data
        mask = np.any(df1[:, columns_check_list] != df2[:, columns_check_list], axis=1)
        return mask

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df1 = np.array([
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
            ])
            df2 = np.array([
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
            ])
            columns_check_list = [0, 1, 2, 3, 4, 5]
        return df1, df2, columns_check_list

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
df1, df2, columns_check_list = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df1, df2, columns_check_list):
    mask= (df1[columns_check_list] != df2[columns_check_list]).any(axis=1).values
    return mask

result = g(df1, df2, columns_check_list)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df1, df2, columns_check_list = data
        mask = (df1[columns_check_list] != df2[columns_check_list]).any(axis=1).values
        return mask

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df1 = pd.DataFrame(
                {
                    "A": [1, 1, 1],
                    "B": [2, 2, 2],
                    "C": [3, 3, 3],
                    "D": [4, 4, 4],
                    "E": [5, 5, 5],
                    "F": [6, 6, 6],
                    "Postset": ["yes", "no", "yes"],
                }
            )
            df2 = pd.DataFrame(
                {
                    "A": [1, 1, 1],
                    "B": [2, 2, 2],
                    "C": [3, 3, 3],
                    "D": [4, 4, 4],
                    "E": [5, 5, 5],
                    "F": [6, 4, 6],
                    "Preset": ["yes", "yes", "yes"],
                }
            )
            columns_check_list = ["A", "B", "C", "D", "E", "F"]
        return df1, df2, columns_check_list

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert (result == ans).all()
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df1, df2, columns_check_list = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(arr1, arr2, columns_check_list):
    mask = np.any(arr1[:, columns_check_list] == arr2[:, columns_check_list], axis=1)
    return mask

result = g(arr1, arr2, columns_check_list)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        arr1, arr2, columns_check_list = data
        mask = np.any(arr1[:, columns_check_list] == arr2[:, columns_check_list], axis=1)
        return mask

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr1 = np.array([
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
            ])
            arr2 = np.array([
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
                [1, 2, 3, 4, 5, 6],
            ])
            columns_check_list = [0, 1, 2, 3, 4, 5]
        return arr1, arr2, columns_check_list

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert (result == ans).all()
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr1, arr2, columns_check_list = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df1, df2, columns_check_list):
    mask= (df1[columns_check_list] == df2[columns_check_list]).any(axis=1).values
    return mask

result = g(df1, df2, columns_check_list)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df1, df2, columns_check_list = data
        mask = (df1[columns_check_list] == df2[columns_check_list]).any(axis=1).values
        return mask

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df1 = pd.DataFrame(
                {
                    "A": [1, 1, 1],
                    "B": [2, 2, 2],
                    "C": [3, 3, 3],
                    "D": [4, 4, 4],
                    "E": [5, 5, 5],
                    "F": [6, 6, 6],
                    "Postset": ["yes", "no", "yes"],
                }
            )
            df2 = pd.DataFrame(
                {
                    "A": [1, 1, 1],
                    "B": [2, 2, 2],
                    "C": [3, 3, 3],
                    "D": [4, 4, 4],
                    "E": [5, 5, 5],
                    "F": [6, 4, 6],
                    "Preset": ["yes", "yes", "yes"],
                }
            )
            columns_check_list = ["A", "B", "C", "D", "E", "F"]
        return df1, df2, columns_check_list

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert (result == ans).all()
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df1, df2, columns_check_list = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def reshape_data(data):
    header = data[0, :]
    data = data[1:, :]
    years = header[2:][::-1]
    countries = np.unique(data[:, 0])
    variables = np.unique(data[:, 1])
    reshaped = []
    for country in countries:
        for year in years:
            row = [country, year]
            for var in variables:
                value = data[(data[:, 0] == country) & (data[:, 1] == var), header == year]
                row.append(value[0][0])
            reshaped.append(row)
    return np.array(reshaped)

reshaped_data = reshape_data(data)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        header = data[0, :]
        data = data[1:, :]
        years = header[2:][::-1]
        countries = np.unique(data[:, 0])
        variables = np.unique(data[:, 1])
        reshaped = []
        for country in countries:
            for year in years:
                row = [country, year]
                for var in variables:
                    value = data[(data[:, 0] == country) & (data[:, 1] == var), header == year]
                    row.append(value[0][0])
                reshaped.append(row)
        return np.array(reshaped)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                ['Country', 'Variable', '2000', '2001', '2002', '2003', '2004', '2005'],
                ['Argentina', 'var1', 12, 15, 18, 17, 23, 29],
                ['Argentina', 'var2', 1, 3, 2, 5, 7, 5],
                ['Brazil', 'var1', 20, 23, 25, 29, 31, 32],
                ['Brazil', 'var2', 0, 1, 2, 2, 3, 3]
            ])
        if test_case_id == 2:
            data = np.array([
                ['Country', 'Variable', '2000', '2001', '2002', '2003', '2004', '2005'],
                ['Argentina', 'var1', 12, 15, 18, 17, 23, 29],
                ['Argentina', 'var2', 1, 1, 4, 5, 1, 4],
                ['Brazil', 'var1', 20, 23, 25, 29, 31, 32],
                ['Brazil', 'var2', 0, 1, 2, 2, 3, 3]
            ])
        return data

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data = test_input
[insert]
result = reshaped_data
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    cols = list(df)[:2]+list(df)[-1:1:-1]
    df = df.loc[:, cols]
    return df.set_index(['Country', 'Variable']).rename_axis(['year'], axis=1).stack().unstack('Variable').reset_index()

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        cols = list(df)[:2] + list(df)[-1:1:-1]
        df = df.loc[:, cols]
        return (
            df.set_index(["Country", "Variable"])
            .rename_axis(["year"], axis=1)
            .stack()
            .unstack("Variable")
            .reset_index()
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Country": ["Argentina", "Argentina", "Brazil", "Brazil"],
                    "Variable": ["var1", "var2", "var1", "var2"],
                    "2000": [12, 1, 20, 0],
                    "2001": [15, 3, 23, 1],
                    "2002": [18, 2, 25, 2],
                    "2003": [17, 5, 29, 2],
                    "2004": [23, 7, 31, 3],
                    "2005": [29, 5, 32, 3],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Country": ["Argentina", "Argentina", "Brazil", "Brazil"],
                    "Variable": ["var1", "var2", "var1", "var2"],
                    "2000": [12, 1, 20, 0],
                    "2001": [15, 1, 23, 1],
                    "2002": [18, 4, 25, 2],
                    "2003": [17, 5, 29, 2],
                    "2004": [23, 1, 31, 3],
                    "2005": [29, 4, 32, 3],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(names, details, values):
    mask = np.all(np.abs(values) < 1, axis=1)
    return names[mask], details[mask], values[mask]

filtered_names, filtered_details, filtered_values = g(names, details, values)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(names, details, values):
        mask = np.all(np.abs(values) < 1, axis=1)
        return names[mask], details[mask], values[mask]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            names = np.array(['AA', 'BB', 'CC', 'DD', 'EE', 'FF', 'GG'])
            details = np.array(['X1', 'Y1', 'Z1', 'L1', 'M1', 'N1', 'K1'])
            values = np.array([
                [1.2, 0.5, -1.3],
                [0.76, -0.7, 0.8],
                [0.7, -1.3, 2.5],
                [0.9, -0.5, 0.4],
                [1.3, 1.8, -1.3],
                [0.7, -0.8, 0.9],
                [-2.4, -1.9, 2.1]
            ])
        elif test_case_id == 2:
            names = np.array(['AA', 'BB', 'CC', 'DD', 'EE', 'FF', 'GG'])
            details = np.array(['X1', 'Y1', 'Z1', 'L1', 'M1', 'N1', 'K1'])
            values = np.array([
                [1.2, 0.5, -1.3, 1, -1.9],
                [0.76, -0.7, 0.8, 1, 2.6],
                [0.7, -1.3, 2.5, 4, 0.8],
                [0.9, -0.5, 0.4, -5, 1.7],
                [1.3, 1.8, -1.3, -1, -1.3],
                [0.7, -0.8, 0.9, -4, 0.9],
                [-2.4, -1.9, 2.1, 2.1, 2.1]
            ])
        return names, details, values

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(*copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result[0], ans[0])
        np.testing.assert_array_equal(result[1], ans[1])
        np.testing.assert_array_equal(result[2], ans[2])
        return 1
    except:
        return 0

exec_context = r'''
import numpy as np
names, details, values = test_input
[insert]
result = (filtered_names, filtered_details, filtered_values)
'''

def test_execution(solution: str):
    code = exec_context.replace('[insert]', solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {'test_input': test_input}
        exec(code, test_env)
        assert exec_test(test_env['result'], expected_result)

def g(df):
    mask = (df.filter(like='Value').abs() < 1).all(axis=1)
    return df[mask]

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        mask = (df.filter(like="Value").abs() < 1).all(axis=1)
        return df[mask]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "A_Name": ["AA", "BB", "CC", "DD", "EE", "FF", "GG"],
                    "B_Detail": ["X1", "Y1", "Z1", "L1", "M1", "N1", "K1"],
                    "Value_B": [1.2, 0.76, 0.7, 0.9, 1.3, 0.7, -2.4],
                    "Value_C": [0.5, -0.7, -1.3, -0.5, 1.8, -0.8, -1.9],
                    "Value_D": [-1.3, 0.8, 2.5, 0.4, -1.3, 0.9, 2.1],
                }
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                {
                    "A_Name": ["AA", "BB", "CC", "DD", "EE", "FF", "GG"],
                    "B_Detail": ["X1", "Y1", "Z1", "L1", "M1", "N1", "K1"],
                    "Value_B": [1.2, 0.76, 0.7, 0.9, 1.3, 0.7, -2.4],
                    "Value_C": [0.5, -0.7, -1.3, -0.5, 1.8, -0.8, -1.9],
                    "Value_D": [-1.3, 0.8, 2.5, 0.4, -1.3, 0.9, 2.1],
                    "Value_E": [1, 1, 4, -5, -1, -4, 2.1],
                    "Value_F": [-1.9, 2.6, 0.8, 1.7, -1.3, 0.9, 2.1],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def filter_rows(data, value_indices):
    values = data[:, value_indices].astype(float)
    mask = np.any(np.abs(values) > 1, axis=1)
    return data[mask]

filtered_data = filter_rows(data, value_indices)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data, value_indices):
        values = data[:, value_indices].astype(float)
        mask = np.any(np.abs(values) > 1, axis=1)
        return data[mask]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                ['AA', 'X1', 1.2, 0.5, -1.3],
                ['BB', 'Y1', 0.76, -0.7, 0.8],
                ['CC', 'Z1', 0.7, -1.3, 2.5],
                ['DD', 'L1', 0.9, -0.5, 0.4],
                ['EE', 'M1', 1.3, 1.8, -1.3],
                ['FF', 'N1', 0.7, -0.8, 0.9],
                ['GG', 'K1', -2.4, -1.9, 2.1]
            ])
            value_indices = [2, 3, 4]
        elif test_case_id == 2:
            data = np.array([
                ['AA', 'X1', 1.2, 0.5, -1.3, 1, -1.9],
                ['BB', 'Y1', 0.76, -0.7, 0.8, 1, 2.6],
                ['CC', 'Z1', 0.7, -1.3, 2.5, 4, 0.8],
                ['DD', 'L1', 0.9, -0.5, 0.4, -5, 1.7],
                ['EE', 'M1', 1.3, 1.8, -1.3, -1, -1.3],
                ['FF', 'N1', 0.7, -0.8, 0.9, -4, 0.9],
                ['GG', 'K1', -2.4, -1.9, 2.1, 2.1, 2.1]
            ])
            value_indices = [2, 3, 4, 5, 6]
        return data, value_indices

    test_input, value_indices = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input), value_indices)
    return test_input, value_indices, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data, value_indices = test_input
[insert]
result = filtered_data
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, value_indices, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": (test_input, value_indices)}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    mask = (df.filter(like='Value').abs() > 1).any(axis=1)
    return df[mask]

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        mask = (df.filter(like="Value").abs() > 1).any(axis=1)
        return df[mask]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "A_Name": ["AA", "BB", "CC", "DD", "EE", "FF", "GG"],
                    "B_Detail": ["X1", "Y1", "Z1", "L1", "M1", "N1", "K1"],
                    "Value_B": [1.2, 0.76, 0.7, 0.9, 1.3, 0.7, -2.4],
                    "Value_C": [0.5, -0.7, -1.3, -0.5, 1.8, -0.8, -1.9],
                    "Value_D": [-1.3, 0.8, 2.5, 0.4, -1.3, 0.9, 2.1],
                }
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                {
                    "A_Name": ["AA", "BB", "CC", "DD", "EE", "FF", "GG"],
                    "B_Detail": ["X1", "Y1", "Z1", "L1", "M1", "N1", "K1"],
                    "Value_B": [1.2, 0.76, 0.7, 0.9, 1.3, 0.7, -2.4],
                    "Value_C": [0.5, -0.7, -1.3, -0.5, 1.8, -0.8, -1.9],
                    "Value_D": [-1.3, 0.8, 2.5, 0.4, -1.3, 0.9, 2.1],
                    "Value_E": [1, 1, 4, -5, -1, -4, 2.1],
                    "Value_F": [-1.9, 2.6, 0.8, 1.7, -1.3, 0.9, 2.1],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([['1 & 1', 'BB', 'CC', 'DD', '1 & 0'], range(5), ['0 & 0'] * 5], dtype=object)

arr = ... # put solution in this variable

def g(arr):
    for i in range(arr.shape[0]):
        for j in range(arr.shape[1]):
            if isinstance(arr[i, j], str):
                if '&' in arr[i, j]:
                    arr[i, j] = arr[i, j].replace('&', '&')
                    arr[i, j] = arr[i, j] + ' = ' + str(eval(arr[i, j]))
    return arr

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        for i in range(arr.shape[0]):
            for j in range(arr.shape[1]):
                if isinstance(arr[i, j], str):
                    if '&' in arr[i, j]:
                        arr[i, j] = arr[i, j].replace('&', '&')
                        arr[i, j] = arr[i, j] + ' = ' + str(eval(arr[i, j]))
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                ['1 & 1', 'BB', 'CC', 'DD', '1 & 0'],
                range(5),
                ['0 & 0'] * 5
            ], dtype=object)
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

df = pd.DataFrame({'Title': ['1 & 0', 'A & B']})

import pandas as pd

df = pd.DataFrame({'A': ['1 & 1', 'BB', 'CC', 'DD', '1 & 0'], 'B': range(5), 'C': ['0 & 0'] * 5})

df = ... # put solution in this variable

def g(df):
    for i in df.index:
        for col in list(df):
            if type(df.loc[i, col]) == str:
                if '&' in df.loc[i, col]:
                    df.loc[i, col] = df.loc[i, col].replace('&', '&')
                    df.loc[i, col] = df.loc[i, col]+' = '+str(eval(df.loc[i, col]))
    df.replace('&', '&', regex=True)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        for i in df.index:
            for col in list(df):
                if type(df.loc[i, col]) == str:
                    if "&" in df.loc[i, col]:
                        df.loc[i, col] = df.loc[i, col].replace("&", "&")
                        df.loc[i, col] = (
                            df.loc[i, col] + " = " + str(eval(df.loc[i, col]))
                        )
        df.replace("&", "&", regex=True)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "A": ["1 & 1", "BB", "CC", "DD", "1 & 0"],
                    "B": range(5),
                    "C": ["0 & 0"] * 5,
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


name_array = np.array(['Jack Fine', 'Kim Q. Danger', 'Jane Smith', 'Juan de la Cruz'])

import numpy as np

name_array = np.array(['Jack Fine', 'Kim Q. Danger', 'Jane Smith', 'Zhongli'])

result_array = ... # put solution in this variable

def split_names(arr):
    first_names = []
    last_names = []
    for name in arr:
        parts = name.split()
        if len(parts) == 2:
            first_names.append(parts[0])
            last_names.append(parts[1])
        else:
            first_names.append(name)
            last_names.append(None)
    return np.array([first_names, last_names]).T

result_array = split_names(name_array)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        first_names = []
        last_names = []
        for name in data:
            parts = name.split()
            if len(parts) == 2:
                first_names.append(parts[0])
                last_names.append(parts[1])
            else:
                first_names.append(name)
                last_names.append(None)
        return np.array([first_names, last_names]).T

    def define_test_input(test_case_id):
        if test_case_id == 1:
            return np.array(['Jack Fine', 'Kim Q. Danger', 'Jane Smith', 'Zhongli'])

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
name_array = test_input
[insert]
result = result_array
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

name_df = pd.DataFrame({'name':['Jack Fine','Kim Q. Danger','Jane Smith', 'Juan de la Cruz']})

import pandas as pd

df = pd.DataFrame({'name':['Jack Fine','Kim Q. Danger','Jane Smith', 'Zhongli']})

df = ... # put solution in this variable

def g(df):
    df.loc[df['name'].str.split().str.len() == 2, 'last_name'] = df['name'].str.split().str[-1]
    df.loc[df['name'].str.split().str.len() == 2, 'name'] = df['name'].str.split().str[0]
    df.rename(columns={'name': 'first_name'}, inplace=True)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df.loc[df["name"].str.split().str.len() == 2, "last_name"] = (
            df["name"].str.split().str[-1]
        )
        df.loc[df["name"].str.split().str.len() == 2, "name"] = (
            df["name"].str.split().str[0]
        )
        df.rename(columns={"name": "first_name"}, inplace=True)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"name": ["Jack Fine", "Kim Q. Danger", "Jane Smith", "Zhongli"]}
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(name_array):
    result = np.empty((name_array.shape[0], 2), dtype=object)
    for i, name in enumerate(name_array):
        parts = name.split()
        if len(parts) == 2:
            result[i] = parts
        else:
            result[i] = [name, '']
    return result

result_array = g(name_array.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        result = np.empty((data.shape[0], 2), dtype=object)
        for i, name in enumerate(data):
            parts = name.split()
            if len(parts) == 2:
                result[i] = parts
            else:
                result[i] = [name, '']
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            return np.array(['Jack Fine', 'Kim Q. Danger', 'Jane Smith', 'Zhongli'])

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r'''
import numpy as np
name_array = test_input
[insert]
result = result_array
'''

def test_execution(solution: str):
    code = exec_context.replace('[insert]', solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {'test_input': test_input}
        exec(code, test_env)
        assert exec_test(test_env['result'], expected_result)

def g(df):
    df.loc[df['name'].str.split().str.len() == 2, '2_name'] = df['name'].str.split().str[-1]
    df.loc[df['name'].str.split().str.len() == 2, 'name'] = df['name'].str.split().str[0]
    df.rename(columns={'name': '1_name'}, inplace=True)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df.loc[df["name"].str.split().str.len() == 2, "2_name"] = (
            df["name"].str.split().str[-1]
        )
        df.loc[df["name"].str.split().str.len() == 2, "name"] = (
            df["name"].str.split().str[0]
        )
        df.rename(columns={"name": "1_name"}, inplace=True)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"name": ["Jack Fine", "Kim Q. Danger", "Jane Smith", "Zhongli"]}
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([(1, 1.15), (2, 2), (3, 1), (4, 25), (5, 'and')], dtype=object)

arr = ... # put solution in this variable

def g(arr):
    return [x[1] for x in arr if not isinstance(x[1], int)]

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        return [x[1] for x in arr if not isinstance(x[1], int)]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([(1, 1.15), (2, 2), (3, 1), (4, 25), (5, 'and')], dtype=object)
        if test_case_id == 2:
            arr = np.array([(1, 1), (2, 2), (3, 1), (4, 2.5), (5, 'and')], dtype=object)
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df = pd.DataFrame({"ID": [1,2,3,4,5], "Field1": [1.15,2,1,25,"and"]})

df = ... # put solution in this variable

def g(df):
    return df.loc[~df['Field1'].astype(str).str.isdigit(), 'Field1'].tolist()

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.loc[~df["Field1"].astype(str).str.isdigit(), "Field1"].tolist()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"ID": [1, 2, 3, 4, 5], "Field1": [1.15, 2, 1, 25, "and"]}
            )
        if test_case_id == 2:
            df = pd.DataFrame({"ID": [1, 2, 3, 4, 5], "Field1": [1, 2, 1, 2.5, "and"]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([1.15, 2, 1, 25, 'and'], dtype=object)

arr = ... # put solution in this variable

def g(arr):
    return [x for x in arr if isinstance(x, int)]

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        return [x for x in arr if isinstance(x, int)]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([1.15, 2, 1, 25, 'and'], dtype=object)
        if test_case_id == 2:
            arr = np.array([1, 2, 1, 2.5, 'and'], dtype=object)
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    return df.loc[df['Field1'].astype(str).str.isdigit(), 'Field1'].tolist()

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.loc[df["Field1"].astype(str).str.isdigit(), "Field1"].tolist()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"ID": [1, 2, 3, 4, 5], "Field1": [1.15, 2, 1, 25, "and"]}
            )
        if test_case_id == 2:
            df = pd.DataFrame({"ID": [1, 2, 3, 4, 5], "Field1": [1, 2, 1, 2.5, "and"]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

example_array = np.array([1.15, 2, 1, 25, 'and'], dtype=object)
def f(arr=example_array):
    # return the solution in this function
    # result = f(arr)
    ###

    result = [x for x in arr if not (isinstance(x, int) or (isinstance(x, float) and x.is_integer()))]

    return result

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        return [x for x in arr if not (isinstance(x, int) or (isinstance(x, float) and x.is_integer()))]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([1.15, 2, 1, 25, 'and'], dtype=object)
        if test_case_id == 2:
            arr = np.array([1, 2, 1, 2.5, 'and'], dtype=object)
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
def f(arr):
[insert]
arr = test_input
result = f(arr)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

example_df = pd.DataFrame({"ID": [1,2,3,4,5], "Field1": [1.15,2,1,25,"and"]})
def f(df=example_df):
    # return the solution in this function
    # result = f(df)
    ###

    result = df.loc[~df['Field1'].astype(str).str.isdigit(), 'Field1'].tolist()

    return result

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.loc[~df["Field1"].astype(str).str.isdigit(), "Field1"].tolist()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"ID": [1, 2, 3, 4, 5], "Field1": [1.15, 2, 1, 25, "and"]}
            )
        if test_case_id == 2:
            df = pd.DataFrame({"ID": [1, 2, 3, 4, 5], "Field1": [1, 2, 1, 2.5, "and"]})
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
def f(df):
[insert]
df = test_input
result = f(df)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np

arr = np.array([
    ['A', 7, 10, 0, 19],
    ['B', 10, 2, 1, 14],
    ['C', 5, 15, 6, 16]
], dtype=object)

arr = ... # put solution in this variable

def g(arr):
    values = arr[:, 1:].astype(float)
    row_sums = values.sum(axis=1, keepdims=True)
    percentages = values / row_sums
    return np.column_stack((arr[:, 0], percentages))

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        values = data[:, 1:].astype(float)
        row_sums = values.sum(axis=1, keepdims=True)
        percentages = values / row_sums
        return np.column_stack((data[:, 0], percentages))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                ['A', 7, 10, 0, 19],
                ['B', 10, 2, 1, 14],
                ['C', 5, 15, 6, 16]
            ], dtype=object)
        if test_case_id == 2:
            arr = np.array([
                ['A', 1, 10, 0, 19],
                ['B', 1, 2, 1, 14],
                ['C', 4, 15, 6, 16]
            ], dtype=object)
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_almost_equal(result[:, 1:].astype(float), ans[:, 1:].astype(float), decimal=3)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    df = df.set_index('cat')
    res = df.div(df.sum(axis=1), axis=0)
    return res.reset_index()

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df = df.set_index("cat")
        res = df.div(df.sum(axis=1), axis=0)
        return res.reset_index()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "cat": ["A", "B", "C"],
                    "val1": [7, 10, 5],
                    "val2": [10, 2, 15],
                    "val3": [0, 1, 6],
                    "val4": [19, 14, 16],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "cat": ["A", "B", "C"],
                    "val1": [1, 1, 4],
                    "val2": [10, 2, 15],
                    "val3": [0, 1, 6],
                    "val4": [19, 14, 16],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


array = [['apple', 'banana', None, 'date'], ['elephant', None, 'grape', 'honey']]

import numpy as np

users = np.array(['Hu Tao', 'Zhongli', 'Xingqiu'])
keywords_0 = np.array(['a', np.nan, 'c'], dtype=object)
keywords_1 = np.array(['d', 'e', np.nan], dtype=object)
keywords_2 = np.array([np.nan, np.nan, 'b'], dtype=object)
keywords_3 = np.array(['f', np.nan, 'g'], dtype=object)

keywords_all = ... # put solution in this variable

import numpy as np

def g(users, keywords_0, keywords_1, keywords_2, keywords_3):
    keywords = np.array([keywords_0, keywords_1, keywords_2, keywords_3], dtype=object).T
    keywords_all = []
    for row in keywords:
        non_nan_values = [str(x) for x in row if x is not np.nan]
        concatenated = '-'.join(non_nan_values)[::-1]
        keywords_all.append(concatenated)
    return np.array(keywords_all)

keywords_all = g(users, keywords_0, keywords_1, keywords_2, keywords_3)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(users, keywords_0, keywords_1, keywords_2, keywords_3):
        keywords = np.array([keywords_0, keywords_1, keywords_2, keywords_3], dtype=object).T
        keywords_all = []
        for row in keywords:
            non_nan_values = [str(x) for x in row if x is not np.nan]
            concatenated = '-'.join(non_nan_values)[::-1]
            keywords_all.append(concatenated)
        return np.array(keywords_all)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            users = np.array(['Hu Tao', 'Zhongli', 'Xingqiu'])
            keywords_0 = np.array(['a', np.nan, 'c'], dtype=object)
            keywords_1 = np.array(['d', 'e', np.nan], dtype=object)
            keywords_2 = np.array([np.nan, np.nan, 'b'], dtype=object)
            keywords_3 = np.array(['f', np.nan, 'g'], dtype=object)
        if test_case_id == 2:
            users = np.array(['Hu Tao', 'Zhongli', 'Xingqiu'])
            keywords_0 = np.array(['a', np.nan, 'c'], dtype=object)
            keywords_1 = np.array(['b', 'g', np.nan], dtype=object)
            keywords_2 = np.array([np.nan, np.nan, 'j'], dtype=object)
            keywords_3 = np.array(['d', np.nan, 'b'], dtype=object)
        return users, keywords_0, keywords_1, keywords_2, keywords_3

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(*copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
users, keywords_0, keywords_1, keywords_2, keywords_3 = test_input
[insert]
result = keywords_all
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
df = pd.DataFrame({'users': ['Hu Tao', 'Zhongli', 'Xingqiu'], 'keywords_0': ['a', np.nan, 'c'], 'keywords_1': ['d', 'e', np.nan], 'keywords_2': [np.nan, np.nan, 'b'], 'keywords_3': ['f', np.nan, 'g']})

import pandas as pd
import numpy as np

df = pd.DataFrame({'users': ['Hu Tao', 'Zhongli', 'Xingqiu'],
                   'keywords_0': ["a", np.nan, "c"],
                   'keywords_1': ["d", "e", np.nan],
                   'keywords_2': [np.nan, np.nan, "b"],
                   'keywords_3': ["f", np.nan, "g"]})

df = ... # put solution in this variable

import numpy as np
def g(df):
    df["keywords_all"] = df.filter(like='keyword').apply(lambda x: '-'.join(x.dropna()), axis=1)
    for i in range(len(df)):
        df.loc[i, "keywords_all"] = df.loc[i, "keywords_all"][::-1]
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["keywords_all"] = df.filter(like="keyword").apply(
            lambda x: "-".join(x.dropna()), axis=1
        )
        for i in range(len(df)):
            df.loc[i, "keywords_all"] = df.loc[i, "keywords_all"][::-1]
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "users": ["Hu Tao", "Zhongli", "Xingqiu"],
                    "keywords_0": ["a", np.nan, "c"],
                    "keywords_1": ["d", "e", np.nan],
                    "keywords_2": [np.nan, np.nan, "b"],
                    "keywords_3": ["f", np.nan, "g"],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "users": ["Hu Tao", "Zhongli", "Xingqiu"],
                    "keywords_0": ["a", np.nan, "c"],
                    "keywords_1": ["b", "g", np.nan],
                    "keywords_2": [np.nan, np.nan, "j"],
                    "keywords_3": ["d", np.nan, "b"],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(arr):
    np.random.seed(0)
    l = int(0.2 * len(arr))
    indices = np.random.choice(len(arr), l, replace=False)
    arr[indices, 2] = 0
    return arr

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        np.random.seed(0)
        l = int(0.2 * len(arr))
        indices = np.random.choice(len(arr), l, replace=False)
        arr[indices, 2] = 0
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [1, 1, 6],
                [1, 4, 1],
                [1, 7, 3],
                [2, 4, 2],
                [3, 2, 7],
                [3, 1, 2],
            ])
        if test_case_id == 2:
            arr = np.array([
                [1, 1, 6],
                [1, 4, 1],
                [1, 7, 3],
                [2, 4, 2],
                [3, 2, 7],
                [3, 1, 2],
                [1, 5, 9],
                [1, 1, 9],
                [4, 4, 6],
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    assert "choice" in solution

UserId    ProductId    Quantity
1         1            6
1         4            1
1         7            3
2         4            2
3         2            7
3         1            2

import pandas as pd

df = pd.DataFrame({'UserId': [1, 1, 1, 2, 3, 3],
                   'ProductId': [1, 4, 7, 4, 2, 1],
                   'Quantity': [6, 1, 3, 2, 7, 2]})

df = ... # put solution in this variable

def g(df):
    l = int(0.2 * len(df))
    dfupdate = df.sample(l, random_state=0)
    dfupdate.Quantity = 0
    df.update(dfupdate)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        l = int(0.2 * len(df))
        dfupdate = df.sample(l, random_state=0)
        dfupdate.Quantity = 0
        df.update(dfupdate)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "UserId": [1, 1, 1, 2, 3, 3],
                    "ProductId": [1, 4, 7, 4, 2, 1],
                    "Quantity": [6, 1, 3, 2, 7, 2],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "UserId": [1, 1, 1, 2, 3, 3, 1, 1, 4],
                    "ProductId": [1, 4, 7, 4, 2, 1, 5, 1, 4],
                    "Quantity": [6, 1, 3, 2, 7, 2, 9, 9, 6],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "sample" in tokens


def g(arr):
    np.random.seed(0)
    l = int(0.2 * len(arr))
    indices = np.random.choice(len(arr), l, replace=False)
    arr[indices, 1] = 0
    return arr

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        np.random.seed(0)
        l = int(0.2 * len(arr))
        indices = np.random.choice(len(arr), l, replace=False)
        arr[indices, 1] = 0
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [1, 1, 6],
                [1, 4, 1],
                [1, 7, 3],
                [2, 4, 2],
                [3, 2, 7],
                [3, 1, 2],
            ])
        if test_case_id == 2:
            arr = np.array([
                [1, 1, 6],
                [1, 4, 1],
                [1, 7, 3],
                [2, 4, 2],
                [3, 2, 7],
                [3, 1, 2],
                [1, 5, 9],
                [1, 1, 9],
                [4, 4, 6],
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    assert "choice" in solution

def g(df):
    l = int(0.2 * len(df))
    dfupdate = df.sample(l, random_state=0)
    dfupdate.ProductId = 0
    df.update(dfupdate)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        l = int(0.2 * len(df))
        dfupdate = df.sample(l, random_state=0)
        dfupdate.ProductId = 0
        df.update(dfupdate)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "UserId": [1, 1, 1, 2, 3, 3],
                    "ProductId": [1, 4, 7, 4, 2, 1],
                    "Quantity": [6, 1, 3, 2, 7, 2],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "UserId": [1, 1, 1, 2, 3, 3, 1, 1, 4],
                    "ProductId": [1, 4, 7, 4, 2, 1, 5, 1, 4],
                    "Quantity": [6, 1, 3, 2, 7, 2, 9, 9, 6],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "sample" in tokens


def g(arr):
    unique_users = np.unique(arr[:, 0])
    for user in unique_users:
        user_indices = np.where(arr[:, 0] == user)[0]
        l = int(0.2 * len(user_indices))
        np.random.seed(0)
        selected_indices = np.random.choice(user_indices, l, replace=False)
        arr[selected_indices, 2] = 0
    return arr

arr = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        unique_users = np.unique(arr[:, 0])
        for user in unique_users:
            user_indices = np.where(arr[:, 0] == user)[0]
            l = int(0.2 * len(user_indices))
            np.random.seed(0)
            selected_indices = np.random.choice(user_indices, l, replace=False)
            arr[selected_indices, 2] = 0
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [1, 1, 6],
                [1, 4, 1],
                [1, 7, 3],
                [1, 4, 2],
                [1, 2, 7],
                [2, 1, 2],
                [2, 1, 6],
                [2, 4, 1],
                [2, 7, 3],
                [2, 4, 2],
                [3, 2, 7],
                [3, 1, 2],
                [3, 1, 6],
                [3, 4, 1],
                [3, 7, 3],
            ])
        if test_case_id == 2:
            arr = np.array([
                [1, 6, 1],
                [1, 1, 4],
                [1, 3, 7],
                [1, 2, 4],
                [1, 7, 2],
                [2, 2, 1],
                [2, 6, 1],
                [2, 1, 4],
                [2, 3, 7],
                [2, 2, 4],
                [3, 7, 2],
                [3, 2, 1],
                [3, 6, 1],
                [3, 1, 4],
                [3, 3, 7],
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
result = arr
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    assert "np.random.choice" in solution

def g(df):
    for i in range(len(df)):
        tot = 0
        if i != 0:
            if df.loc[i, 'UserId'] == df.loc[i-1, 'UserId']:
                continue
        for j in range(len(df)):
            if df.loc[i, 'UserId'] == df.loc[j, 'UserId']:
                tot += 1
        l = int(0.2*tot)
        dfupdate = df.iloc[i:i+tot].sample(l, random_state=0)
        dfupdate.Quantity = 0
        df.update(dfupdate)
    return df

df = g(df.copy())

import pandas as pd
import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        for i in range(len(df)):
            tot = 0
            if i != 0:
                if df.loc[i, "UserId"] == df.loc[i - 1, "UserId"]:
                    continue
            for j in range(len(df)):
                if df.loc[i, "UserId"] == df.loc[j, "UserId"]:
                    tot += 1
            l = int(0.2 * tot)
            dfupdate = df.iloc[i : i + tot].sample(l, random_state=0)
            dfupdate.Quantity = 0
            df.update(dfupdate)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "UserId": [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],
                    "ProductId": [1, 4, 7, 4, 2, 1, 1, 4, 7, 4, 2, 1, 1, 4, 7],
                    "Quantity": [6, 1, 3, 2, 7, 2, 6, 1, 3, 2, 7, 2, 6, 1, 3],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "UserId": [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],
                    "ProductId": [6, 1, 3, 2, 7, 2, 6, 1, 3, 2, 7, 2, 6, 1, 3],
                    "Quantity": [1, 4, 7, 4, 2, 1, 1, 4, 7, 4, 2, 1, 1, 4, 7],
                }
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "sample" in tokens


import numpy as np

arr = np.array([[1, 2], [3, 4], [1, 2], [1, 4], [1, 2]])

result = ... # put solution in this variable

def g(arr):
    unique, index, counts = np.unique(arr, axis=0, return_index=True, return_counts=True)
    duplicate_indices = np.where(counts > 1)[0]
    index_original = index[duplicate_indices]
    duplicates = np.array([arr[i] for i in range(len(arr)) if i not in index and tuple(arr[i]) in map(tuple, unique[duplicate_indices])])
    index_col = np.array([index_original[np.where((unique[duplicate_indices] == row).all(axis=1))[0][0]] for row in duplicates])
    return np.column_stack((duplicates, index_col))

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        unique, index, counts = np.unique(arr, axis=0, return_index=True, return_counts=True)
        duplicate_indices = np.where(counts > 1)[0]
        index_original = index[duplicate_indices]
        duplicates = np.array([arr[i] for i in range(len(arr)) if i not in index and tuple(arr[i]) in map(tuple, unique[duplicate_indices])])
        index_col = np.array([index_original[np.where((unique[duplicate_indices] == row).all(axis=1))[0][0]] for row in duplicates])
        return np.column_stack((duplicates, index_col))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([[1, 2], [3, 4], [1, 2], [1, 4], [1, 2]])
        if test_case_id == 2:
            arr = np.array([[1, 1], [3, 1], [1, 4], [1, 9], [1, 6]])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df=pd.DataFrame(data=[[1,2],[3,4],[1,2],[1,4],[1,2]],columns=['col1','col2'])

result = ... # put solution in this variable

def g(df):
    df['index_original'] = df.groupby(['col1', 'col2']).col1.transform('idxmin')
    return df[df.duplicated(subset=['col1', 'col2'], keep='first')]

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["index_original"] = df.groupby(["col1", "col2"]).col1.transform("idxmin")
        return df[df.duplicated(subset=["col1", "col2"], keep="first")]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                data=[[1, 2], [3, 4], [1, 2], [1, 4], [1, 2]], columns=["col1", "col2"]
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                data=[[1, 1], [3, 1], [1, 4], [1, 9], [1, 6]], columns=["col1", "col2"]
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(arr):
    unique_rows, indices, inverse_indices, counts = np.unique(arr, axis=0, return_index=True, return_inverse=True, return_counts=True)
    index_original = np.zeros(arr.shape[0], dtype=int)
    for idx in range(len(unique_rows)):
        last_index = np.max(np.where(inverse_indices == idx)[0])
        index_original[np.where(inverse_indices == idx)] = last_index
    duplicate_mask = np.isin(inverse_indices, np.where(counts > 1)[0])
    result = np.column_stack((arr[duplicate_mask], index_original[duplicate_mask]))
    return result

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        unique_rows, indices, inverse_indices, counts = np.unique(arr, axis=0, return_index=True, return_inverse=True, return_counts=True)
        index_original = np.zeros(arr.shape[0], dtype=int)
        for idx in range(len(unique_rows)):
            last_index = np.max(np.where(inverse_indices == idx)[0])
            index_original[np.where(inverse_indices == idx)] = last_index
        duplicate_mask = np.isin(inverse_indices, np.where(counts > 1)[0])
        result = np.column_stack((arr[duplicate_mask], index_original[duplicate_mask]))
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([[1, 2], [3, 4], [1, 2], [1, 4], [1, 2]])
        if test_case_id == 2:
            arr = np.array([[1, 1], [3, 1], [1, 4], [1, 9], [1, 6]])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    df['index_original'] = df.groupby(['col1', 'col2']).col1.transform('idxmax')
    for i in range(len(df)):
        i = len(df) - 1 - i
        origin = df.loc[i, 'index_original']
        if i <= origin:
            continue
        if origin == df.loc[origin, 'index_original']:
            df.loc[origin, 'index_original'] = i
        df.loc[i, 'index_original'] = df.loc[origin, 'index_original']
    return df[df.duplicated(subset=['col1', 'col2'], keep='last')]

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["index_original"] = df.groupby(["col1", "col2"]).col1.transform("idxmax")
        for i in range(len(df)):
            i = len(df) - 1 - i
            origin = df.loc[i, "index_original"]
            if i <= origin:
                continue
            if origin == df.loc[origin, "index_original"]:
                df.loc[origin, "index_original"] = i
            df.loc[i, "index_original"] = df.loc[origin, "index_original"]
        return df[df.duplicated(subset=["col1", "col2"], keep="last")]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                data=[[1, 2], [3, 4], [1, 2], [1, 4], [1, 2]], columns=["col1", "col2"]
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                data=[[1, 1], [3, 1], [1, 4], [1, 9], [1, 6]], columns=["col1", "col2"]
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(arr):
    cols = arr[:, 1:]
    unique, index, counts = np.unique(cols, axis=0, return_index=True, return_counts=True)
    duplicate_indices = np.where(counts > 1)[0]
    index_original = index[duplicate_indices]
    duplicates = np.array([arr[i] for i in range(len(arr)) if i not in index_original and any((cols[i] == unique[j]).all() for j in duplicate_indices)])
    index_col = np.array([index_original[np.where((cols[i] == unique[duplicate_indices]).all(axis=1))[0][0]] for i in range(len(arr)) if i not in index_original and any((cols[i] == unique[j]).all() for j in duplicate_indices)])
    return np.column_stack((duplicates, index_col))

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        cols = arr[:, 1:]
        unique, index, counts = np.unique(cols, axis=0, return_index=True, return_counts=True)
        duplicate_indices = np.where(counts > 1)[0]
        index_original = index[duplicate_indices]
        duplicates = np.array([arr[i] for i in range(len(arr)) if i not in index_original and any((cols[i] == unique[j]).all() for j in duplicate_indices)])
        index_col = np.array([index_original[np.where((cols[i] == unique[duplicate_indices]).all(axis=1))[0][0]] for i in range(len(arr)) if i not in index_original and any((cols[i] == unique[j]).all() for j in duplicate_indices)])
        return np.column_stack((duplicates, index_col))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [1, 1, 2, 5],
                [1, 3, 4, 1],
                [4, 1, 2, 5],
                [5, 1, 4, 9],
                [1, 1, 2, 5],
            ])
        elif test_case_id == 2:
            arr = np.array([
                [1, 1, 2, 5],
                [1, 3, 4, 1],
                [4, 1, 2, 5],
                [5, 1, 4, 9],
                [1, 1, 2, 5],
                [4, 1, 2, 6],
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd

df=pd.DataFrame(data=[[1,1,2,5],[1,3,4,1],[4,1,2,5],[5,1,4,9],[1,1,2,5]],columns=['val', 'col1','col2','3col'])

result = ... # put solution in this variable

def g(df):
    cols = list(df.filter(like='col'))
    df['index_original'] = df.groupby(cols)[cols[0]].transform('idxmin')
    return df[df.duplicated(subset=cols, keep='first')]

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        cols = list(df.filter(like="col"))
        df["index_original"] = df.groupby(cols)[cols[0]].transform("idxmin")
        return df[df.duplicated(subset=cols, keep="first")]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                data=[
                    [1, 1, 2, 5],
                    [1, 3, 4, 1],
                    [4, 1, 2, 5],
                    [5, 1, 4, 9],
                    [1, 1, 2, 5],
                ],
                columns=["val", "col1", "col2", "3col"],
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                data=[
                    [1, 1, 2, 5],
                    [1, 3, 4, 1],
                    [4, 1, 2, 5],
                    [5, 1, 4, 9],
                    [1, 1, 2, 5],
                    [4, 1, 2, 6],
                ],
                columns=["val", "col1", "col2", "3col"],
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


def g(arr):
    cols = arr[:, 1:3]
    index_original = np.zeros(len(arr), dtype=int)
    for i in range(len(arr)):
        matches = np.all(cols == cols[i], axis=1)
        index_original[i] = np.where(matches)[0][-1]
    for i in range(len(arr)):
        i = len(arr) - 1 - i
        origin = index_original[i]
        if i <= origin:
            continue
        if origin == index_original[origin]:
            index_original[origin] = i
        index_original[i] = index_original[origin]
    duplicates = np.array([i for i in range(len(arr)) if np.any((cols == cols[i]).all(axis=1) & (np.arange(len(arr)) != i))])
    return np.hstack((arr[duplicates], index_original[duplicates, np.newaxis]))

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        cols = arr[:, 1:3]
        index_original = np.zeros(len(arr), dtype=int)
        for i in range(len(arr)):
            matches = np.all(cols == cols[i], axis=1)
            index_original[i] = np.where(matches)[0][-1]
        for i in range(len(arr)):
            i = len(arr) - 1 - i
            origin = index_original[i]
            if i <= origin:
                continue
            if origin == index_original[origin]:
                index_original[origin] = i
            index_original[i] = index_original[origin]
        duplicates = np.array([i for i in range(len(arr)) if np.any((cols == cols[i]).all(axis=1) & (np.arange(len(arr)) != i))])
        return np.hstack((arr[duplicates], index_original[duplicates, np.newaxis]))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [1, 1, 2, 5],
                [1, 3, 4, 1],
                [4, 1, 2, 5],
                [5, 1, 4, 9],
                [1, 1, 2, 5],
            ])
        if test_case_id == 2:
            arr = np.array([
                [4, 1, 2, 5],
                [1, 1, 2, 5],
                [1, 3, 4, 1],
                [9, 9, 1, 4],
                [1, 1, 2, 5],
            ])
        return arr

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def g(df):
    cols = list(df.filter(like='col'))
    df['index_original'] = df.groupby(cols)[cols[0]].transform('idxmax')
    for i in range(len(df)):
        i = len(df) - 1 - i
        origin = df.loc[i, 'index_original']
        if i <= origin:
            continue
        if origin == df.loc[origin, 'index_original']:
            df.loc[origin, 'index_original'] = i
        df.loc[i, 'index_original'] = df.loc[origin, 'index_original']
    return df[df.duplicated(subset=cols, keep='last')]

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        cols = list(df.filter(like="col"))
        df["index_original"] = df.groupby(cols)[cols[0]].transform("idxmax")
        for i in range(len(df)):
            i = len(df) - 1 - i
            origin = df.loc[i, "index_original"]
            if i <= origin:
                continue
            if origin == df.loc[origin, "index_original"]:
                df.loc[origin, "index_original"] = i
            df.loc[i, "index_original"] = df.loc[origin, "index_original"]
        return df[df.duplicated(subset=cols, keep="last")]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                data=[
                    [1, 1, 2, 5],
                    [1, 3, 4, 1],
                    [4, 1, 2, 5],
                    [5, 1, 4, 9],
                    [1, 1, 2, 5],
                ],
                columns=["val", "col1", "col2", "3col"],
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                data=[
                    [4, 1, 2, 5],
                    [1, 1, 2, 5],
                    [1, 3, 4, 1],
                    [9, 9, 1, 4],
                    [1, 1, 2, 5],
                ],
                columns=["val", "col1", "col2", "3col"],
            )
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)