# Coefficients and constants of the equations
A <- matrix(c(3, 2, 1, 1, -1, 2, 4, 2, 2), nrow = 3, byrow = TRUE)
B <- c(1, 2, 2)

# Solve the overdetermined system of equations using least squares
solution <- lm.fit(A, B)

# Extract the values of x and y from the solution
x <- solution$coefficients[1]
y <- solution$coefficients[2]

# Display the results
print(paste("Solution for x =", x))
## [1] "Solution for x = 1"
print(paste("Solution for y =", y))
## [1] "Solution for y = -1"