import numpy as np N, P = map(int, input().split()) abc = [[int(_) for _ in input().split()] for _ in range(N)] dp = np.zeros([2, P+3], dtype=int) for i in range(1, N+1): if i % 2 == 1: dp[1][0] = dp[0][0] + abc[i-1][0] dp[1][1] = min(dp[0][1] + abc[i-1][0], dp[0][0] + abc[i-1][1]) dp[1][2] = min(dp[0][2]+abc[i-1][0], dp[0][1]+abc[i-1][1], dp[0][0]+abc[i-1][2]) dp[1][3:] = np.minimum(np.minimum(np.minimum(dp[0][:-3]+1, dp[0][1:-2]+abc[i-1][2]), dp[0][2:-1]+abc[i-1][1]), dp[0][3:]+abc[i-1][0]) else: dp[0][0] = dp[0][0] + abc[i-1][0] dp[0][1] = min(dp[0][1] + abc[i-1][0], dp[0][0] + abc[i-1][1]) dp[0][2] = min(dp[0][2]+abc[i-1][0], dp[0][1]+abc[i-1][1], dp[0][0]+abc[i-1][2]) dp[0][3:] = np.minimum(np.minimum(np.minimum(dp[0][:-3]+1, dp[0][1:-2]+abc[i-1][2]), dp[0][2:-1]+abc[i-1][1]), dp[0][3:]+abc[i-1][0]) print(dp[N%2][P]/N)