import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
from scipy.optimize import fsolve
def eqn(x, a, b):
    return x + 2*a - b**2

xdata, adata = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
A = np.array([fsolve(lambda b,x,a: eqn(x, a, b), x0=0, args=(x,a))[0] for x, a in zip(xdata, adata)])
temp = -A
result = np.zeros((len(A), 2))
result[:, 0] = A
result[:, 1] = temp
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
from scipy import sparse
import numpy as np
import math
sa = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
sa = sparse.csr_matrix(sa.toarray() / np.sqrt(np.sum(sa.toarray()**2, axis=0)))

#print(sa)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(sa, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
from scipy import stats
mu, stddev = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
expected_value = np.exp(mu + stddev ** 2 / 2)
median = np.exp(mu)

#print(expected_value, median)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump([expected_value, median], f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
from scipy import ndimage

img = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
threshold = 0.75
blobs = img < threshold
labels, result = ndimage.label(blobs)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
from scipy import ndimage

img = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
threshold = 0.75
blobs = img > threshold
labels, nlabels = ndimage.label(blobs)
r, c = np.vstack(ndimage.center_of_mass(img, labels, np.arange(nlabels) + 1)).T
# find their distances from the top-left corner
d = np.sqrt(r * r + c * c)
result = sorted(d)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
import scipy.interpolate

points, V, request = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = scipy.interpolate.griddata(points, V, request)
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
from scipy import stats
import numpy as np

x, y, alpha = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
s, p = stats.ks_2samp(x, y)
result = (p <= alpha)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

from scipy import sparse
import numpy as np
a, b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
b = sparse.csr_matrix(a)
b.setdiag(0)
b.eliminate_zeros()

#print(b)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(b, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

from scipy import misc
from scipy.ndimage import rotate
import numpy as np
data_orig, x0, y0, angle = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def rot_ans(image, xy, angle):
    im_rot = rotate(image,angle)
    org_center = (np.array(image.shape[:2][::-1])-1)/2.
    rot_center = (np.array(im_rot.shape[:2][::-1])-1)/2.
    org = xy-org_center
    a = np.deg2rad(angle)
    new = np.array([org[0]*np.cos(a) + org[1]*np.sin(a),
            -org[0]*np.sin(a) + org[1]*np.cos(a) ])
    return im_rot, new+rot_center
data_rot, (xrot, yrot) =rot_ans(data_orig, np.array([x0, y0]), angle)

#print(data_rot, (xrot, yrot))

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump([data_rot, (xrot, yrot)], f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
from scipy import stats
import numpy as np
np.random.seed(42)
x, y = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
statistic, p_value = stats.ks_2samp(x, y)

#print(statistic, p_value)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump([statistic, p_value], f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import pandas as pd
import io
from scipy import stats

df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
indices = [('1415777_at Pnliprp1', 'data'), ('1415777_at Pnliprp1', 'zscore'), ('1415805_at Clps', 'data'), ('1415805_at Clps', 'zscore'), ('1415884_at Cela3b', 'data'), ('1415884_at Cela3b', 'zscore')]
indices = pd.MultiIndex.from_tuples(indices)
df2 = pd.DataFrame(data=stats.zscore(df, axis = 1), index=df.index, columns=df.columns)
df3 = pd.concat([df, df2], axis=1).to_numpy().reshape(-1, 3)
result = pd.DataFrame(data=df3, index=indices, columns=df.columns)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import scipy.interpolate
x, y, eval = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = scipy.interpolate.griddata(x, y, eval)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
from scipy import stats
import pandas as pd
import numpy as np
LETTERS = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
df = df[(np.abs(stats.zscore(df.select_dtypes(exclude='object'))) < 3).all(axis=1)]

#print(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(df, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import scipy.integrate
import math
import numpy as np
x, u, o2 = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def NDfx(x):
    return((1/math.sqrt((2*math.pi)))*(math.e**((-.5)*(x**2))))
def f(x, u, o2):
    norm = (x-u)/o2
    prob = scipy.integrate.quad(NDfx, -np.inf, norm)[0]
    return prob

result = f(x, u, o2)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
import scipy.spatial.distance
example_array = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
import itertools
n = example_array.max()+1
indexes = []
for k in range(1, n):
    tmp = np.nonzero(example_array == k)
    tmp = np.asarray(tmp).T
    indexes.append(tmp)
result = np.zeros((n-1, n-1))
for i, j in itertools.combinations(range(n-1), 2):
    d2 = scipy.spatial.distance.cdist(indexes[i], indexes[j], metric='sqeuclidean')
    result[i, j] = result[j, i] = d2.min()**0.5

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
from scipy import interpolate
import numpy as np
x, y, x_val = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.zeros((5, 100))
for i in range(5):
    extrapolator = interpolate.UnivariateSpline(x[:, i], y[:, i], k = 2, s = 4)
    y_int = extrapolator(x_val)
    result[i, :] = y_int

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import scipy.integrate
c, low, high = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = scipy.integrate.quadrature(lambda x: 2*c*x, low, high)[0]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
from scipy.sparse import csr_matrix

col = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
mean = col.mean()
N = col.shape[0]
sqr = col.copy()  # take a copy of the col
sqr.data **= 2  # square the data, i.e. just the non-zero data
standard_deviation = np.sqrt(sqr.sum() / N - col.mean() ** 2)

#print(mean)
#print(standard_deviation)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump([mean, standard_deviation], f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import scipy.integrate
import numpy as np
N0, time_span = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def dN1_dt(t, N1):
    input = 1-np.cos(t) if 0<t<2*np.pi else 0
    return -100*N1 + input
sol = scipy.integrate.solve_ivp(fun=dN1_dt, t_span=time_span, y0=[N0,])
result = sol.y
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np

import scipy.stats
p_values = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
z_scores = scipy.stats.norm.ppf(p_values)

#print(z_scores)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(z_scores, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
import scipy.fft as sf
N = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = sf.dct(np.eye(N), axis=0, norm= 'ortho')

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
from scipy.sparse import csr_matrix

M, row, column = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.array(M[row,column]).squeeze()
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
from scipy import ndimage

img = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
threshold = 0.75
blobs = img > threshold
labels, result = ndimage.label(blobs)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()

import numpy as np
from scipy.sparse import csr_matrix

M, row, column = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = M[row,column]
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
from scipy import sparse
import numpy as np
import math
sa = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
sa = sparse.csc_matrix(sa.toarray() / np.sqrt(np.sum(sa.toarray()**2, axis=0)))

#print(sa)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(sa, f)


import pickle
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
from scipy.linalg import block_diag
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = block_diag(*a)
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.expand_dims(a, 2)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths = [8-x for x in lengths]
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(~mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
x.assign(114514)
###END SOLUTION
result = x

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse
import shutil
import os

if os.path.exists('my_model'):
    shutil.rmtree('my_model')
parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

FLAG = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))

network_layout = []
for i in range(3):
    network_layout.append(8)

model = Sequential()

inputdim = 4
activation = 'relu'
outputdim = 2
opt='rmsprop'
epochs = 50
#Adding input layer and first hidden layer
model.add(Dense(network_layout[0],
                name="Input",
                input_dim=inputdim,
                kernel_initializer='he_normal',
                activation=activation))

#Adding the rest of hidden layer
for numneurons in network_layout[1:]:
    model.add(Dense(numneurons,
                    kernel_initializer = 'he_normal',
                    activation=activation))

#Adding the output layer
model.add(Dense(outputdim,
                name="Output",
                kernel_initializer="he_normal",
                activation="relu"))

#Compiling the model
model.compile(optimizer=opt,loss='mse',metrics=['mse','mae','mape'])

#Save the model in "export/1"

###BEGIN SOLUTION
tms_model = tf.saved_model.save(model,"export/1")
###END SOLUTION

try:
    assert os.path.exists("export")
    p = os.path.join("export", "1")
    assert os.path.exists(p)
    assert os.path.exists(os.path.join(p, "assets"))
    assert os.path.exists(os.path.join(p, "saved_model.pb"))
    p = os.path.join(p, "variables")
    assert os.path.exists(p)
    assert os.path.exists(os.path.join(p, "variables.data-00000-of-00001"))
    assert os.path.exists(os.path.join(p, "variables.index"))
    result = 1
except:
    result = 0

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(labels):
    ### BEGIN SOLUTION
    result =  tf.one_hot(indices=labels, depth=10, on_value=1, off_value=0, axis=-1)

    ### END SOLUTION
    return result
result = f(labels)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(A):
    return tf.reduce_sum(A, 1)

result = g(A.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.squeeze(a)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.expand_dims(tf.expand_dims(a, 2), 0)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

input = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
tf.compat.v1.disable_eager_execution()
###BEGIN SOLUTION
def g(input):
    ds = tf.data.Dataset.from_tensor_slices(input)
    ds = ds.flat_map(lambda x: tf.data.Dataset.from_tensor_slices([x, x + 1, x + 2]))
    element = tf.compat.v1.data.make_one_shot_iterator(ds).get_next()

    result = []
    with tf.compat.v1.Session() as sess:
        for _ in range(9):
            result.append(sess.run(element))
    return result

result = g(input)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x):
    return [tf.compat.as_str_any(a) for a in x]

result = g(x.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b):
    return tf.reduce_sum(tf.square( tf.subtract( a, b)), 1)

result = g(a.__copy__(),b.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.argmin(a,axis=0)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

FLAG = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
result = tf.version.VERSION
###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(lengths):
    ### BEGIN SOLUTION
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(mask, tf.ones([4, 8]), tf.zeros([4, 8]))

    ### END SOLUTION
    return result
result = f(lengths)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x):
    non_zero = tf.cast(x != 0, tf.float32)
    y = tf.reduce_sum(x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    return y

result = g(x.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(A):
    return tf.reduce_prod(A, 1)

result = g(A.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
x.assign(1)
###END SOLUTION
result = x

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

FLAG = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
tf.random.set_seed(10)
def get_values():
  A = tf.random.normal([100,100])
  B = tf.random.normal([100,100])
  return A,B

@tf.function
def compute():
  A,B = get_values()
  return tf.reduce_sum(tf.matmul(A,B))

result = compute()
###END SOLUTION
result = result.numpy()

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.argmax(a,axis=0)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    return tf.one_hot(indices=labels, depth=10, on_value=1, off_value=0, axis=-1)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse
import numpy as np

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

A = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(A):
    return tf.math.reciprocal(A)

result = g(A.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

seed_x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(seed_x):
    ### BEGIN SOLUTION
    tf.random.set_seed(seed_x)
    result = tf.random.uniform(shape=(10,), minval=1, maxval=5, dtype=tf.int32)

    ### END SOLUTION
    return result
result = f(seed_x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b):
    return tf.reduce_sum(tf.square( tf.subtract( a, b)), 0)

result = g(a.__copy__(),b.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b):
    tile_a = tf.tile(tf.expand_dims(a, 1), [1, tf.shape(b)[0]])
    tile_a = tf.expand_dims(tile_a, 2)
    tile_b = tf.tile(tf.expand_dims(b, 0), [tf.shape(a)[0], 1])
    tile_b = tf.expand_dims(tile_b, 2)
    cart = tf.concat([tile_a, tile_b], axis=2)
    return cart

result = g(a.__copy__(),b.__copy__())

###END SOLUTION
if result.shape == [12,2]:
    result = tf.reshape(result, [3,4,2])

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    t = tf.one_hot(indices=labels, depth=10, on_value=0, off_value=1, axis=-1)
    n = t.numpy()
    for i in range(len(n)):
        n[i] = n[i][::-1]
    return tf.constant(n)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(x):
    ### BEGIN SOLUTION
    result = [tf.compat.as_str_any(a) for a in x]

    ### END SOLUTION
    return result
result = f(x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x):
    non_zero = tf.cast(x != 0, tf.float32)
    y = tf.reduce_sum(x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    y = y * y
    z = tf.reduce_sum(x*x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    return z-y

result = g(x.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

seed_x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(seed_x):
    tf.random.set_seed(seed_x)
    return tf.random.uniform(shape=(114,), minval=2, maxval=6, dtype=tf.int32)

result = g(seed_x)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A,B = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(A,B):
    return tf.constant(np.einsum( 'ikm, jkm-> ijk', A, B))

result = g(A.__copy__(),B.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.argmax(a,axis=1)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

A,B = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(A,B):
    ### BEGIN SOLUTION
    result = tf.reduce_sum(tf.square( tf.subtract( A, B)), 1)

    ### END SOLUTION
    return result
result = f(A,B)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(~mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x,y,z = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(x,y,z):
    ### BEGIN SOLUTION
    result = tf.gather_nd(x, [y, z])

    ### END SOLUTION
    return result
result = f(x,y,z)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A,B = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(A,B):
    return tf.constant(np.einsum('ijm, ikm-> ijk', A, B))

result = g(A.__copy__(),B.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths = [8-x for x in lengths]
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    t = tf.one_hot(indices=labels, depth=10, on_value=1, off_value=0, axis=-1)
    n = t.numpy()
    for i in range(len(n)):
        n[i] = n[i][::-1]
    return tf.constant(n)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x,y,z = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x,y,z):
    return tf.gather_nd(x, [y, z])

result = g(x.__copy__(),y.__copy__(),z.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(a,b):
    ### BEGIN SOLUTION
    tile_a = tf.tile(tf.expand_dims(a, 1), [1, tf.shape(b)[0]])
    tile_a = tf.expand_dims(tile_a, 2)
    tile_b = tf.tile(tf.expand_dims(b, 0), [tf.shape(a)[0], 1])
    tile_b = tf.expand_dims(tile_b, 2)
    cart = tf.concat([tile_a, tile_b], axis=2)
    result = cart

    ### END SOLUTION
    return result
result = f(a,b)
if result.shape == [12,2]:
    result = tf.reshape(result, [3,4,2])

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    return tf.one_hot(indices=labels, depth=10, on_value=0, off_value=1, axis=-1)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(a):
    ### BEGIN SOLUTION
    result = tf.argmax(a,axis=1)

    ### END SOLUTION
    return result
result = f(a)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

seed_x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(seed_x):
    tf.random.set_seed(seed_x)
    return tf.random.uniform(shape=(10,), minval=1, maxval=5, dtype=tf.int32)

result = g(seed_x)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(x):
    ### BEGIN SOLUTION
    non_zero = tf.cast(x != 0, tf.float32)
    y = tf.reduce_sum(x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    result = y

    ### END SOLUTION
    return result
result = f(x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

input = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
tf.compat.v1.disable_eager_execution()
def f(input):
    ### BEGIN SOLUTION
    ds = tf.data.Dataset.from_tensor_slices(input)
    ds = ds.flat_map(lambda x: tf.data.Dataset.from_tensor_slices([x, x + 1, x + 2]))
    element = tf.compat.v1.data.make_one_shot_iterator(ds).get_next()

    result = []
    with tf.compat.v1.Session() as sess:
        for _ in range(9):
            result.append(sess.run(element))

    ### END SOLUTION
    return result
result = f(input)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x,row,col = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x,row,col):
    index = [[row[i],col[i]] for i in range(len(row))]
    return tf.gather_nd(x, index)

result = g(x.__copy__(),row.__copy__(),col.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.expand_dims(a, 2)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths = [8-x for x in lengths]
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(~mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
x.assign(114514)
###END SOLUTION
result = x

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse
import shutil
import os

if os.path.exists('my_model'):
    shutil.rmtree('my_model')
parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

FLAG = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))

network_layout = []
for i in range(3):
    network_layout.append(8)

model = Sequential()

inputdim = 4
activation = 'relu'
outputdim = 2
opt='rmsprop'
epochs = 50
#Adding input layer and first hidden layer
model.add(Dense(network_layout[0],
                name="Input",
                input_dim=inputdim,
                kernel_initializer='he_normal',
                activation=activation))

#Adding the rest of hidden layer
for numneurons in network_layout[1:]:
    model.add(Dense(numneurons,
                    kernel_initializer = 'he_normal',
                    activation=activation))

#Adding the output layer
model.add(Dense(outputdim,
                name="Output",
                kernel_initializer="he_normal",
                activation="relu"))

#Compiling the model
model.compile(optimizer=opt,loss='mse',metrics=['mse','mae','mape'])

#Save the model in "export/1"

###BEGIN SOLUTION
tms_model = tf.saved_model.save(model,"export/1")
###END SOLUTION

try:
    assert os.path.exists("export")
    p = os.path.join("export", "1")
    assert os.path.exists(p)
    assert os.path.exists(os.path.join(p, "assets"))
    assert os.path.exists(os.path.join(p, "saved_model.pb"))
    p = os.path.join(p, "variables")
    assert os.path.exists(p)
    assert os.path.exists(os.path.join(p, "variables.data-00000-of-00001"))
    assert os.path.exists(os.path.join(p, "variables.index"))
    result = 1
except:
    result = 0

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(labels):
    ### BEGIN SOLUTION
    result =  tf.one_hot(indices=labels, depth=10, on_value=1, off_value=0, axis=-1)

    return result

    ### END SOLUTION
result = f(labels)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(A):
    return tf.reduce_sum(A, 1)

result = g(A.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.squeeze(a)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.expand_dims(tf.expand_dims(a, 2), 0)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

input = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
tf.compat.v1.disable_eager_execution()
###BEGIN SOLUTION
def g(input):
    ds = tf.data.Dataset.from_tensor_slices(input)
    ds = ds.flat_map(lambda x: tf.data.Dataset.from_tensor_slices([x, x + 1, x + 2]))
    element = tf.compat.v1.data.make_one_shot_iterator(ds).get_next()

    result = []
    with tf.compat.v1.Session() as sess:
        for _ in range(9):
            result.append(sess.run(element))
    return result

result = g(input)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x):
    return [tf.compat.as_str_any(a) for a in x]

result = g(x.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b):
    return tf.reduce_sum(tf.square( tf.subtract( a, b)), 1)

result = g(a.__copy__(),b.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.argmin(a,axis=0)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

FLAG = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
result = tf.version.VERSION
###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(lengths):
    ### BEGIN SOLUTION
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(mask, tf.ones([4, 8]), tf.zeros([4, 8]))

    return result

    ### END SOLUTION
result = f(lengths)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x):
    non_zero = tf.cast(x != 0, tf.float32)
    y = tf.reduce_sum(x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    return y

result = g(x.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(A):
    return tf.reduce_prod(A, 1)

result = g(A.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
x.assign(1)
###END SOLUTION
result = x

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

FLAG = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
tf.random.set_seed(10)
def get_values():
  A = tf.random.normal([100,100])
  B = tf.random.normal([100,100])
  return A,B

@tf.function
def compute():
  A,B = get_values()
  return tf.reduce_sum(tf.matmul(A,B))

result = compute()
###END SOLUTION
result = result.numpy()

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.argmax(a,axis=0)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    return tf.one_hot(indices=labels, depth=10, on_value=1, off_value=0, axis=-1)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse
import numpy as np

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

A = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(A):
    return tf.math.reciprocal(A)

result = g(A.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

seed_x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(seed_x):
    ### BEGIN SOLUTION
    tf.random.set_seed(seed_x)
    result = tf.random.uniform(shape=(10,), minval=1, maxval=5, dtype=tf.int32)

    return result

    ### END SOLUTION
result = f(seed_x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b):
    return tf.reduce_sum(tf.square( tf.subtract( a, b)), 0)

result = g(a.__copy__(),b.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a,b):
    tile_a = tf.tile(tf.expand_dims(a, 1), [1, tf.shape(b)[0]])
    tile_a = tf.expand_dims(tile_a, 2)
    tile_b = tf.tile(tf.expand_dims(b, 0), [tf.shape(a)[0], 1])
    tile_b = tf.expand_dims(tile_b, 2)
    cart = tf.concat([tile_a, tile_b], axis=2)
    return cart

result = g(a.__copy__(),b.__copy__())

###END SOLUTION
if result.shape == [12,2]:
    result = tf.reshape(result, [3,4,2])

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    t = tf.one_hot(indices=labels, depth=10, on_value=0, off_value=1, axis=-1)
    n = t.numpy()
    for i in range(len(n)):
        n[i] = n[i][::-1]
    return tf.constant(n)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(x):
    ### BEGIN SOLUTION
    result = [tf.compat.as_str_any(a) for a in x]

    return result

    ### END SOLUTION
result = f(x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x):
    non_zero = tf.cast(x != 0, tf.float32)
    y = tf.reduce_sum(x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    y = y * y
    z = tf.reduce_sum(x*x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    return z-y

result = g(x.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

seed_x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(seed_x):
    tf.random.set_seed(seed_x)
    return tf.random.uniform(shape=(114,), minval=2, maxval=6, dtype=tf.int32)

result = g(seed_x)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A,B = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(A,B):
    return tf.constant(np.einsum( 'ikm, jkm-> ijk', A, B))

result = g(A.__copy__(),B.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(a):
    return tf.argmax(a,axis=1)

result = g(a.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

A,B = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(A,B):
    ### BEGIN SOLUTION
    result = tf.reduce_sum(tf.square( tf.subtract( A, B)), 1)

    return result

    ### END SOLUTION
result = f(A,B)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(~mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x,y,z = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(x,y,z):
    ### BEGIN SOLUTION
    result = tf.gather_nd(x, [y, z])

    return result

    ### END SOLUTION
result = f(x,y,z)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf
import numpy as np

A,B = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
import numpy as np
def g(A,B):
    return tf.constant(np.einsum('ijm, ikm-> ijk', A, B))

result = g(A.__copy__(),B.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

lengths = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(lengths):
    lengths = [8-x for x in lengths]
    lengths_transposed = tf.expand_dims(lengths, 1)
    range = tf.range(0, 8, 1)
    range_row = tf.expand_dims(range, 0)
    mask = tf.less(range_row, lengths_transposed)
    result = tf.where(mask, tf.ones([4, 8]), tf.zeros([4, 8]))
    return result

result = g(lengths.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    t = tf.one_hot(indices=labels, depth=10, on_value=1, off_value=0, axis=-1)
    n = t.numpy()
    for i in range(len(n)):
        n[i] = n[i][::-1]
    return tf.constant(n)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x,y,z = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x,y,z):
    return tf.gather_nd(x, [y, z])

result = g(x.__copy__(),y.__copy__(),z.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a,b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(a,b):
    ### BEGIN SOLUTION
    tile_a = tf.tile(tf.expand_dims(a, 1), [1, tf.shape(b)[0]])
    tile_a = tf.expand_dims(tile_a, 2)
    tile_b = tf.tile(tf.expand_dims(b, 0), [tf.shape(a)[0], 1])
    tile_b = tf.expand_dims(tile_b, 2)
    cart = tf.concat([tile_a, tile_b], axis=2)
    result = cart

    return result

    ### END SOLUTION
result = f(a,b)
if result.shape == [12,2]:
    result = tf.reshape(result, [3,4,2])

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

labels = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(labels):
    return tf.one_hot(indices=labels, depth=10, on_value=0, off_value=1, axis=-1)

result = g(labels.copy())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(a):
    ### BEGIN SOLUTION
    result = tf.argmax(a,axis=1)

    return result

    ### END SOLUTION
result = f(a)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

seed_x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(seed_x):
    tf.random.set_seed(seed_x)
    return tf.random.uniform(shape=(10,), minval=1, maxval=5, dtype=tf.int32)

result = g(seed_x)

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(x):
    ### BEGIN SOLUTION
    non_zero = tf.cast(x != 0, tf.float32)
    y = tf.reduce_sum(x, axis=-2) / tf.reduce_sum(non_zero, axis=-2)
    result = y

    return result

    ### END SOLUTION
result = f(x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

input = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
tf.compat.v1.disable_eager_execution()
def f(input):
    ### BEGIN SOLUTION
    ds = tf.data.Dataset.from_tensor_slices(input)
    ds = ds.flat_map(lambda x: tf.data.Dataset.from_tensor_slices([x, x + 1, x + 2]))
    element = tf.compat.v1.data.make_one_shot_iterator(ds).get_next()

    result = []
    with tf.compat.v1.Session() as sess:
        for _ in range(9):
            result.append(sess.run(element))

    return result

    ### END SOLUTION
result = f(input)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import tensorflow as tf

x,row,col = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
###BEGIN SOLUTION
def g(x,row,col):
    index = [[row[i],col[i]] for i in range(len(row))]
    return tf.gather_nd(x, index)

result = g(x.__copy__(),row.__copy__(),col.__copy__())

###END SOLUTION

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as f:
    pickle.dump(result, f)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import torch
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
a_np = a.numpy()

#print(a_np)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(a_np, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.diag(np.fliplr(a))

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, p = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.percentile(a, p)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, pos, element = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(a, pos=2, element = 66):
    a = np.insert(a, pos, element)

    return a

result = f(a, pos, element)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
im = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
mask = im == 0
rows = np.flatnonzero((~mask).sum(axis=1))
cols = np.flatnonzero((~mask).sum(axis=0))
if rows.shape[0] == 0:
    result = np.array([])
else:
    result = im[rows.min():rows.max()+1, cols.min():cols.max()+1]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
arr, shape = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(arr, shape=(93,13)):
    result = np.pad(arr, ((0, shape[0]-arr.shape[0]), (0, shape[1]-arr.shape[1])), 'constant')

    return result

result = f(arr, shape)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = True
for arr in a:
    if any(np.isnan(arr)) == False:
        result = False
        break

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
np.random.seed(0)
r_old = np.random.randint(3, size=(100, 2000)) - 1
np.random.seed(0)
r_new = np.random.randint(3, size=(100, 2000)) - 1
#print(r_old, r_new)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump([r_old, r_new], file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
import pandas as pd
a, df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
df = pd.DataFrame(df.values - a[:, None], df.index, df.columns)

#print(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(df, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
A, nrow = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
B = np.reshape(A, (nrow, -1))

#print(B)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(B, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
pairs, array_of_arrays = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))

import copy
result = copy.deepcopy(array_of_arrays)
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
result = np.array([])

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
grades, threshold = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def ecdf_result(x):
    xs = np.sort(x)
    ys = np.arange(1, len(xs)+1)/float(len(xs))
    return xs, ys
resultx, resulty = ecdf_result(grades)
t = (resulty > threshold).argmax()
low = resultx[0]
high = resultx[t]
#print(low, high)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump([low, high], file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
A, B = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
C = A[np.logical_and(A > B[0], A < B[1]) | np.logical_and(A > B[1], A < B[2])]

#print(C)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(C, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
a = np.delete(a, 2, axis = 0)

#print(a)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(a, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
X = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = []
for value in X.flat:
    result.append(value)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
dim, a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.triu(np.linalg.norm(a - a[:, None], axis = -1))

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
x = x[~np.isnan(x)]

#print(x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(x, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, patch_size = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
x = a[:a.shape[0] // patch_size * patch_size, :a.shape[1] // patch_size * patch_size]
result = x.reshape(x.shape[0]//patch_size, patch_size, x.shape[1]// patch_size, patch_size).swapaxes(1, 2). reshape(-1, patch_size, patch_size)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
sort_indices = np.argsort(a, axis=0)[::-1, :, :]
static_indices = np.indices(a.shape)
c = b[sort_indices, static_indices[1], static_indices[2]]

#print(c)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(c, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
n = 20
m = 10
tag = np.random.rand(n, m)
s1, s2 = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = (~np.isclose(s1,s2, equal_nan=True)).sum()

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.take_along_axis(a, b[..., np.newaxis], axis=-1)[..., 0]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
x_dists, y_dists = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
dists = np.vstack(([x_dists.T], [y_dists.T])).T

#print(dists)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(dists, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = x[x >=0]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
Z = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = Z[..., -1:]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np

numerator, denominator = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
gcd = np.gcd(numerator, denominator)
result = (numerator//gcd, denominator//gcd)
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
import pandas as pd
lat, lon, val = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
df = pd.DataFrame({'lat': lat.ravel(), 'lon': lon.ravel(), 'val': val.ravel()})
df['maximum'] = df.max(axis=1)

#print(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(df, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
A, NA = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
AVG = np.mean(NA.astype(float), axis = 0)

#print(AVG)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(AVG, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
b = np.zeros((a.size, a.max()+1))
b[np.arange(a.size), a]=1

#print(b)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(b, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, b = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
arr = np.take_along_axis(a, b[..., np.newaxis], axis=-1)[..., 0]
result = np.sum(arr)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, low, high = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = a[low:high, :]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
data, bin_size = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
new_data = data[:, ::-1]
bin_data_mean = new_data[:,:(data.shape[1] // bin_size) * bin_size].reshape(data.shape[0], -1, bin_size).mean(axis=-1)

#print(bin_data_mean)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(bin_data_mean, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
import pandas as pd
lat, lon, val = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
df = pd.DataFrame({'lat': lat.ravel(), 'lon': lon.ravel(), 'val': val.ravel()})

#print(df)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(df, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.lib.stride_tricks.sliding_window_view(a, window_shape=(2,2)).reshape(-1, 2, 2)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = a.argmin()

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, index = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
add = np.max(index)
mask =index < 0
index[mask] += add+1
uni = np.unique(index)
result = np.zeros(np.amax(index)+1)
for i in uni:
    result[i] = np.min(a[index==i])

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, second, third = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = a[:, np.array(second).reshape(-1,1), third]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, shift = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def solution(xs, shift):
    e = np.empty_like(xs)
    for i, n in enumerate(shift):
        if n >= 0:
            e[i,:n] = np.nan
            e[i,n:] = xs[i,:-n]
        else:
            e[i,n:] = np.nan
            e[i,:n] = xs[i,-n:]
    return e
result = solution(a, shift)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
arr = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = arr.copy()
arr[np.where(result < -10)] = 0
arr[np.where(result >= 15)] = 30
arr[np.logical_and(result >= -10, result < 15)] += 5

#print(arr)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(arr, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = a.argmax()

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
temp = np.array([0, 2])
a = np.delete(a, temp, axis = 1)

#print(a)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(a, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
x, x_min, x_max = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def smoothclamp(x):
    return np.where(x < x_min, x_min, np.where(x > x_max, x_max, 3*x**2 - 2*x**3))

result = smoothclamp(x)
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
from scipy.stats import rankdata
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = len(a) - rankdata(a).astype(int)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
x, y, degree = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.polyfit(x, y, degree)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
vals, idx = np.unique(a, return_inverse=True)
b = np.zeros((a.size, vals.size))
b[np.arange(a.size), idx] = 1
#print(b)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(b, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
selection = np.ones((len(a), 1), dtype = bool)
selection[1:] = a[1:] != a[:-1]
selection &= a != 0
result = a[selection].reshape(-1, 1)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
from scipy.stats import rankdata
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = len(a) - rankdata(a, method = 'ordinal').astype(int)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.unravel_index(a.argmax(), a.shape)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, number = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
is_contained = number in a

#print(is_contained)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(is_contained, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
arr = np.zeros((20,10,10,2))

#print(arr)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(arr, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
from numpy import linalg as LA
import numpy as np
X = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
l2 = np.sqrt((X*X).sum(axis=-1))
result = X / l2.reshape(-1, 1)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(a):
    result = a.argmax()

    return result

result = f(a)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, del_col = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
mask = (del_col <= a.shape[1])
del_col = del_col[mask] - 1
result = np.delete(a, del_col, axis=1)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.einsum('ii->i', a)
save = result.copy()
a[...] = 0
result[...] = save

#print(a)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(a, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
data, bin_size = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
new_data = data[::-1]
bin_data_mean = new_data[:(data.size // bin_size) * bin_size].reshape(-1, bin_size).mean(axis=1)

#print(bin_data_mean)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(bin_data_mean, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = x[x.imag !=0]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))

selection = np.ones(len(a), dtype = bool)
selection[1:] = a[1:] != a[:-1]
selection &= a != 0
result = a[selection]

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = (a.mean()-3*a.std(), a.mean()+3*a.std())

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, power = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(a, power):
    result = a ** power

    return result

result = f(a, power)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, shape, element = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.pad(a, ((0, shape[0]-a.shape[0]), (0, shape[1]-a.shape[1])), 'constant', constant_values=element)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a, b, c = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.max([a, b, c], axis=0)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
A, ncol = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
col = ( A.shape[0] // ncol) * ncol
B = A[:col]
B= np.reshape(B, (-1, ncol))

#print(B)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(B, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
import pandas as pd
names, times, df = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = df.values.reshape(15, 5, 4).transpose(0, 2, 1)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
degree = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.sin(np.deg2rad(degree))

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.linalg.norm(a - a[:, None], axis = -1)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.unravel_index(a.argmax(), a.shape, order = 'F')

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
data, bin_size = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
bin_data_mean = data[:,:(data.shape[1] // bin_size) * bin_size].reshape(data.shape[0], -1, bin_size).mean(axis=-1)

#print(bin_data_mean)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(bin_data_mean, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = a.shape

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
value = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.degrees(np.arcsin(value))

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.diag(np.fliplr(a))

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
A, length = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
if length > A.shape[0]:
    result = np.pad(A, (0, length-A.shape[0]), 'constant')
else:
    result = A.copy()
    result[length:] = 0

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
x = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
x[np.isnan(x)] = np.inf

#print(x)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(x, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np

min, max, n = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def f(min=1, max=np.e, n=10000):
    import scipy.stats
    result = scipy.stats.loguniform.rvs(a = min, b = max, size = n)

    return result

result = f(min, max, n)
with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
def all_equal(iterator):
    try:
        iterator = iter(iterator)
        first = next(iterator)
        return all(np.array_equal(first, rest) for rest in iterator)
    except StopIteration:
        return True
result = all_equal(a)
#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = np.argsort(a)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
result = a.reshape(a.shape[0]//2, 2, a.shape[1]//2, 2).swapaxes(1, 2).transpose(1, 0, 2, 3).reshape(-1, 2, 2)

#print(result)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(result, file)


import pickle

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test_case", type=int, default=1)
args = parser.parse_args()
import numpy as np
a = pickle.load(open(f"input/input{args.test_case}.pkl", "rb"))
U, i, V = np.linalg.svd(a,full_matrices=True)

i = np.diag(i)

#print(i)

with open('result/result_{}.pkl'.format(args.test_case), 'wb') as file:
    pickle.dump(i, file)