# M1.py
import os
import math

def func1(filename, KK):
    numbers = []
    f = open(filename, 'r')
    for line in f:
        parts = line.split()
        for p in parts:
            numbers.append(float(p))
    f.close()

    base, ext = os.path.splitext(filename)
    f1 = open(base + '1' + ext, 'w')
    f2 = open(base + '2' + ext, 'w')
    
    for x in numbers:
        if x > KK:
            f1.write(str(x) + '\n')
        else:
            f2.write(str(x) + '\n')
    
    f1.close()
    f2.close()
    return numbers


def func2(filename):
    numbers = []
    f = open(filename, 'r')
    for line in f:
        parts = line.split()
        for p in parts:
            numbers.append(float(p))
    f.close()

    if len(numbers) == 0:
        return 0, 0, 0, 0, 0  # пустой файл

    n = len(numbers)
    mean = sum(numbers) / n
    min_val = min(numbers)
    max_val = max(numbers)
    std_dev = math.sqrt(sum((x - mean) ** 2 for x in numbers) / n)

    sorted_nums = sorted(numbers)
    if n % 2 == 1:
        median = sorted_nums[n // 2]
    else:
        median = (sorted_nums[n // 2 - 1] + sorted_nums[n // 2]) / 2

    return mean, median, min_val, max_val, std_dev
