Identify the time complexity of the following code as constant, linear, quadratic, cubic, log(n), nlog(n) or NP-hard. import java.io.*;
import java.util.*;
 
/**
 * A simple template for competitive programming problems.
 */
public class Solution {
    //InputReader in = new InputReader("input.txt");
    final InputReader in = new InputReader(System.in);
 
    final PrintWriter out = new PrintWriter(System.out);

    int n,m;

    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        int k = in.nextInt();

        int[][] hor = new int[n][m-1];
        int[][] ver = new int[n-1][m];

        for(int i=0; i<n; i++) {
            for(int j=0; j<m-1; j++) {
                hor[i][j] = in.nextInt(); //hor[i][j]=mat[i][j] -> mat[i][j+1]
            }
        }

        for(int i=0; i<n-1; i++) {
            for(int j=0; j<m; j++) {
                ver[i][j] = in.nextInt(); //ver[i][j]= mat[i][j] -> mat[i+1][j]
            }
        }

        int[][] ans = new int[n][m];

        if(k%2==1) {
            for(int i=0; i<n; i++)
                Arrays.fill(ans[i], -1);
        } else {
            for(int dummy=0; dummy<k>>1; dummy++) {
                int[][] newAns = new int[n][m];
                for(int i=0; i<n; i++) {
                    Arrays.fill(newAns[i], Integer.MAX_VALUE);
                    for(int j=0; j<m; j++) {
                        if(isGood(i+1, j)) {
                            newAns[i][j] = Math.min(newAns[i][j], 2*ver[i][j] + ans[i+1][j]);
                        }
                        if(isGood(i, j+1)) {
                            newAns[i][j] = Math.min(newAns[i][j], 2*hor[i][j] + ans[i][j+1]);
                        }
                        if(isGood(i, j-1)) {
                            newAns[i][j] = Math.min(newAns[i][j], 2*hor[i][j-1] + ans[i][j-1]);
                        }
                        if(isGood(i-1, j)) {
                            newAns[i][j] = Math.min(newAns[i][j], 2*ver[i-1][j] + ans[i-1][j]);
                        }
                    }
                }
                ans = newAns;
            }
        }

        for(int i=0; i<n; i++) {
    ... Complexity: