var n = parseInt(readline());

var l = readline().trim().split(' ').map((x)=>parseInt(x));

var ans = 0;

var isOne = false;
var nbrOnes=0;
for(var i=0;i<n;i++){
    if(l[i]==0){
        if(nbrOnes>0)
        ans+=nbrOnes+1;
        nbrOnes=0;
        isOne = false;
    }else{
        isOne=true;
        nbrOnes++;
    }
}
if(l[n-1]==0)
    ans=ans==0?0:(ans-1);
else
    ans+=nbrOnes;
print(ans)

var n= readline();
var stateLetters= readline().replace(/\s/g,"").replace(/0/g," ");
stateLetters= stateLetters.trim();
var costoLettersLeidosDosOperaciones= (stateLetters.match(/\s+1/g)|| "").length* 2;
var costoLettersLeidosUnaOperacion= (stateLetters.replace(/\s+1/g, "")|| "").length;
print(costoLettersLeidosDosOperaciones+ costoLettersLeidosUnaOperacion);

;(function () {
	print(function (n, s) {
		var t = 0, q = false;

		for (var i = 0; i < n; i++ ) {
			if (s[i] === '1') {
				t++;
				q = true;
			} else if (q) {
				t++;
				q = false;
			}
		}

		if (!q && t > 0) t--;

		return t;
	}(+readline(), readline().split(' ')));
}.call(this));

function ProblemSolver() {
    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;
    this.CLEAR_ARRAY_PER_CASE = true;

	this.dp = function( i , fl ) {
		if( i >= this.n ) {
			return 0 ;
		}
		var ret , res , re , r1 , a ;
		ret = this.memo[ i ][ fl ] ;
		re = this.done[ i ][ fl ] ;
		if( re == this.cc ) {
			return ret ;
		}
		this.done[ i ][ fl ] = this.cc ;
		res = ( 1 << 29 ) ;
		if( fl == 0 ) {
			if( this.arr[ i ] == 0 ) {
				r1 = this.dp( i + 1 , 0 ) ;
				res = Math.min( res , r1 ) ;
			}
			else {
				r1 = this.dp( i + 1 , 1 ) + 1 ;
				res = Math.min( res , r1 ) ;
				a = 2 ;
				if( this .brr[ i + 1 ] == 0 ) {
					a = 1 ;
				}
				r1 = this.dp( i + 1 , 0 ) + a ;
				res = Math.min( res , r1 ) ;
			}
		}
		else {
			if( this.arr[ i ] == 0 ) {
				a = 2 ;
				if( this .brr[ i + 1 ] == 0 ) {
					a = 1 ;
				}
				r1 = this.dp( i + 1 , 0 ) + a ;
				res = Math.min( res , r1 ) ;
			}
			else {
				r1 = this.dp( i + 1 , 1 ) + 1 ;
				res = Math.min( res , r1 ) ;
				a = 2 ;
				if( this .brr[ i + 1 ] == 0 ) {
					a = 1 ;
				}
				r1 = this.dp( i + 1 , 0 ) + a ;
				res = Math.min( res , r1 ) ;
			}
		}
		return this.memo[ i ][ fl ] = res ;
	};

    this.solveCase = function() {
        var res , i , j , fl , cn , temp ;
        for( i = this.n - 1 ; i >= 0 ; i-- ) {
        	if( i == this.n - 1 ) {
        		this.brr[ i ] = this.arr[ i ] ;
        	}
        	else {
        		this.brr[ i ] = this.brr[ i + 1 ] + this.arr[ i ] ;
        	}
        }
        res = this.dp( 0 , 0 ) ;
        print( res );
    };

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

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = 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 ;
    	for( i = 0 ; i < this.lim1 ; i++ ) {
    		this.brr[ i ] = 0 ;
    	}
    };

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

    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.lim1 ; 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 InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

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

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    };

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    };

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    };

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        this.allLines = [] ;
        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;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            res = "";
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( 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;
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );
                }
            }
            this.currrentCharacterIndex = endIdx;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            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() {
        return 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;
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

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

    this.runCases = function() {
        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 ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {
                    environmentType = 'local-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    };

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                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 );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

var n = Number(readline()),
    letters = readline().split(' ');

// var n = Number("5"),
//     letters = "0 0".split(' ');

function solver() {
    var operationsCount = 0,
        inTheList = true,
        inALetter = false,
        isNextUnread = false,
        readSoFar = 0,
        totalLetters = letters.reduce(function (a, b) {
            return Number(a) + Number(b);
        });

    for (var i = 0; i < letters.length; i++) {
        if (letters[i] === "1") {
            readSoFar++;
            if (inTheList || (isNextUnread && inALetter)) {
                operationsCount++;
            }

            inALetter = true;
            inTheList = false;

            if (i + 1 < letters.length) {
                if (letters[i + 1] == "1") {
                    isNextUnread = true;
                } else {
                    isNextUnread = false;
                    inTheList = true;

                    if (readSoFar < totalLetters) {
                        operationsCount++;
                    }
                    inALetter = false;
                }
            }
        }
    }

    return operationsCount;
}

print(solver());
// console.log(solver());

n = readline();
list = readline().split(' ').map(Number);
num = 0;
i = list.indexOf(1);
if (i != -1) {
while (i < list.length){
	num++;
	list[i]=2;
	if (list[i+1] == 1){
		i++;
	}
	else {
		if (list.indexOf(1) == -1){
			i = list.length;
		}
		else {
			i = list.indexOf(1);
			num++;
		}
	}
	}
}
print(num);

var n = parseInt(readline()),
			arr = readline().replace(/\s{1,}/gi, ' ').split(/\s/),
			click = 0, goList = false;

		for(var i = 0; i < n; i++)	{
			if(arr[i] == 1)	{
				click++;
				goList = false;

				if(arr[i + 1] == 0)	{
					click++;
					goList = true;
				}
			}
		}

		if(goList)	click--;

		//console.log(bits, count);

		print(click);

readline(); // not needed

print(readline().split(' ').map(function (x) {
    return parseInt(x);
}).reduce(function (p, x) {
    if (x || p[1]) {
        p[0]++;
    }
    p[1] = x;
    return p;
}, [0, 0]).reduce(function (s, r) {
    if (s && !r) {
        s--;
    }
    return s;
}));


var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var n = parseInt(readline());
  if(n===2)
  {
      print("2");
  print(n , " ", n -1);
  continue;
  }
  print("2");
  print(n , " ", n -2);
  print(n-1 , " ", n -1);
  for (var j = n-1; j >= 3; j--) {
    print(j , " " , j - 2);
  }
}

function solv() {
    var x = parseInt(readline())
    var res = [];
    var cur = x;
    var pv = x - 1;
    for (var n = 0; n < x - 1; n++) {
        res.push([cur, pv]);
        cur = Math.ceil((cur + pv) / 2);
        pv--;
    }
    print(cur);
    for (n in res) {
        print(res[n][0], res[n][1])
    }
}

var tc = parseInt(readline())
while (tc--) solv()

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const num = +readLine();
    const arr = [];
    for (let i = 1; i <= num; i++) arr.push(i);

    console.log(2);
    for (let i = 0; i < num - 1; i++) {
      const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];
      console.log(`${a} ${b}`);
      arr.pop();
      arr.pop();
      const avg = Math.ceil((a + b) / 2);
      arr.push(avg);
    }
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = $()
  while (t--) {
    let n = $(), c = n;
    out.push(2)
    ForR(n - 1, 1, i => {
      out.push(`${c} ${i}`)
      c = Math.round((c + i) / 2);
    })
  }
  log(out.join('\n'))
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    C();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = 0;
        let b = 0;
        let c = 0;
        let isFound = false;
        for(let i = 0; i <= Math.floor(n/3); i++){
            if(isFound)
                break;
            if(3*i > n)
                break;
            else if(3*i === n){
                a = i;
                isFound = true;
                break;
            }
            for(let j = 0; j <= Math.floor(n/5); j++){
                if(isFound)
                    break;
                if(3*i + 5*j > n)
                    break;
                else if(3*i + 5*j === n){
                    a = i; b = j;
                    isFound = true;
                    break;
                }
                for(let k = 0; k <= Math.floor(n/7); k++){
                    if(3*i + 5*j + 7*k === n){
                        a = i; b = j; c = k;
                        isFound = true;
                        break;
                    }else if(3*i + 5*j + 7*k > n){
                        break;
                    }
                }
            }
        }

        if(isFound)
            console.log(a,b,c)
        else
            console.log(-1);
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,k] = ti(readline().split(' '));
        let a = ti(readline().split(' '));
        a.sort((a,b) => b-a);

        let d = 0;
        for(let i = 0; i < k; i++){
            if(i < n){
                d += a[i];
            }else{
                break;
            }
        }

        if(k < n)
            console.log(d+a[k]);
        else
            console.log(d);
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let ans = [];
        let curr = n-1;
        let last = n;
        let i = 0;
        while(i < n-1 && curr > 0){
            ans.push([curr, last]);
            last = Math.ceil((last+curr)/2);
            curr = curr-1;
            i++;
        }
        console.log(last);
        for(let item of ans){
            console.log(item[0], item[1]);
        }
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const num = +readLine();
    const arr = [];
    for (let i = 1; i <= num; i++) arr.push(i);

    console.log(num - 1);
    for (let i = 0; i < num - 1; i++) {
      const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];
      console.log(`${a} ${b}`);
      arr.pop();
      arr.pop();
      const avg = Math.ceil((a + b) / 2);
      arr.push(avg);
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const num = +readLine();
    let [same, n, first] = [false, num, true];

    for (let i = 0; i < num - 1; i++) {
      if (same) {
        console.log(`${n} ${n}`);
      } else {
        if (first) {
          let other = n - 2;
          if (other <= 0) other = n - 1;
          console.log(`${n} ${other}`);
          n = Math.floor((n + other) / 2);
          first = false;
        } else {
          let other = n - 3;
          if (n - 3 <= 0) other = n - 2;

          console.log(`${n} ${other}`);
          n = Math.floor((n + other) / 2);
        }
      }
      same = !same;
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const num = +readLine();
    const arr = [];
    for (let i = 1; i <= num; i++) arr.push(i);

    for (let i = 0; i < num - 1; i++) {
      const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];
      console.log(`${a} ${b}`);
      arr.pop();
      arr.pop();
      const avg = Math.ceil((a + b) / 2);
      arr.push(avg);
    }
  }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var n = parseInt(readline());
  print("2");
  print(n + " " + n - 1);
  for (var j = n; j >= 3; j--) {
    print(j + " " + j - 2);
  }
}

function solve(nu) {
  print("2");
  print(nu + " " + nu - 1);
  for (var j = nu; j >= 3; j--) {
    print(j + " " + j - 2);
  }
}


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 main() {
	var tokens = tokenize(readline()),
		a10 = parseInt(tokens[0]), b = tokens[1],
		c = trim(readline()),
		digits = '0123456789ABCDEFGHIJKLMNO',
		digit2value = {}, value2digit = {};
	for (var i = 0; i < 25; ++i) {
		digit = digits.charAt(i);
		digit2value[digit] = i;
		value2digit[i] = digit;
	}
	var c10 = 0;
	for (var i = 0; i < c.length; ++i) {
		c10 = a10*c10 + digit2value[c.charAt(i)];
	}
	function roman(x) {
		if (x >= 1000) {
			return 'M'+roman(x-1000);
		} else if (x >= 900) {
			return 'CM'+roman(x-900);
		} else if (x >= 500) {
			return 'D'+roman(x-500);
		} else if (x >= 400) {
			return 'CD'+roman(x-400);
		} else if (x >= 100) {
			return 'C'+roman(x-100);
		} else if (x >= 90) {
			return 'XC'+roman(x-90);
		} else if (x >= 50) {
			return 'L'+roman(x-50);
		} else if (x >= 40) {
			return 'XL'+roman(x-40);
		} else if (x >= 10) {
			return 'X'+roman(x-10);
		} else if (x >= 9) {
			return 'IX'+roman(x-9);
		} else if (x >= 5) {
			return 'V'+roman(x-5);
		} else if (x >= 4) {
			return 'IV'+roman(x-4);
		} else if (x >= 1) {
			return 'I'+roman(x-1);
		} else {
			return '';
		}
	}
	if (b == 'R') {
		print(roman(c10));
	} else {
		if (c10 == 0) {
			print('0');
			return;
		}
		var x = c10, parts = [];
		while (x != 0) {
			var value = x%b;
			parts.push(value2digit[value]);
			x = (x-value)/b;
		}
		print(parts.reverse().join(''));
	}
}

main();

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 main() {
	var tokens = tokenize(readline()),
		a10 = parseInt(tokens[0]), b = tokens[1],
		c = trim(readline()),
		digits = '0123456789ABCDEFGHIJKLMNO',
		digit2value = {}, value2digit = {};
	for (var i = 0; i < 25; ++i) {
		digit = digits.charAt(i);
		digit2value[digit] = i;
		value2digit[i] = digit;
	}
	var c10 = 0;
	for (var i = 0; i < c.length; ++i) {
		c10 = a10*c10 + digit2value[c.charAt(i)];
	}
	var romanValues = { M: 1000, C: 100, D: 500, L: 50, X: 10, V: 5, I: 1 },
		romanList = [ { main: 'M', sub: 'C' },
					  { main: 'D', sub: 'C' },
					  { main: 'C', sub: 'X' },
					  { main: 'L', sub: 'X' },
					  { main: 'X', sub: 'I' },
					  { main: 'V', sub: 'I' } ];
	function roman(x) {
		for (var i = 0; i < romanList.length; ++i) {
			var mainChar = romanList[i].main, mainValue = romanValues[mainChar],
				subChar = romanList[i].sub, subValue = romanValues[subChar];
			if (x >= mainValue) {
				return mainChar + roman(x-mainValue);
			} else if (x >= mainValue-subValue) {
				return subChar + mainChar + roman(x-mainValue+subValue);
			}
		}
		if (x >= 1) {
			return 'I' + roman(x-1);
		}
		return '';
	}
	if (b == 'R') {
		print(roman(c10));
	} else {
		if (c10 == 0) {
			print('0');
			return;
		}
		var x = c10, parts = [];
		while (x != 0) {
			var value = x%b;
			parts.push(value2digit[value]);
			x = (x-value)/b;
		}
		print(parts.reverse().join(''));
	}
}

main();

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 main() {
	var tokens = tokenize(readline()),
		a10 = parseInt(tokens[0]), b = tokens[1],
		c = trim(readline()),
		digits = '0123456789ABCDEFGHIJKLMNO',
		digit2value = {}, value2digit = {};
	for (var i = 0; i < 25; ++i) {
		digit = digits.charAt(i);
		digit2value[digit] = i;
		value2digit[i] = digit;
	}
	var c10 = 0;
	for (var i = 0; i < c.length; ++i) {
		c10 = a10*c10 + digit2value[c.charAt(i)];
	}
	var romanValues = { M: 1000, C: 100, L: 50, X: 10, V: 5, I: 1 },
		romanList = [ { main: 'M', sub: 'C' },
					  { main: 'C', sub: 'X' },
					  { main: 'L', sub: 'X' },
					  { main: 'X', sub: 'I' },
					  { main: 'V', sub: 'I' } ];
	function roman(x) {
		for (var i = 0; i < romanList.length; ++i) {
			var mainChar = romanList[i].main, mainValue = romanValues[mainChar],
				subChar = romanList[i].sub, subValue = romanValues[subChar];
			if (x >= mainValue) {
				return mainChar + roman(x-mainValue);
			} else if (x >= mainValue-subValue) {
				return subChar + mainChar + roman(x-mainValue+subValue);
			}
		}
		if (x >= 1) {
			return 'I' + roman(x-1);
		}
		return '';
	}
	if (b == 'R') {
		print(roman(c10));
	} else {
		if (c10 == 0) {
			print('0');
			return;
		}
		var x = c10, parts = [];
		while (x != 0) {
			var value = x%b;
			parts.push(value2digit[value]);
			x = (x-value)/b;
		}
		print(parts.reverse().join(''));
	}
}

main();

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 main() {
	var tokens = tokenize(readline()),
		a10 = parseInt(tokens[0]), b = tokens[1],
		c = trim(readline()),
		digits = '0123456789ABCDEFGHIJKLMNO',
		digit2value = {}, value2digit = {};
	for (var i = 0; i < 25; ++i) {
		digit = digits.charAt(i);
		digit2value[digit] = i;
		value2digit[i] = digit;
	}
	var c10 = 0;
	for (var i = 0; i < c.length; ++i) {
		c10 = a10*c10 + digit2value[c.charAt(i)];
	}
	function roman(x) {
		if (x >= 1000) {
			return 'M'+roman(x-1000);
		} else if (x >= 900) {
			return 'CM'+roman(x-900);
		} else if (x >= 500) {
			return 'D'+roman(x-500);
		} else if (x >= 400) {
			return 'CD'+roman(x-400);
		} else if (x >= 100) {
			return 'C'+roman(x-100);
		} else if (x >= 90) {
			return 'XC'+roman(x-90);
		} else if (x >= 50) {
			return 'L'+roman(x-50);
		} else if (x >= 40) {
			return 'XL'+roman(x-40);
		} else if (x >= 10) {
			return 'X'+roman(x-10);
		} else if (x >= 9) {
			return 'IX'+roman(x-9);
		} else if (x >= 5) {
			return 'V'+roman(x-5);
		} else if (x >= 4) {
			return 'IV'+roman(x-4);
		} else if (x >= 1) {
			return 'I'+roman(x-1);
		} else {
			return '';
		}
	}
	if (b == 'R') {
		print(roman(c10));
	} else {
		var x = c10, parts = [];
		while (x != 0) {
			var value = x%b;
			parts.push(value2digit[value]);
			x = (x-value)/b;
		}
		print(parts.reverse().join(''));
	}
}

main();

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 main() {
	var tokens = tokenize(readline()),
		a10 = parseInt(tokens[0]), b = tokens[1],
		c = trim(readline()),
		digits = '0123456789ABCDEFGHIJKLMNO',
		digit2value = {}, value2digit = {};
	for (var i = 0; i < 25; ++i) {
		digit = digits.charAt(i);
		digit2value[digit] = i;
		value2digit[i] = digit;
	}
	var c10 = 0;
	for (var i = 0; i < c.length; ++i) {
		c10 = a10*c10 + digit2value[c.charAt(i)];
	}
	var romanValues = { M: 1000, C: 100, L: 50, X: 10, V: 5, I: 1 },
		romanList = [ { main: 'M', sub: 'C' },
					  { main: 'C', sub: 'X' },
					  { main: 'L', sub: 'X' },
					  { main: 'X', sub: 'I' },
					  { main: 'V', sub: 'I' } ];
	function roman(x) {
		for (var i = 0; i < romanList.length; ++i) {
			var mainChar = romanList[i].main, mainValue = romanValues[mainChar],
				subChar = romanList[i].sub, subValue = romanValues[subChar];
			if (x >= mainValue) {
				return mainChar + roman(x-mainValue);
			} else if (x >= mainValue-subValue) {
				return subChar + mainChar + roman(x-mainValue-subValue);
			}
		}
		return '';
	}
	if (b == 'R') {
		print(roman(c10));
	} else {
		if (c10 == 0) {
			print('0');
			return;
		}
		var x = c10, parts = [];
		while (x != 0) {
			var value = x%b;
			parts.push(value2digit[value]);
			x = (x-value)/b;
		}
		print(parts.reverse().join(''));
	}
}

main();


var tc = parseInt(readline());
while(tc--){
    var num = parseInt(readline());
    print(num%2==0 ? parseInt(num/2) : parseInt(num/2)+1);
}

function solve() {
   var n = Number(read());
   write(Math.floor((n + 1) / 2));
}

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

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

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

var Tc = parseInt(readline());
while (Tc-- > 0) {
  var n = parseInt(readline());
  print(Math.floor((n + 1) / 2));
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  var T = readline();

  while (T-- > 0) {
    let n = readline();

    let res = 1 + parseInt((n - 1) / 2);

    console.log(res);
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let n = +readLine();
    if (n % 2 === 0) {
      console.log(Math.floor(n / 2));
    } else {
      console.log(Math.floor(n / 2) + 1);
    }
  }
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;

  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var n = nextInt();
		output[i] = Math.ceil(n / 2);
	}
	myout(myconv(output,9));
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
});

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
  data = data.split('\n');
  const testCases = data[0] * 1;
  let i = 1;
  while (i <= testCases) {
    let n = data[i] * 1;
    console.log(Math.ceil(n / 2));
    i += 1;
  }
}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let t = -1;

rl.on('line', (input) => {
    if (t === -1) {
        t = parseInt(input);
    } else {
        let tmp = parseInt(input);
        console.log(tmp % 2 === 0 ? tmp / 2 : tmp / 2 + 0.5);
    }
})

const process = require('process');

let inp = "";
process.stdin.on('data', chunk => inp += chunk);
process.stdin.on('end', () => {
    inp = inp.split('\n');
    let ic = 0;
    let ntest = +inp[ic++];
    for (let testcase = 0; testcase < ntest; ++testcase) {
        let n = +inp[ic++];
        console.log(Math.floor((n + 1) / 2));
    }

});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = ''
let currentLine = 0

process.stdin.on('data', inputStdin => {
    inputString += inputStdin
})

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n')

    main()
})

function readLine() {
    return inputString[currentLine++]
}

const s2i = s => parseInt(s, 10)

const readLineOfInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(s2i(split[i]));
  }
  return result
}

function main() {
  let T = s2i(readLine())
  let out = ''

  while (T--) {
    const n = s2i(readLine())

    out += Math.ceil(n/2) + '\n'
  }
  console.log(out)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function main() {
    let n = parseInt(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let n = Number(readline());

    console.log(Math.ceil(n / 2));
}

const process = require('process');

let inp = "";
process.stdin.on('data', chunk => inp += chunk);
process.stdin.on('end', () => {
    inp = inp.split(/\s/);
    let ic = 0;
    let ntest = +inp[ic++];
    for (let testcase = 0; testcase < ntest; ++testcase) {
        let n = +inp[ic++];
        console.log(Math.floor((n + 1) / 2));
    }

});


var readline = require('readline')
var k=0
var n=0;
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('', (answer) => {
  n= answer
  rl.question('', (answer) => {
    x=answer.split(' ')
    for (var i = (n-1);i>=0;i--) {
      if(Number(x[i])<0) x[i] = 0
      if(Number(x[i-1])>Number(x[i]) || Number(x[i-1])==Number(x[i])) {
        x[i-1] = Number(x[i])-1
      }
    }
    x.forEach(function(i) {
      k+=+i
    })
    console.log(k)
    rl.close()
  })
})

var n=readline();
var a=readline().split(" ");
a=a.slice(0,n);
var curV=1000000001;
var res=0;
for(var i=n-1; i>=0; --i){
    curV=Math.max(0,Math.min(a[i],curV-1));
    res+=curV;
}
print(res);

const readline = require('readline');

const rl = readline.createInterface({
	input: process.stdin,
	setEncoding: 'utf8',
	terminal: false
});

const readInput = (function* () {
	const n = Number(yield);
	const s = (yield).trim().split(" ").map(Number);
	rl.close();
	let x = y = s[n - 1];
	for (let i = n - 2; i >= 0; i--) {
		if (y < 2) break;
		y = Math.min(s[i], y - 1);
		x += y;
	}
	console.log(x)
})();

readInput.next();

rl.on('line', (line) => {
	readInput.next(line);
});

var n = readline();
var a = readline().split(' ');
a=a.slice(0,n);

var curV=1000000001;
var res=0;
for(var i=n-1; i>=0; --i ){
    curV=Math.max(0,Math.min(curV-1, a[i]));
    res+=curV;
}
print(res);

const readline = require('readline');

const rl = readline.createInterface({
	input: process.stdin,
	setEncoding: 'utf8',
	terminal: false
});

const readInput = (function* () {
	const n = Number(yield);
	const s = (yield).trim().split(" ").map(Number);
	rl.close();
	let x = 0;
	let y = Infinity;
	for (let i = n - 1; i >= 0; i--) {
		if (s[i] < 2) {
			if (y > 1) x += s[i];
			break;
		}
		y = Math.min(s[i], y - 1);
		x += y;
	}
	console.log(x)
})();

readInput.next();

rl.on('line', (line) => {
	readInput.next(line);
});

const readline = require('readline');

const rl = readline.createInterface({
	input: process.stdin,
	setEncoding: 'utf8',
	terminal: false
});

const readInput = (function* () {
	const n = Number(yield);
	const s = (yield).trim().split(" ").map(Number);
	rl.close();
	let x = 0;
	let y = Infinity;
	for (let i = n - 1; i >= 0; i--) {
		if (s[i] < 2) {
			if (y > 1) x += s[i];
			break;
		}
		y = Math.max(s[i], y - 1);
		x += y;
	}
	console.log(x)
})();

readInput.next();

rl.on('line', (line) => {
	readInput.next(line);
});

const readline = require('readline');

const rl = readline.createInterface({
	input: process.stdin,
	setEncoding: 'utf8',
	terminal: false
});

const readInput = (function* () {
	const n = Number(yield);
	const s = (yield).trim().split(" ").map(Number);
	rl.close();
	let x = 0;
	let y = Infinity;
	for (let i = n - 1; i >= 0; i--) {
		if (s[i] < 2) {
			x += s[i];
			break;
		}
		y = Math.min(s[i], y - 1);
		x += y;
	}
	console.log(x)
})();

readInput.next();

rl.on('line', (line) => {
	readInput.next(line);
});

const readline = require('readline');

const rl = readline.createInterface({
	input: process.stdin,
	setEncoding: 'utf8',
	terminal: false
});

const readInput = (function* () {
	const n = Number(yield);
	const s = (yield).trim().split(" ").map(Number);
	rl.close();
	let x = y = s[n - 1];
	for (let i = n - 2; i >= 0; i--) {
		console.log('iteration', n - i,': y =', y);
		if (y < 2) break;
		y = Math.min(s[i], y - 1);
		x += y;
	}
	console.log(x)
})();

readInput.next();

rl.on('line', (line) => {
	readInput.next(line);
});

var n = readline();
var a = readline().split(' ');
var x = [];
var flag = false;
if(n<1 || n>200000) exit();

for(var i=0; i<n; i++){
    for(var j=i+1; j<n; j++){
        if(a[i]>=a[j]) flag = true;
    }
    if(flag) x.push(0);
    else x.push(Number(a[i]));

    flag = false;
}
print(x.reduce((a,b) => a+b));

var n = 5;
var a = "3 2 5 4 10".split(' ');
var x = [];
var flag = false;
if(n<1 || n>200000) exit();

for(var k=0; k<a.length; k++){
    a[k] = Number(a[k]);
}

for(var i=0; i<n; i++){
    if(a[i]==Math.min(...a.slice(i)) && a[i]!=Math.max(...a.slice(i))){
        x[i]=a[i];
    } else if(i==n-1){
        x[i]=Math.min(...a.slice(i));
    } else {
        x[i]=Math.min(...a.slice(i))-1;
    }
}

print(x.reduce((a,b)=>a+b));