function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function printValues() {
	var parts = [];
	for (var i = 0; i < arguments.length; i += 2) {
		parts.push(arguments[i]+' = '+arguments[i+1]);
	}
	print(parts.join(', '));
}

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1], k = data[2],
		values = tokenizeIntegers(readline()),
		span = 0, spans = [];
	for (var i = 0; i < m; ++i) {
		span += values[i];
		spans.push(0);
	}
	spans.push(span);
	for (var i = m; i < n; ++i) {
		span += values[i] - values[i-m];
		spans.push(span);
	}
	var previous = [], current = [];
	for (var i = 0; i <= n; ++i) {
		previous.push(0);
		current.push(0);
	}
	for (var i = 0; i < k; ++i) {
		var t = previous;
		previous = current;
		current = t;
		var prefix = 0;
		for (var j = m; j <= n; ++j) {
			prefix = Math.max(prefix, previous[j-m]);
			current[j] = prefix + spans[j];
		}
	}
	var best = 0;
	for (var i = 1; i <= n; ++i) {
		best = Math.max(best, current[i]);
	}
	print(best);
}

main();

function ProblemSolver() {

    this.solveCase = function() {
        var res , i , j , fl , a , b , c , d , e , cur , hand , other;
        res = 0;
        for( i = 0 ; i < this.n ; i++ ) {
            if( i == 0 ) {
                this.brr[ i ] = this.arr[ i ];
            }
            else {
                this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];
            }
        }
        cur = 0 ;
        other = 1 ;
        for( j = 0 ; j < this.k ; j++ ) {
            hand = 0 ;
            for( i = 0 ; i < this.n ; i++ ) {
                this.memo[ i ][ cur ] = 0;
            }
            for( i = 0 ; i < this.n ; i++ ) {
                b = 0 ;
                if( i - 1 >= 0 ) {
                    b = this.brr[ i - 1 ] ;
                }
                if( i + this.m - 1 < this.n ) {
                    a = this.brr[ i + this.m - 1 ] - b ;
                    c = hand + a ;
                    this.memo[ i + this.m - 1 ][ cur ] = Math.max( this.memo[ i + this.m - 1 ][ cur ] , c ) ;
                }
                hand = Math.max( hand , this.memo[ i ][ other ] ) ;
            }
            cur = ( cur + 1 ) % 2 ;
            other = ( other + 1 ) % 2 ;
        }
        for( i = 0 ; i < this.n ; i++ ) {
            res = Math.max( res , this.memo[ i ][ other ] ) ;
        }
        print( res );
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            this.m = irObj.nextInt();
            this.k = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i , j;
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.vis = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.memo.push( new Array() );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.vis.push( 0 );
            this.adj_list.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( 0 );
            }
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        this.clearArraysPerCase();
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init = function() {
        this.lim1 = 5010;
        this.lim2 = 2;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx , lengthType;
        len = this.allLines[ this.currrentLineNumber ].length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = this.allLines[ this.currrentLineNumber ].length();
        }
        if( flag == 0 ) {
            res = "";
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\t'.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = -1;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\t'.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            if( endIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            else {
                this.currrentCharacterIndex = endIdx;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        if( currentDirectory.charAt( 1 ) != ":" ) {
            //not local machine/windows
            outputFilePath = outputFileName;
        }
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();

function ProblemSolver() {

    this.solveCase = function() {
        var res , i , j , fl , a , b , c , d , e , cur , hand , other;
        res = 0;
        for( i = 0 ; i < this.n ; i++ ) {
            if( i == 0 ) {
                this.brr[ i ] = this.arr[ i ];
            }
            else {
                this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];
            }
        }
        cur = 0 ;
        other = 1 ;
        for( j = 0 ; j < this.k ; j++ ) {
            hand = 0 ;
            this.memo[ i ][ cur ] = 0 ;
            for( i = 0 ; i < this.n ; i++ ) {
                b = 0 ;
                if( i - 1 >= 0 ) {
                    b = this.brr[ i - 1 ] ;
                }
                if( i + this.m - 1 < this.n ) {
                    a = this.brr[ i + this.m - 1 ] - b ;
                    c = hand + a ;
                    this.memo[ i ][ cur ] = Math.max( this.memo[ i ][ cur ] , c ) ;
                }
                hand = Math.max( hand , this.memo[ i ][ other ] ) ;
            }
            cur = ( cur + 1 ) % 2 ;
            other = ( other + 1 ) % 2 ;
        }
        for( i = 0 ; i < this.n ; i++ ) {
            res = Math.max( res , this.memo[ i ][ other ] ) ;
        }
        print( res );
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            this.m = irObj.nextInt();
            this.k = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i , j;
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.vis = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.memo.push( new Array() );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.vis.push( 0 );
            this.adj_list.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( 0 );
            }
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        this.clearArraysPerCase();
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init = function() {
        this.lim1 = 5010;
        this.lim2 = 2;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx , lengthType;
        len = this.allLines[ this.currrentLineNumber ].length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = this.allLines[ this.currrentLineNumber ].length();
        }
        if( flag == 0 ) {
            res = "";
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\t'.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = -1;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\t'.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            if( endIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            else {
                this.currrentCharacterIndex = endIdx;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        if( currentDirectory.charAt( 1 ) != ":" ) {
            //not local machine/windows
            outputFilePath = outputFileName;
        }
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();

function ProblemSolver() {

    this.solveCase = function() {
        var res , i , j , fl , a , b , c , d , e;
        res = 0;
        for( i = 0 ; i < this.n ; i++ ) {
            if( i == 0 ) {
                this.brr[ i ] = this.arr[ i ];
            }
            else {
                this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];
            }
        }
        e = 0;
        while( true ) {
            c = -1;
            d = -1;
            for( i = 0 ; i < this.n ; i++ ) {
                a = 0;
                b = 0;
                for( j = i ; j < i + this.m ; j++ ) {
                    if( this.vis[ j ] == 1 ) {
                        break;
                    }
                    b += this.arr[ j ];
                    a++;
                }
                if( a == this.m ) {
                    if( b > c ) {
                        d = i;
                        c = b;
                    }
                }
            }
            if( c == -1 ) {
                break;
            }
            for( j = d ; j < d + this.m ; j++ ) {
                this.vis[ j ] = 1;
            }
            res += c;
            e++;
            if( e >= this.k ) {
                break;
            }
        }
        print( res );
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            this.m = irObj.nextInt();
            this.k = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.brr = new Array();
        this.vis = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.vis.push( 0 );
            this.adj_list.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        this.clearArraysPerCase();
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init = function() {
        this.lim1 = 100010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx , lengthType;
        len = this.allLines[ this.currrentLineNumber ].length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = this.allLines[ this.currrentLineNumber ].length();
        }
        if( flag == 0 ) {
            res = "";
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\t'.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = -1;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\t'.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            if( endIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            else {
                this.currrentCharacterIndex = endIdx;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        if( currentDirectory.charAt( 1 ) != ":" ) {
            //not local machine/windows
            outputFilePath = outputFileName;
        }
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();

function ProblemSolver() {

    this.solveCase = function() {
        var res , i , j , fl , a , b , c , d , e , cur , hand , other;
        res = 0;
        for( i = 0 ; i < this.n ; i++ ) {
            if( i == 0 ) {
                this.brr[ i ] = this.arr[ i ];
            }
            else {
                this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];
            }
        }
        cur = 0 ;
        other = 1 ;
        for( j = 0 ; j < this.k ; j++ ) {
            hand = 0 ;
            for( i = 0 ; i < this.n ; i++ ) {
                this.memo[ i ][ cur ] = 0 ;
                b = 0 ;
                if( i - 1 >= 0 ) {
                    b = this.brr[ i - 1 ] ;
                }
                if( i + this.m - 1 < this.n ) {
                    a = this.brr[ i + this.m - 1 ] - b ;
                    c = hand + a ;
                    this.memo[ i ][ cur ] = Math.max( this.memo[ i ][ cur ] , c ) ;
                }
                hand = Math.max( hand , this.memo[ i ][ other ] ) ;
            }
            cur = ( cur + 1 ) % 2 ;
            other = ( other + 1 ) % 2 ;
        }
        for( i = 0 ; i < this.n ; i++ ) {
            res = Math.max( res , this.memo[ i ][ other ] ) ;
        }
        print( res );
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            this.m = irObj.nextInt();
            this.k = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i , j;
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.vis = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.memo.push( new Array() );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.vis.push( 0 );
            this.adj_list.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( 0 );
            }
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        this.clearArraysPerCase();
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init = function() {
        this.lim1 = 5010;
        this.lim2 = 2;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx , lengthType;
        len = this.allLines[ this.currrentLineNumber ].length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = this.allLines[ this.currrentLineNumber ].length();
        }
        if( flag == 0 ) {
            res = "";
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\t'.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = -1;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\t'.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            if( endIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            else {
                this.currrentCharacterIndex = endIdx;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        if( currentDirectory.charAt( 1 ) != ":" ) {
            //not local machine/windows
            outputFilePath = outputFileName;
        }
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();

function ProblemSolver() {

    this.solveCase = function() {
        var res , i , j , fl , a , b , c , d , e , cur , hand , other;
        res = 0;
        for( i = 0 ; i < this.n ; i++ ) {
            if( i == 0 ) {
                this.brr[ i ] = this.arr[ i ];
            }
            else {
                this.brr[ i ] = this.brr[ i - 1 ] + this.arr[ i ];
            }
        }
        cur = 0 ;
        other = 1 ;
        for( j = 0 ; j < this.k ; j++ ) {
            hand = 0 ;
            this.memo[ i ][ cur ] = this.memo[ i ][ other ] ;
            for( i = 0 ; i < this.n ; i++ ) {
                b = 0 ;
                if( i - 1 >= 0 ) {
                    b = this.brr[ i - 1 ] ;
                }
                if( i + this.m - 1 < this.n ) {
                    a = this.brr[ i + this.m - 1 ] - b ;
                    c = hand + a ;
                    this.memo[ i ][ cur ] = Math.max( this.memo[ i ][ cur ] , c ) ;
                }
                hand = Math.max( hand , this.memo[ i ][ other ] ) ;
            }
            cur = ( cur + 1 ) % 2 ;
            other = ( other + 1 ) % 2 ;
        }
        for( i = 0 ; i < this.n ; i++ ) {
            res = Math.max( res , this.memo[ i ][ 0 ] ) ;
            res = Math.max( res , this.memo[ i ][ 1 ] ) ;
        }
        print( res );
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            this.m = irObj.nextInt();
            this.k = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i , j;
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.vis = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.memo.push( new Array() );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.vis.push( 0 );
            this.adj_list.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( 0 );
            }
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        this.clearArraysPerCase();
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init = function() {
        this.lim1 = 5010;
        this.lim2 = 2;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx , lengthType;
        len = this.allLines[ this.currrentLineNumber ].length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = this.allLines[ this.currrentLineNumber ].length();
        }
        if( flag == 0 ) {
            res = "";
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\t'.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = -1;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\t'.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            if( endIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            else {
                this.currrentCharacterIndex = endIdx;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        if( currentDirectory.charAt( 1 ) != ":" ) {
            //not local machine/windows
            outputFilePath = outputFileName;
        }
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();


var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

const INF = 1e10;

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, k] = rna();
		const a = rna();
		const t = rna();

		const tmps = Array(n).fill(INF);
		for (let i = 0; i < k; i++) {
			--a[i];
			tmps[a[i]] = t[i];
		}

		const ans = Array(n).fill(INF); ans[-1] = ans[n] = INF;
		for (let i = 0; i < n; i++) {
			ans[i] = Math.min(ans[i-1] + 1, tmps[i]);
		}
		for (let i = n-1; i >= 0; i--) {
			ans[i] = Math.min(ans[i], ans[i+1] + 1);
		}

		console.log(ans.slice(0, n).join(' '));
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

const INF = 1e10;

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, k] = rna();
		const a = rna();
		const t = rna();

		const ans = Array(n).fill(INF);
		for (let i = 0; i < k; i++) {
			--a[i]; ans[a[i]] = t[i];
		}

		ans[-1] = ans[n] = INF;
		for (let i = 0; i < n; i++) {
			ans[i] = Math.min(ans[i], ans[i-1] + 1);
		}
		for (let i = n-1; i >= 0; i--) {
			ans[i] = Math.min(ans[i], ans[i+1] + 1);
		}

		console.log(ans.slice(0, n).join(' '));
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

const INF = 1e10;

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, k] = rna();
		const a = rna();
		const t = rna();

		const tmps = Array(n).fill(INF);
		for (let i = 0; i < k; i++) {
			--a[i];
			tmps[a[i]] = t[i];
		}

		const ans = [];
		for (let i = 0, cur = INF; i < n; i++) {
			cur = Math.min(++cur, tmps[i]);
			ans[i] = cur;
		}
		for (let i = n-1, cur = INF; i >= 0; i--) {
			cur = Math.min(++cur, tmps[i]);
			ans[i] = Math.min(cur, ans[i]);
		}

		console.log(ans.join(' '));
	}
}

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.
const INT = Math.floor;
Array.prototype.last = function () {
    return this.length === 0 ? undefined : this[this.length - 1];
};
Array.prototype.isEmpty = function () {
    return this.length === 0;
};
const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);
const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);
const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
const bigIntAbs = (arg) => (arg < 0 ? -arg : arg);
function read_stdin() {
    return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');
}
class Input {
    constructor(str) {
        this.index = 0;
        this.inputs = (str ? str : read_stdin()).split(/\s+/);
    }
    number() {
        return Number(this.inputs[this.index++]);
    }
    numbers(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(Number);
    }
    bigint() {
        return BigInt(this.inputs[this.index++]);
    }
    bigints(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(BigInt);
    }
    word() {
        return this.inputs[this.index++];
    }
    words(n) {
        return this.inputs.slice(this.index, (this.index += n));
    }
}
function array(len, init) {
    return Array(len).fill(init);
}
function array2(h, w, init) {
    return array(h, 0).map(() => array(w, init));
}
class FixedDeque {
    constructor(half_size) {
        this.ary = Array(half_size * 2 + 1).fill(undefined);
        this.head = this.tail = half_size;
    }
    first() {
        return this.head === this.tail ? undefined : this.ary[this.head];
    }
    last() {
        return this.head === this.tail ? undefined : this.ary[this.tail - 1];
    }
    at(i) {
        return this.head + i < this.tail ? this.ary[this.head + i] : undefined;
    }
    isEmpty() {
        return this.head === this.tail;
    }
    unshift(value) {
        this.ary[--this.head] = value;
    }
    shift() {
        return this.head === this.tail ? undefined : this.ary[this.head++];
    }
    push(value) {
        this.ary[this.tail++] = value;
    }
    pop() {
        return this.head === this.tail ? undefined : this.ary[--this.tail];
    }
    toArray() {
        return this.ary.slice(this.head, this.tail);
    }
    [Symbol.iterator]() {
        let pos = this.head;
        const tail = this.tail;
        const ary = this.ary;
        return {
            next() {
                const done = pos === tail;
                return {
                    value: done ? undefined : ary[pos++],
                    done,
                };
            },
        };
    }
}
class Queue {
    constructor() {
        this.elems = [];
        this.head = 0;
    }
    push(elem) {
        this.elems.push(elem);
    }
    dequeue() {
        if (this.head < this.elems.length) {
            return this.elems[this.head++];
        }
        return undefined;
    }
    isEmpty() {
        return this.head >= this.elems.length;
    }
}
function main() {
    const input = new Input();
    const q = input.number();
    const ans = Array(q);
    for (let i = 0; i < q; i++) {
        const n = input.number();
        const k = input.number();
        const A = Array(k);
        for (let j = 0; j < k; j++) {
            A[j] = input.number() - 1;
        }
        const T = input.numbers(k);
        const cools = Array(k);
        for (let j = 0; j < k; j++) {
            cools[j] = { a: A[j], t: T[j] };
        }
        cools.sort((a, b) => a.a - b.a);
        for (let j = 0; j < k; j++) {
            A[j] = cools[j].a;
            T[j] = cools[j].t;
        }
        const lefts = new FixedDeque(k + 1);
        let right = Infinity;
        const rights = array(n, Infinity);
        for (let j = 0; j < k; j++) {
            rights[A[j]] = T[j] - A[j];
            const y = A[j] + T[j];
            // console.log({ i: A[j], y })
            while (!lefts.isEmpty() && lefts.last().y > y) {
                lefts.pop();
            }
            lefts.push({ i: A[j], y });
        }
        const ts = Array(n);
        for (let j = 0; j < n; j++) {
            let min = Infinity;
            const left = lefts.first();
            if (left !== undefined) {
                min = left.y - j;
            }
            if (right !== Infinity) {
                min = Math.min(min, right + j);
            }
            // console.log({ j, left, right, min })
            ts[j] = min;
            if (left !== undefined && left.i === j) {
                lefts.shift();
            }
            if (rights[j] < right) {
                right = rights[j];
            }
        }
        ans[i] = ts;
    }
    console.log(ans.map((ts) => ts.join(' ')).join('\n'));
}
main();
//# sourceMappingURL=aoj.js.map

'use strict';

function solve(n, m, a, b) {
  a = a.map(num => num - 1);
  const l = new Array(n).fill(Infinity),
        r = new Array(n).fill(Infinity);
  for (let i = 0; i < m; i++) {
    const j = a[i];
    l[j] = Math.min(l[j], b[i]);
    r[j] = Math.min(r[j], b[i]);
  }
  for (let i = 1; i < n; i++) {
    l[i] = Math.min(l[i - 1] + 1, l[i]);
  }
  for (let i = n - 2; i >= 0; i--) {
    r[i] = Math.min(r[i + 1] + 1, r[i]);
  }
  const res = new Array(n);
  for (let i = 0; i < n; i++) res[i] = Math.min(l[i], r[i]);
  return res.join(' ');
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      await read();
      const [n, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      const b = (await read()).split(' ').map(Number);
      res[i] = solve(n, m, a, b);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

const INF = 2 * Math.pow(10, 9);
function solve() {
   read();
   const [n, k] = readArray(Number);
   const ind = readArray(Number);
   const arr = 'x'.repeat(n).split('').map(() => INF);
   readArray((x, i) => {
      arr[ind[i] - 1] = Number(x);
   });
   const L = [];
   L[0] = arr[0];
   for (let i = 1; i < n; i++) {
      L[i] = Math.min(arr[i], L[i - 1] + 1);
   }
   const R = [];
   R[n - 1] = arr[n - 1];
   for (let i = n - 2; i >= 0; i--) {
      R[i] = Math.min(arr[i], R[i + 1] + 1);
   }
   const ans = L.map((x, i) => Math.min(x, R[i]));
   write(ans.join(' '));
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var t = +lines[l++]
    for (var i = 0; i < t; i++) {
        l++
        var [n, k] = lines[l++].trim().split(' ').map(Number)
        var as = lines[l++].trim().split(' ').map(Number)
        var ts = lines[l++].trim().split(' ').map(Number)
        console.log(solve(n, k, as, ts))
    }
});

function solve(n, k, as, ts) {
    const sorted = as.map((a, i) => ({
        i: a,
        t: ts[i],
        f: ts[i] + a - 1 // t at pos 0
    }))
        .sort((a, b) => a.f - b.f)
// console.log(sorted)
    const r = []
    let cur = 0
    let next = 1
    for (let i = 1; i <= n; i++) {
        if (i <= sorted[cur].i) {
            r.push(sorted[cur].t + sorted[cur].i - i)
        } else {
            while (next < k && sorted[next].i < i) {
                next++
            }
            while (1) {
                const t1 = sorted[cur].t + Math.abs(i - sorted[cur].i)
                if (next >= k) {
                    r.push(t1)
                    break
                }
                const t2 = sorted[next].t + sorted[next].i - i
                if (t1 <= t2) {
                    r.push(t1)
                    break
                }
                cur = next++
            }
        }
        // console.log(i, cur)
    }
    return r.join(' ')
}

function _toConsumableArray(arr) {
  return (
    _arrayWithoutHoles(arr) ||
    _iterableToArray(arr) ||
    _unsupportedIterableToArray(arr) ||
    _nonIterableSpread()
  );
}

function _nonIterableSpread() {
  throw new TypeError(
    "Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
  );
}

function _iterableToArray(iter) {
  if (
    (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null) ||
    iter["@@iterator"] != null
  )
    return Array.from(iter);
}

function _arrayWithoutHoles(arr) {
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}

function _newArrowCheck(innerThis, boundThis) {
  if (innerThis !== boundThis) {
    throw new TypeError("Cannot instantiate an arrow function");
  }
}

function _slicedToArray(arr, i) {
  return (
    _arrayWithHoles(arr) ||
    _iterableToArrayLimit(arr, i) ||
    _unsupportedIterableToArray(arr, i) ||
    _nonIterableRest()
  );
}

function _nonIterableRest() {
  throw new TypeError(
    "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
  );
}

function _unsupportedIterableToArray(o, minLen) {
  if (!o) return;
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  var n = Object.prototype.toString.call(o).slice(8, -1);
  if (n === "Object" && o.constructor) n = o.constructor.name;
  if (n === "Map" || n === "Set") return Array.from(o);
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
    return _arrayLikeToArray(o, minLen);
}

function _arrayLikeToArray(arr, len) {
  if (len == null || len > arr.length) len = arr.length;
  for (var i = 0, arr2 = new Array(len); i < len; i++) {
    arr2[i] = arr[i];
  }
  return arr2;
}

function _iterableToArrayLimit(arr, i) {
  var _i =
    arr == null
      ? null
      : (typeof Symbol !== "undefined" && arr[Symbol.iterator]) ||
        arr["@@iterator"];
  if (_i == null) return;
  var _arr = [];
  var _n = true;
  var _d = false;
  var _s, _e;
  try {
    for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
      _arr.push(_s.value);
      if (i && _arr.length === i) break;
    }
  } catch (err) {
    _d = true;
    _e = err;
  } finally {
    try {
      if (!_n && _i["return"] != null) _i["return"]();
    } finally {
      if (_d) throw _e;
    }
  }
  return _arr;
}

function _arrayWithHoles(arr) {
  if (Array.isArray(arr)) return arr;
}

var q = parseInt(readline());
readline();

var _loop = function _loop(i) {
  var _this = this;

  var _readline$split$map = readline()
      .split(" ")
      .map(
        function (y) {
          _newArrowCheck(this, _this);

          return parseInt(y);
        }.bind(this)
      ),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    lengthOfStrip = _readline$split$map2[0],
    noOfAC = _readline$split$map2[1];

  var positionsOfAC = readline()
    .split(" ")
    .map(
      function (y) {
        _newArrowCheck(this, _this);

        return parseInt(y);
      }.bind(this)
    );
  var temperatureAC = readline()
    .split(" ")
    .map(
      function (y) {
        _newArrowCheck(this, _this);

        return parseInt(y);
      }.bind(this)
    );
  var temperatureAtPosition = new Array(lengthOfStrip).fill(Infinity);
  var temperatureFromleft = new Array(lengthOfStrip).fill(Infinity);
  var temperatureFromRight = new Array(lengthOfStrip).fill(Infinity);

  for (var _i2 = 0; _i2 < noOfAC; _i2++) {
    temperatureAtPosition[positionsOfAC[_i2] - 1] = temperatureAC[_i2];
  }

  temperatureFromleft[0] = temperatureAtPosition[0];
  temperatureFromRight[lengthOfStrip - 1] =
    temperatureAtPosition[lengthOfStrip - 1]; //  compute left

  for (var j = 1; j < lengthOfStrip; j++) {
    temperatureFromleft[j] = Math.min(
      temperatureFromleft[j - 1] + 1,
      temperatureAtPosition[j]
    );
  } //   compute right

  for (var _j = lengthOfStrip - 2; _j >= 0; _j--) {
    temperatureFromRight[_j] = Math.min(
      temperatureFromRight[_j + 1] + 1,
      temperatureAtPosition[_j]
    );
  } // print(temperatureFromleft)
  // print(temperatureFromRight)

  var finalTemp = _toConsumableArray(new Array(lengthOfStrip)).map(
    function (_, index) {
      _newArrowCheck(this, _this);

      return Math.min(temperatureFromleft[index], temperatureFromRight[index]);
    }.bind(this)
  ); // print(finalTemp)

  print(finalTemp.join(" "));
  readline();
};

for (var i = 0; i < q; i++) {
  _loop(i);
}