var InputReader = (function () {
    function InputReader() {
        this.index = 0;
        this.tokenizer = [];
    }
    InputReader.prototype.next = function () {
        while (this.tokenizer == null || this.index == this.tokenizer.length) {
            this.tokenizer = readline().split(" ");
            this.index = 0;
        }
        var res = this.tokenizer[this.index++];
        return res;
    };
    InputReader.prototype.nextInt = function () {
        return parseInt(this.next());
    };
    InputReader.prototype.nextFloat = function () {
        return parseFloat(this.next());
    };
    return InputReader;
})();
function main() {
    var input = new InputReader();
    var a = input.nextInt();
    var b = input.nextInt();
    var res = 0;
    var h = Math.min(a, b);
    var w = Math.max(a, b);
    while (h != 0) {
        res += Math.floor(w / h);
        var t = w;
        w = h;
        h = t % h;
    }
    print(res);
}
main();


var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

function main() {
    var a = nextInt();
    var b = nextInt();
    var result = 0;
    while (a * b > 0) {
        if (b > a) {
            var t = a;
            a = b;
            b = t;
        }
        result += Math.floor(a / b);
        a = a % b;
    }
    print(result);
}

main();


(function () {
	'use strict';

	var str = readline().split(' ').map(Number),
		a = str[0], b = str[1], result = 0;

	while (true) {
		if (a === b) {
			result++;
			break;
		}

		if (a * b === 0) break;

		var max = Math.max(a, b),
			min = Math.min(a, b),
			itter = parseInt(max / min);

		result += itter;
		a = min;
		b = max - min * itter;
	}

	print(result);

}).call(this);


var line = readline().split(' ');

var a = parseInt(line[0]);
var b = parseInt(line[1]);

var total = 0;
var newSquares = 0;
var tempA = 0;

while (b > 0) {
  newSquares = Math.floor(a/b);
  tempA = a - b*newSquares;
  a = b;
  b = tempA;
  total += newSquares;
}

write(total);


var a = readline().split(' '),
    n = a[0], m = a[1], count = 0, x, y;

    while(n > 0 && m > 0){
        count = count + parseInt(n / m);
        x = n % m;
        y = m;
        if(x < y){
        	m = x;
        	n = y;
        }
        else{
        	n = x;
        	m = y;
        }
    }

print(count);


var a = readline().split(' ');
var ans = 0;
while(a[1] > 0) {
    ans += parseInt(a[0]/a[1]);
    var t = a[0] % a[1];
    a[0] = a[1];
    a[1] = t;
}
print(ans);


var a = readline().split(' '),
    n = a[0], m = a[1], count = 0, x, y;

    while(n > 0 && m > 0){
        count = count + (n / m);
        x = n % m;
        y = m;
        if(x < y){
        	m = x;
        	n = y;
        }
        else{
        	n = x;
        	m = y;
        }
    }

print(count);


var line = readline().split(' ');

var a = parseInt(line[0]);
var b = parseInt(line[1]);

var total = 0;
var newSquares = 0;
var tempA = 0;

while (b > 0) {
  tempA = a;
  newSquares = Math.floor(a/b);
  a -= b*newSquares;
  b = tempA;
  total += newSquares;
}

write(total);


var a = readline().split(' '),
    n = a[0], m = a[1], count = 0, x, y;

    while(n > 0 && m > 0){
        count = count + (n / m);
        x = n % m;
        y = m;
        n = max(x, y);
        m = min(x, y);
    }

print(count);


function main() {
  readLine();
  var sum = readLine().split(' ').map(Number)
    .reduce((acc, d) => acc + (d < 0 ? -d : d), 0);
  print(sum);
}


n=readline()
res=0
a=readline().split(' ')
for (i=0;i<n;i++)
{
    if (a[i]<0){a[i]*=-1;}
    res+=a[i];
}
print(res)


process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
  readLine();
  var sum = readLine().split(' ').map(Number)
    .reduce((acc, d) => acc + (d < 0 ? -d : d), 0);
  console.log(sum);
}


var input = readline()
var k = readline()

var n = readline().split(' ')

var s = 0
for(var i=0; i<k; i++) {
    s += Math.abs(parseInt(n[i]))
}
print(s)


n=+readline()
res=0
a=readline().split(' ')
for (i=0;i<n;i++)
{
    if (a[i]<0){a[i]*=-1;}
    res+=+a[i];
}
print(res)


const n = readline();
const input = readline();
const numbers = input.split(' ');

var result = 0;

for (var i = 0; i < n; i++){
    result += Math.abs(numbers[i]);
}

print(result);


//var input = readline()
var k = readline()

var n = readline().split(' ')

var s = 0
for(var i=0; i<k; i++) {
    s += Math.abs(parseInt(n[i]))
}
print(s)


(function() {
  readline();
  var elem = readline().split(' ').map(x => +x);

  print(solution(elem));
})();

function solution(elem) {
  var B = elem.filter(x => x > 0).reduce((s, v) => s + v, 0);
  var C = elem.filter(x => x < 0).reduce((s, v) => s + v, 0);

  return B - C;
}


x=readline();
 y=(readline()).split(' ');
sum=0;
for(i=0;i<x;i++)
{
_y=parseInt(y[i])
if(_y<0)
    sum=sum+(-1*_y)
else
    sum=sum+_y
}
print(sum)


readline();
var sum = readline().split(' ').map(Number)
  .reduce((acc, d) => acc + (d < 0 ? -d : d), 0);
print(sum);


var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

function sortNumber(a, b) {
    return a - b;
}

function sortSegment(a, l, r) {
    var n = a.length;
    var b = [];
    var m = r - l + 1;
    for (var i = 0; i < m; i++) {
        b[i] = a[l + i];
    }
    b.sort(sortNumber);
    for (var i = 0; i < m; i++) {
        a[l + i] = b[i];
    }
    return a;
}

function nextPermutation(a) {
    var n = a.length;
    for (var i = n - 1; i >= 0; i--) {
        if (i == 0) {
            return "null";
        }
        if (a[i] > a[i - 1]) {
            for (var j = i; j < n; j++) {
                if (j == n - 1) {
                    var t = a[j];
                    a[j] = a[i - 1];
                    a[i - 1] = t;
                    a = sortSegment(a, i, n - 1);
                    return a;
                }
                if (a[j + 1] < a[i - 1]) {
                    var t = a[j];
                    a[j] = a[i - 1];
                    a[i - 1] = t;
                    a = sortSegment(a, i, n - 1);
                    return a;
                }
            }
        }
    }
    return a;
}

function main() {
    var p = [0, 1, 2, 3, 4];
    var a = [[], [], [], [], []];
    for (var i = 0; i < 5; i++) {
        for (var j = 0; j < 5; j++) {
            a[i][j] = nextInt();
        }
    }
    var p12 = a[p[0]][p[1]] + a[p[1]][p[0]];
    var p23 = a[p[2]][p[1]] + a[p[1]][p[2]];
    var p34 = a[p[2]][p[3]] + a[p[3]][p[2]];
    var p45 = a[p[4]][p[3]] + a[p[3]][p[4]];
    var max = p12 + p23 + 2 * (p34 + p45);
    while (nextPermutation(p) != 'null') {
        p12 = a[p[0]][p[1]] + a[p[1]][p[0]];
        p23 = a[p[2]][p[1]] + a[p[1]][p[2]];
        p34 = a[p[2]][p[3]] + a[p[3]][p[2]];
        p45 = a[p[4]][p[3]] + a[p[3]][p[4]];
        var sum = p12 + p23 + 2 * (p34 + p45);
        if (sum > max) {
            max = sum;
        }
    }
    print(max);
}

main();


;(function () {

	var m = [];
	for (var i = 0; i < 5; i++) m.push(readline().split(' ').map(Number));

	var t = 0, k = [];
	for (var a = 0; a < 5; a++)
		for (var b = 0; b < 5; b++)
			for (var c = 0; c < 5; c++)
				for (var d = 0; d < 5; d++)
					for (var e = 0; e < 5; e++)
						if (dif(a, b, c, d, e))
							t = Math.max(t, sum(a, b, c, d, e));

	print(t);

	function sum (a, b, c, d, e) {
		return 0
			+ m[a][b] + m[b][a] + m[c][d]
			+ m[d][c] + m[c][b] + m[b][c]
			+ m[d][e] + m[e][d] + m[c][d]
			+ m[d][c] + m[d][e] + m[e][d];
	}

	function dif (a, b, c, d, e) {
		var m = {}; m[a] = true; m[b] = true;
		m[c] = true; m[d] = true; m[e] = true;
		return Object.keys(m).length === 5;
	}

}).call(this);


var infoLine = [0, 0, 0, 0, 0];
var honor = 0;
var limitHonor = 0;
for (var s = 0; s<5; s++) {
    infoLine[s] = readline().split(' ').map(Number);
}
var permArr = [],
usedChars = [];

function permute(input) {
    var k, ch;
    for (k = 0; k < input.length; k++) {
        ch = input.splice(k, 1)[0];
        usedChars.push(ch);
        if (input.length == 0) {
            permArr.push(usedChars.slice());
        }
        permute(input);
        input.splice(k, 0, ch);
        usedChars.pop();
    }
    return permArr
};
permute([0,1,2,3,4]);

for (var i=0; i < permArr.length; i++) {
    limitHonor = (infoLine[permArr[i][0]][permArr[i][1]] + infoLine[permArr[i][1]][permArr[i][0]] + infoLine[permArr[i][2]][permArr[i][3]] + infoLine[permArr[i][3]][permArr[i][2]]) + (infoLine[permArr[i][1]][permArr[i][2]] + infoLine[permArr[i][2]][permArr[i][1]] + infoLine[permArr[i][3]][permArr[i][4]] + infoLine[permArr[i][4]][permArr[i][3]]) + (infoLine[permArr[i][2]][permArr[i][3]] + infoLine[permArr[i][3]][permArr[i][2]]) + (infoLine[permArr[i][3]][permArr[i][4]] + infoLine[permArr[i][4]][permArr[i][3]]);
    if (limitHonor > honor) {
        honor = limitHonor;
    }
}

print(honor);


        var next_permutation = function( d ) {
            var i = d.length - 1;
            while ( i > 0 ) {
                var k = i;
                i--;
                if ( d[i] < d[k] ) {
                    var j = d.length-1;
                    while ( d[i] >= d[j] ) {
                        j--;
                    }
                    d[i] = d.splice( j, 1, d[i] )[0]; // d[i]とd[j]を入れ替える
                    np_reverse( d, k, d.length-1 );
                    return true;
                }
            }
            return false;
        }

        var np_reverse = function( d, a, b ) {
            var sub = d.slice( a, b+1 ).reverse();
            for ( var i = a; i <= b; i++ ) {
                d[i] = sub[i-a];
            }
        }
        function main(){
            var m = [], i,j;
            for( i = 0 ; i < 5 ; ++i){
                m[i] = readline().split(' ');
                for ( j = 0 ; j < 5 ; ++j){
                    m[i][j] = parseInt(m[i][j]);
                }
            }
            var answer = 0;
            var p = [0,1,2,3,4];
            do{
                var sum = 2 * (m[p[3]][p[4]]+m[p[4]][p[3]] + m[p[2]][p[3]] + m[p[3]][p[2]]) + m[p[0]][p[1]]  + m[p[1]][p[0]] + m[p[1]][p[2]] + m[p[2]][p[1]];
                answer = Math.max(answer,sum);
            }while(next_permutation(p));
            print(answer);
        }
        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 h = [];
	for (var r = 0; r < 5; ++r) {
		h.push(tokenizeIntegers(readline()));
	}

	var best = 0,
		p = [0, 1, 2, 3, 4];

	function permute(i) {
		if (i == 5) {
			var a = p[0], b = p[1], c = p[2], d = p[3], e = p[4];
			best = Math.max(best, h[a][b] + h[b][c] + 2*h[c][d] + 2*h[d][e] +
								  h[b][a] + h[c][b] + 2*h[d][c] + 2*h[e][d]);
			return;
		}
		permute(i+1);
		var t = p[i];
		for (var j = i+1; j < 5; j += 1) {
			p[i] = p[j];
			p[j] = t;
			permute(i+1);
			p[j] = p[i];
		}
		p[i] = t;
	}

	permute(0);
	print(best);
}

main();


var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

function sortNumber(a, b) {
    return a - b;
}

function sortSegment(a, l, r) {
    var n = a.length;
    var b = [];
    var m = r - l + 1;
    for (var i = 0; i < m; i++) {
        b[i] = a[l + i];
    }
    b.sort(sortNumber);
    for (var i = 0; i < m; i++) {
        a[l + i] = b[i];
    }
    return a;
}

function nextPermutation(a) {
    var n = a.length;
    for (var i = n - 1; i >= 0; i--) {
        if (i == 0) {
            return "null";
        }
        if (a[i] > a[i - 1]) {
            for (var j = i; j < n; j++) {
                if (j == n - 1) {
                    var t = a[j];
                    a[j] = a[i - 1];
                    a[i - 1] = t;
                    a = sortSegment(a, i, n - 1);
                    return a;
                }
                if (a[j + 1] < a[i - 1]) {
                    var t = a[j];
                    a[j] = a[i - 1];
                    a[i - 1] = t;
                    a = sortSegment(a, i, n - 1);
                    return a;
                }
            }
        }
    }
    return a;
}

function main() {
    var p = [0, 1, 2, 3, 4];
    var max = 0;
    var a = [[], [], [], [], []];
    for (var i = 0; i < 5; i++) {
        for (var j = 0; j < 5; j++) {
            a[i][j] = nextInt();
        }
    }
    while (nextPermutation(p) != 'null') {
        var p12 = a[p[0]][p[1]] + a[p[1]][p[0]];
        var p23 = a[p[2]][p[1]] + a[p[1]][p[2]];
        var p34 = a[p[2]][p[3]] + a[p[3]][p[2]];
        var p45 = a[p[4]][p[3]] + a[p[3]][p[4]];
        var sum = p12 + p23 + 2 * (p34 + p45);

        if (sum > max) {
            max = sum;
        }
    }
    print(max);
}

main();


var n = parseInt(readline());

var result = 0 ;

for(var i = 1 ; i <= n; i ++){
    for(var j = 1 ; j <= n; j ++){
        var k = j ^ i;
        if( k<(i+j) &&    j<(i+k)   && i<(j+k)){
            result ++;
        }

    }
}

print(result/n);


var n = parseInt(readline());

var result = 0 ;

for(var i = 1 ; i <= n; i ++){
    for(var j = 1 ; j <= n; j ++){
        var k = j ^ i;
        if((i-j)<k && k<(i+j) &&  (i-k)<j && j<(i+k) && (j-k)<i && i<(j+k)){
            result ++;
        }

    }
}

print(result/6);


var n = parseInt(readline());

var result = 0 ;

for(var i = 1 ; i <= n; i ++){
    for(var j = 1 ; j <= n; j ++){
        var k = j ^ i;

        if( k<=n && k<(i+j) &&    j<(i+k)   && i<(j+k)){
            result ++;
        }

    }
}

print(result/6);


function main() {
    let line = stdin[0].split(' ');
    let k = parseInt(line[1], 10);
    let items = stdin[1].split(' ').map(i => parseInt(i, 10));
    let allItems = {}, sum = 0;

    for (let i = 0; i < items.length; ++i) {
       if (!(items[i] in allItems)) allItems[items[i]] = 0;
       ++allItems[items[i]];
    }

    for (let p in allItems) {
       sum += allItems[p];
    }

    const uniqCount = Object.keys(allItems).length;
    const countForOneMeal = uniqCount * k;

    const d1 = countForOneMeal - sum;

    return countForOneMeal * d1 - items.length;
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);


function main() {
    let line = stdin[0].split(' ');
    let k = parseInt(line[1], 10);
    let items = stdin[1].split(' ').map(i => parseInt(i, 10));
    let allItems = {}, sum = 0;

    for (let i = 0; i < items.length; ++i) {
       if (!(items[i] in allItems)) allItems[items[i]] = 0;
       ++allItems[items[i]];
    }

    for (let p in allItems) {
       sum += allItems[p];
    }

    const uniqCount = Object.keys(allItems).length;
    const countForOneMeal = uniqCount * k;

    const d1 = countForOneMeal - sum;

    console.log(countForOneMeal * d1 - items.length)
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);


function main() {
    let line = stdin[0].split(' ');
    let k = parseInt(line[1], 10);
    let items = stdin[1].split(' ').map(i => parseInt(i, 10));
    let allItems = {}, sum = 0, overhead = 0;

    for (let i = 0; i < items.length; ++i) {
       if (!(items[i] in allItems)) allItems[items[i]] = 0;
       ++allItems[items[i]];
    }

    for (let p in allItems) {
       sum += Math.min(allItems[p], k);
       overhead += Math.max(allItems[p] - k, 0)
    }

    const uniqCount = Object.keys(allItems).length;
    const countForOneMeal = uniqCount * k;

    const o1 = overhead / countForOneMeal;

    console.log(countForOneMeal - countForOneMeal * o1 + countForOneMeal - sum);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);


var guests = +readline().split(' ')[1];
var map = {};
var max = 0;
var leftovers = +readline().split(' ').map(v => {
    map[v] = (map[v] || 0) + 1;
    max = Math.max(max, map[v]);
});

max = Math.ceil(max / guests) * guests;

var k;
var res = 0;
for(var k in map) {
    res+= max - map[k];
}

print(res);


function main() {
    let line = stdin[0].split(' ');
    let k = parseInt(line[1], 10);
    let items = stdin[1].split(' ').map(i => parseInt(i, 10));
    let allItems = {}, sum = 0, overhead = 0;

    for (let i = 0; i < items.length; ++i) {
       if (!(items[i] in allItems)) allItems[items[i]] = 0;
       ++allItems[items[i]];
    }

    for (let p in allItems) {
       max = Math.max(allItems[p], max);
    }

    const uniqCount = Object.keys(allItems).length;

    while (max % k != 0) { max++; }

    console.log(uniqCount * max - items.length);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);


var s = readline().split(' ').map(Number).sort((a,b)=>a-b);
var m = (x,y)=>{var fun =(a)=>{var r=2*Math.floor(a/3); if (a%3==2){r++;} return r}; if (x<y) {var mi =Math.min(y-x,x); return (mi+fun(x-mi));} else {return fun(x);}};
var p = m.apply(null,s);
print(p);


var x = readline().split(" ").map(function(x) { return parseInt(x); });
var n = x[0], m = x[1], ans = 0;

for (var i = 0; i <= n; i++)
    if (m >= 2 * i)
        ans = Math.max(ans, i + Math.min(Math.floor((n - i) / 2), m - 2 * i));

print(ans);


// 519C     A и B и командная тренировка

//var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arr = readline().split(' ').map(Number);
var n = arr[0];
var m = arr[1];

var count = 0;

while ((n > 0) && (m > 0)) {
    if (n > m) {
        n -= 2;
        m -= 1;
        count ++;
    } else {
        if (m >= 2) {
            n -= 1;
            m -= 2;
            count ++;
        } else {
            break;
        };
    };
}

print(count);


var n = readline();

var ans = 0;

for(var i=2; i<n; i++)
{
    ans += i* (i+1);
}

print(ans);


(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runMain((function(){let[t]=i.default.nextNumbers(),e=0;for(let r=2;r<t;++r)e+=r*(r+1);i.default.puts(e)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//
//   let res = 0
//
//   for (let i = 2; i < n; ++i) {
//     res += i * (i + 1)
//   }
//
//   io.puts(res)
// }
//
// // io.runEachTest(main)
// io.runMain(main)


var n = readline();
var w=0;
for(var i=2; i<n; i++){
    w+=1*i*(i+1);
}
print(w);


var n = readline();
var w=0;
var s = new Set();
for(var i=1; i<=n; i++){
    for(var j=1; j<i; j++){
        for(k=1; k<j; k++){
         if(!(s.has(i)&&s.has(j)&&s.has(k))){
                s.add(i);
                s.add(j);
                s.add(k);
                w+=i*j*k;
            }
        }
    }
}
print(w);


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], c = data[2], d = data[3],
    buns = [{ c: c, d: d }],
    best = [];
  best.push(new Array(n+1));
  for (var j = 0; j*c <= n; ++j) {
    best[0][j*c] = j*d;
  }
  for (var i = 1; i <= m; ++i) {
    data = tokenizeIntegers(readline());
    var a = data[0], b = data[1], c = data[2], d = data[3],
        max = Math.floor(a/b);
    buns.push({ a: a, b: b, max: max, c: c, d: d });
    best.push(new Array(n+1));
    for (var p = 0; p <= n; ++p) {
      var previous = best[i-1][p];
      if (previous === undefined) {
        continue;
      }
      for (var j = 0; j <= max && p+j*c <= n; ++j) {
        var x = best[i][p+j*c], y = previous+j*d;
        if (x === undefined || x < y) {
          best[i][p+j*c] = y;
        }
      }
    }
  }
  var result = 0;
  for (var p = 0; p <= n; ++p) {
    var x = best[m][p];
    if (x !== undefined && x > result) {
      result = x;
    }
  }
  print(result);
}

main();


var k = parseInt( readline() ),
	s = readline(),
	ans = [],
	used = {};

for (var i = 0; i < s.length && ans.length < k; i++) {
	if (!used[s.charAt( i )]) {
		ans.push( i );
		used[s.charAt( i )] = true;
	}
}

if (k === ans.length) {
	print( 'YES' );
	ans.push( s.length );
	ans.forEach( function(p, i) {
		if (i > 0) {
			print( s.substring( ans[i-1], i ) );
		}
	} );
} else {
	print( 'NO' );
}


function toi(x){return parseInt(x);}
n=toi(readline());
var s=readline();
var res="";
var dic={};
var num=0;
for(var i=0;i<s.length;i++){
    c=s[i];
    if(dic[c]==1){
	res+=c;
    }else{
	res+="\n";
	dic[c]=1;
	num++;
	if(num==n){
	    res+=s.substring(i);
	    break;
	}else{
	    res+=c;
	}
    }
}
if(num!=n){
    print("NO");
}else{
    print("YES"+res);
}


var k = parseInt( readline() ),
	s = readline(),
	ans = [],
	used = {};

for (var i = 0; i < s.length && ans.length < k; i++) {
	if (!used[s.charAt( i )]) {
		ans.push( i );
		used[s.charAt( i )] = true;
	}
}

if (k === ans.length) {
	print( 'YES' );
	ans.push( s.length );
	ans.forEach( function(p, i) {
		if (i > 0) {
			print( s.substring( ans[i-1], p ) );
		}
	} );
} else {
	print( 'NO' );
}


let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/); r = 0;
  let [n, k, s, t] = inp;
  n = +n;
  k = +k;
  let f = [];
  let c = (i, j, z) => {
    let x = ((f[i] || [])[j] || [])[z]
    return x === undefined ? -1e5 : x;
  }
  let f0 = Arr(0, n, (i, p) => i ? p + (s[i - 1] == t[0]) : 0);
  if (t[0] == t[1]) {
    let m = Math.min(f0[n] + k, n);
    console.log(m * (m - 1) / 2)
    return;
  }
  for (let i = 2; i <= n; i++) {
    f[i] = Array(n + 1);
    for (let j = 0; j <= k; j++) {
      f[i][j] = Array(n + 1);
      for (let z = 1; z <= i; z++) {
        if (i == 2) {
          if (z == 1) {
            let dif = (s[0] != t[0]) + (s[1] != t[1]);
            if (j >= dif) f[i][j][z] = 1;
            else {
              let same = (s[0] == t[0]) + (s[1] == t[0]);
              if (same == 1 || j > 0) f[i][j][z] = 0;
            }
          } else {
            let same = (s[0] == t[0]) + (s[1] == t[0]);
            if (j >= 2 - same) f[i][j][z] = 0;
          }
          // console.log(i, j, z, c(i, j, z));
          continue;
        }
        // if (j == 0) {
        //   if (s[i - 1] == t[1]) {
        //     if (z == f0[i]) f[i][j][z] = 1;
        //   } else {
        //     f[i][j][z] = c(i - 1, j, z - (s[i - 1] == t[0]));
        //   }
        //   console.log(i, j, z, c(i, j, z));
        //   continue;
        // }
        if (s[i - 1] == t[1]) {
          f[i][j][z] = Math.max(c(i, j - 1, z), c(i - 1, j, z) + z);
        } else if (s[i - 1] != t[0]) {
          f[i][j][z] = Math.max(c(i - 1, j, z), c(i, j - 1, z), c(i - 1, j - 1, z) + z, c(i - 1, j - 1, z - 1))
        } else {
          f[i][j][z] = Math.max(c(i - 1, j, z - 1), c(i, j - 1, z), c(i - 1, j - 1, z) + z)
        }
        // console.log(i, j, z, f[i][j][z]);
      }
    }
  }
  console.log(Math.max(...f[n][k].filter(v => v)));
})();


let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/); r = 0;
  let [n, k, s, t] = inp;
  n = +n;
  k = +k;
  if (t[0] == t[1]) {
    let x = Math.min([...s].filter(c => c == t[0]).length + k, n);
    console.log(x * (x - 1) / 2);
    return;
  }
  let t0 = Arr(0, n - 1, (i, p) => p + (s[i] == t[0]));
  let t1 = Arr(0, n - 1, (i, p) => p + (s[n - 1 - i] == t[1])).reverse();
  let max = Arr(0, n - 2, i => s[i] == t[0] ? t1[i + 1] : 0).sum();

  For(0, Math.min(k, n - t0[n - 1] - t1[0]), i => {
    let ss = [...s];
    let remain = i;
    For(0, n - 1, i => {
      if (remain <= 0) return 0;
      if (ss[i] != t[0] && ss[i] != t[1]) { ss[i] = t[0]; remain-- }
    })
    For(0, Math.min(k - i, t1[0]), j => {
      let s0 = [...ss];
      let remain = j;
      For(0, n - 1, i => {
        if (remain <= 0) return 0;
        if (s0[i] == t[1]) { s0[i] = t[0]; remain-- }
      })
      // console.log(i, j, s0.join(''));
      remain = k - i - j;
      let t00 = Arr(0, n - 1, (i, p) => p + (s0[i] == t[0]));
      let j1 = n - 1;
      let j2 = n - 1;
      let sum2 = 0;
      while (remain > 0 && (j1 >= 0 || j2 >= 0)) {
        while (j1 >= 0 && (s0[j1] == t[0] || s0[j1] == t[1])) j1--;
        while (j2 >= 0 && s0[j2] != t[0]) {
          if (s0[j2] == t[1]) sum2++;
          j2--;
        }
        if ((t00[j1 - 1] || 0) > (t00[j2 - 1] || 0) - sum2) {
          s0[j1--] = t[1];
          remain--;
        } else if ((t00[j2 - 1] || 0) - sum2 >= 0) {
          s0[j2--] = t[1];
          sum2++;
          remain--;
        } else break;
      }
      t00 = Arr(0, n - 1, (i, p) => p + (s0[i] == t[0]));
      // console.log(i, j, k - i - j, s0.join(''), Arr(1, n - 1, i => s0[i] == t[1] ? t00[i - 1] : 0).sum());
      max = Math.max(max, Arr(1, n - 1, i => s0[i] == t[1] ? t00[i - 1] : 0).sum())
    })
  })
  console.log(max);
})();


let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/); r = 0;
  let [n, k, s, t] = inp;
  n = +n;
  k = +k;
  let count = s => Arr(0, n - 2, i => Arr(i + 1, n - 1, j => s[i] == t[0] && s[j] == t[1]).sum()).sum();
  let max = count(s);
  For(0, k, i => {
    let s0 = [...s];
    let remain = i;
    For(0, n - 1, j => {
      if (remain <= 0) return 1;
      if (s0[j] != t[0]) {
        s0[j] = t[0];
        remain--;
      }
    });
    remain = k - i;
    For(n -1, 0, j => {
      if (remain <= 0) return 1;
      if (s0[j] != t[1]) {
        s0[j] = t[1];
        remain--;
      }
    })
    max = Math.max(max, count(s0));
  });
  console.log(max);
})();


let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/); r = 0;
  let [n, k, s, t] = inp;
  n = +n;
  k = +k;
  if (t[0] == t[1]) {
    let x = Math.min([...s].filter(c => c == t[0]).length + k, n);
    console.log(x * (x - 1) / 2);
    return;
  }
  let t0 = Arr(0, n - 1, (i, p) => p + (s[i] == t[0]));
  let t1 = Arr(0, n - 1, (i, p) => p + (s[n - 1 - i] == t[1])).reverse();
  let max = Arr(0, n - 2, i => s[i] == t[0] ? t1[i + 1] : 0).sum();

  For(0, Math.min(k, n - t0[n - 1] - t1[0]), i => {
    let ss = [...s];
    let remain = i;
    For(0, n - 1, i => {
      if (remain <= 0) return 0;
      if (ss[i] != t[0] && ss[i] != t[1]) { ss[i] = t[0]; remain-- }
    })
    For(0, Math.min(k - i, t1[0]), j => {
      let s0 = [...ss];
      let remain = j;
      For(0, n - 1, i => {
        if (remain <= 0) return 0;
        if (s0[i] == t[1]) { s0[i] = t[0]; remain-- }
      })

      if (k < 50) {
        For(0, Math.min(k - i - j, n - t0[n - 1] - t1[0]), z => {
          let s1 = [...s0];
          let remain = z;
          For(n - 1, 0, i => {
            if (remain <= 0) return 0;
            if (s1[i] != t[1] && s1[i] != t[0]) { s1[i] = t[1]; remain-- }
          });
          remain = k - i - j - z;
          For(n - 1, 0, i => {
            if (remain <= 0) return 0;
            if (s1[i] == t[0]) { s1[i] = t[1]; remain-- }
          });
          let tt = Arr(0, n - 1, (i, p) => p + (s1[i] == t[0]));
          max = Math.max(max, Arr(1, n - 1, i => s1[i] == t[1] ? tt[i - 1] : 0).sum())
        });
        return 0;
      }

      // console.log(i, j, s0.join(''));
      remain = k - i - j;
      let t00 = Arr(0, n - 1, (i, p) => p + (s0[i] == t[0]));
      let j1 = n - 1;
      let j2 = n - 1;
      let sum2 = 0;
      while (remain > 0 && (j1 >= 0 || j2 >= 0)) {
        while (j1 >= 0 && (s0[j1] == t[0] || s0[j1] == t[1])) j1--;
        while (j2 >= 0 && s0[j2] != t[0]) {
          if (s0[j2] == t[1]) sum2++;
          j2--;
        }
        if ((t00[j1 - 1] || 0) > (t00[j2 - 1] || 0) - sum2) {
          s0[j1--] = t[1];
          remain--;
        } else if ((t00[j2 - 1] || 0) - sum2 >= 0) {
          s0[j2--] = t[1];
          sum2++;
          remain--;
        } else break;
      }
      t00 = Arr(0, n - 1, (i, p) => p + (s0[i] == t[0]));
      // console.log(i, j, k - i - j, s0.join(''), Arr(1, n - 1, i => s0[i] == t[1] ? t00[i - 1] : 0).sum());
      max = Math.max(max, Arr(1, n - 1, i => s0[i] == t[1] ? t00[i - 1] : 0).sum())
    })
  })
  console.log(max);
})();


let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/); r = 0;
  let [n, k, s, t] = inp;
  n = +n;
  k = +k;
  let f = [];
  let c = (i, j, z) => {
    let x = ((f[i] || [])[j] || [])[z]
    return x === undefined ? -1e5 : x;
  }
  let f0 = Arr(0, n, (i, p) => i ? p + (s[i - 1] == t[0]) : 0);
  if (t[0] == t[1]) {
    let m = Math.min(f0[n] + k, n);
    console.log(m * (m - 1) / 2)
    return;
  }
  if (k == 0) {
    let res = 0;
    for (let i = 0; i < n - 1; i++) {
      for (let j = i + 1; j < n; j++) {
        if (s[i] == t[0] && s[j] == t[1]) res++;
      }
    }
    console.log(res);
    return;
  }
  for (let i = 2; i <= n; i++) {
    f[i] = Array(n + 1);
    for (let j = 0; j <= k; j++) {
      f[i][j] = Array(n + 1);
      for (let z = 1; z <= i; z++) {
        if (i == 2) {
          if (z == 1) {
            let dif = (s[0] != t[0]) + (s[1] != t[1]);
            if (j >= dif) f[i][j][z] = 1;
            else {
              let same = (s[0] == t[0]) + (s[1] == t[0]);
              if (same == 1 || j > 0) f[i][j][z] = 0;
            }
          } else {
            let same = (s[0] == t[0]) + (s[1] == t[0]);
            if (j >= 2 - same) f[i][j][z] = 0;
          }
          // console.log(i, j, z, c(i, j, z));
          continue;
        }
        // if (j == 0) {
        //   if (s[i - 1] == t[1]) {
        //     if (z == f0[i]) f[i][j][z] = 1;
        //   } else {
        //     f[i][j][z] = c(i - 1, j, z - (s[i - 1] == t[0]));
        //   }
        //   console.log(i, j, z, c(i, j, z));
        //   continue;
        // }
        if (s[i - 1] == t[1]) {
          f[i][j][z] = Math.max(c(i, j - 1, z), c(i - 1, j, z) + z);
        } else if (s[i - 1] != t[0]) {
          f[i][j][z] = Math.max(c(i - 1, j, z), c(i, j - 1, z), c(i - 1, j - 1, z) + z, c(i - 1, j - 1, z - 1))
        } else {
          f[i][j][z] = Math.max(c(i - 1, j, z - 1), c(i, j - 1, z), c(i - 1, j - 1, z) + z)
        }
        // console.log(i, j, z, f[i][j][z]);
      }
    }
  }
  console.log(Math.max(...f[n][k].filter(v => v)));
})();


let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/); r = 0;
  let [n, k, s, t] = inp;
  n = +n;
  k = +k;
  if (t[0] == t[1]) {
    let x = Math.min([...s].filter(c => c == t[0]).length + k, n);
    console.log(x * (x - 1) / 2);
    return;
  }
  let t0 = Arr(0, n - 1, (i, p) => p + (s[i] == t[0]));
  let t1 = Arr(0, n - 1, (i, p) => p + (s[n - 1 - i] == t[1])).reverse();
  let max = Arr(0, n - 2, i => s[i] == t[0] ? t1[i + 1] : 0).sum();

  For(0, Math.min(k, n - t0[n - 1] - t1[0]), i => {
    let ss = [...s];
    let remain = i;
    For(0, n - 1, i => {
      if (remain <= 0) return 0;
      if (ss[i] != t[0] && ss[i] != t[1]) { ss[i] = t[0]; remain-- }
    })
    For(0, Math.min(k - i, t1[0]), j => {
      let s0 = [...ss];
      let remain = j;
      For(0, n - 1, i => {
        if (remain <= 0) return 0;
        if (s0[i] == t[1]) { s0[i] = t[0]; remain-- }
      })

      For(0, Math.min(k - i - j, n - t0[n - 1] - t1[0]), z => {
        let s1 = [...s0];
        let remain = z;
        For(n - 1, 0, i => {
          if (remain <= 0) return 0;
          if (s1[i] != t[1] && s1[i] != t[0]) { s1[i] = t[1]; remain-- }
        });
        remain = k - i - j - z;
        For(n - 1, 0, i => {
          if (remain <= 0) return 0;
          if (s1[i] == t[0]) { s1[i] = t[1]; remain-- }
        });
        let tt = Arr(0, n - 1, (i, p) => p + (s1[i] == t[0]));
        max = Math.max(max, Arr(1, n - 1, i => s1[i] == t[1] ? tt[i - 1] : 0).sum())
      })

      // console.log(i, j, s0.join(''));
      // remain = k - i - j;
      // let t00 = Arr(0, n - 1, (i, p) => p + (s0[i] == t[0]));
      // let j1 = n - 1;
      // let j2 = n - 1;
      // let sum2 = 0;
      // while (remain > 0 && (j1 >= 0 || j2 >= 0)) {
      //   while (j1 >= 0 && (s0[j1] == t[0] || s0[j1] == t[1])) j1--;
      //   while (j2 >= 0 && s0[j2] != t[0]) {
      //     if (s0[j2] == t[1]) sum2++;
      //     j2--;
      //   }
      //   if ((t00[j1 - 1] || 0) > (t00[j2 - 1] || 0) - sum2) {
      //     s0[j1--] = t[1];
      //     remain--;
      //   } else if ((t00[j2 - 1] || 0) - sum2 >= 0) {
      //     s0[j2--] = t[1];
      //     sum2++;
      //     remain--;
      //   } else break;
      // }
      // t00 = Arr(0, n - 1, (i, p) => p + (s0[i] == t[0]));
      // // console.log(i, j, k - i - j, s0.join(''), Arr(1, n - 1, i => s0[i] == t[1] ? t00[i - 1] : 0).sum());
      // max = Math.max(max, Arr(1, n - 1, i => s0[i] == t[1] ? t00[i - 1] : 0).sum())
    })
  })
  console.log(max);
})();


let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/); r = 0;
  let [n, k, s, t] = inp;
  n = +n;
  k = +k;
  if (t[0] == t[1]) {
    let x = Math.min([...s].filter(c => c == t[0]).length + k, n);
    console.log(x * (x - 1) / 2);
    return;
  }
  let f = Arr(0, n + 1, i => Arr(0, n + 1, i => Arr(0, n + 1, i => -1e5)));
  f[0][0][0] = 0;
  For(0, n, i => {
    For(0, k, j => {
      For(0, i, cnt0 => {
        if (f[i][j][cnt0] < 0) return;
        let e0 = s[i] == t[0];
        let e1 = s[i] == t[1];
        f[i + 1][j][cnt0 + e0] = Math.max(f[i + 1][j][cnt0 + e0], f[i][j][cnt0] + e1 * cnt0);
        f[i + 1][j + 1][cnt0 + 1] = Math.max(f[i + 1][j + 1][cnt0 + 1], f[i][j][cnt0]);
        f[i + 1][j + 1][cnt0] = Math.max(f[i + 1][j][cnt0], f[i][j][cnt0] + cnt0);
      })
    })
  })
  // console.log(f);
  console.log(Arr(0, k, i => Arr(0, n, j => f[n][i][j]).max()[0]).max()[0]);
})();


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    operate(lines);
});

function operate(lines){
     line1=lines[0].split(' ');
    //console.log(line1[0]);
    console.log(line1[1]);
}


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    operate(lines);
});

function operate(lines){
    line1=lines[0].split(' ');
    n=line1[0];
    k=line1[1];
    x=0;
    i=0;
    s=1;
    while(s>0){
        i++;
        x+=i;
        m=x-k;
        s=n-m-i;
    }
    console.log(m);
}


var line = readline();
var n = line.split(' ')[0];
var k = line.split(' ')[1];
var sum = 0;

if(n == 1 && k ==1){
    print(0);
}

for(var i =1; i <= n-1; i++){
    if(gaussSum(i) - (n-i) == k){
        print(n-i);
        break;
    }
}

function gaussSum(n){
    return (n * (n+1))/2;
}


var arr = readline().split(' ').map(item => +item);
var n = arr[0]; k = arr[1];
var i = 0;
var sum = 0;

while(n > 0) {
  i++;
  n--;
  sum += i;
  if(sum >= k && n === sum - k) {
    break;
  }
}

print(n);


function main() {
    // write code here:
    const nk = stdin[0].split(' ').map(Number);
    var i = 0,
        sum = 0;
    while (nk[0] > 0) {
        nk[0]--;
        i++;
        sum += i;
        if (sum >= nk[1] && nk[0] === sum - nk[1]) {
            break;
        }
    }
    console.log(nk[0]);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);


let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  const [n, k] = lines[0].split(' ');
  console.log(getCandiesEaten(parseInt(n, 10), parseInt(k, 10)));
});

function getCandiesEaten(n, k) {
  if (n === 1) return 0;
  n--;
  let candies = 1;
  let sum = 2;
  let consumed = 0;
  while (n > 0) {
    while (candies <= k) {
      candies += sum;
      sum++;
      n--;
    }
    // Reduce candies to less than k
    const candiesToSubtract = candies - k;
    n -= candiesToSubtract;
    consumed += candiesToSubtract;
    candies -= candiesToSubtract;
  }
  return consumed;
}


var n =readline()
var root=Math.sqrt(n)

var nbr=4,curNbr=2,k=1,res=1,ok=false

while(nbr-1<root){
    curNbr=nbr
    nbr*=2
    k++

}

if((nbr-1)*nbr/2==n){
    print(n)
}else{
    while(!ok){
        res= (curNbr-1)*(curNbr/2)
        ok= n%res===0
        curNbr/=2
    }
    print(res)
}


n=parseInt(readline());
c=true;
for(i=n; i>0; i--) {
    if(n%i===0) {
        two=(i).toString(2);
        if(two.length%2===1){
            c=true;
            for(j=0;j<Math.floor(two.length/2)+1;j++){
                if(two[j]==='0') {
                    c=false;
                    break;
                }
            }
            if(c===true){
                for(j=Math.floor(two.length/2)+1;j<two.length;j++){
                    if(two[j]==='1') {
                        c=false;
                        break;
                    }
                }
                if(c===true){
                    print(i);
                    break;
                }
            }
        }
    }
}


n=parseInt(readline());
c=true;
for(i=n; i>0; i--) {
    if(n%i===0) {
        two=(i).toString(2);
        if(two.length%2===1){
            c=true;
            for(j=0;j<Math.floor(two.length/2)+1;j++){
                if(j==='0') {
                    c=false;
                    break;
                }
            }
            if(c===true){
                for(j=Math.floor(two.length/2)+1;j<two.length;j++){
                    if(j==='1') {
                        c=false;
                        break;
                    }
                }
                if(c===true){
                    print(i);
                    break;
                }
            }
        }
    }
}


n=readline();
c=true;
for(i=n; i>0; i--) {
    if(n%i===0) {
        two=(i).toString(2);
        if(two%2===1){
            c=true;
            for(j=0;j<Math.floor(two.length/2)+1;j++){
                if(j==='0') {
                    c=false;
                    break;
                }
            }
            if(c===true){
                for(j=Math.floor(two.length/2)+1;j<two.length;j++){
                    if(j==='1') {
                        c=false;
                        break;
                    }
                }
                if(c===true){
                    print(i);
                    break;
                }
            }
        }
    }
}


n=readline();
c=true;
for(i=n; i>0; i--) {
    if(n%i===0) {
        two=(i).toString(2);
        if(two.length%2===1){
            c=true;
            for(j=0;j<Math.floor(two.length/2)+1;j++){
                if(j==='0') {
                    c=false;
                    break;
                }
            }
            if(c===true){
                for(j=Math.floor(two.length/2)+1;j<two.length;j++){
                    if(j==='1') {
                        c=false;
                        break;
                    }
                }
                if(c===true){
                    print(i);
                    break;
                }
            }
        }
    }
}


var n = readline(),
    a = readline().split(' ').map(v => +v);
var s = 0;
while(a.length) {
    var l = a.length,
        m = Infinity,
        mi = 1;
    for(var i = 1; i < l; i++) {
        var lm = Math.abs(a[0] - a[i]);
        if(lm < m) {
            m = lm;
            mi = i;
        }
    }
    s += m;
    a.splice(mi, 1);
    a.splice(0, 1);
}
write(s);


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

    const input = lines[1];
    const vector = input.split(' ').map(
        n => parseInt(n)
    );

    const insertionSort = (vector) => {
        let res = 0;

        for (let i = 0; i < vector.length; i++) {
            let minIndex = i;

            for (let j = i + 1; j < vector.length; j++) {
                if (vector[j] < vector[minIndex]) {
                    minIndex = j;
                }
            }

            let temp = vector[i];
            vector[i] = vector[minIndex];
            vector[minIndex] = temp;

            if (i !== 0 && i % 2 === 1) {
                res += vector[i] - vector[i -1]
            }
        }

        console.log(res);
    };
});

//////


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

    const input = lines[1];
    const vector = input.split(' ').map(
        n => parseInt(n)
    );

    const insertionSort = (vector) => {
        let res = 0;

        for (let i = 0; i < vector.length; i++) {
            let minIndex = i;

            for (let j = i + 1; j < vector.length; j++) {
                if (vector[j] < vector[minIndex]) {
                    minIndex = j;
                }
            }

            let temp = vector[i];
            vector[i] = vector[minIndex];
            vector[minIndex] = temp;

            if (i !== 0 && i % 2 === 1) {
                res += vector[i] - vector[i -1]
            }
        }

        console.log(res);
    };
});


readline();
const input = readline();
const vector = input.split(' ').map(
    n => parseInt(n)
);

const insertionSort = (vector) => {
    let res = 0;

    for (let i = 0; i < vector.length; i++) {
        let minIndex = i;

        for (let j = i + 1; j < vector.length; j++) {
            if (vector[j] < vector[minIndex]) {
                minIndex = j;
            }
        }

        let temp = vector[i];
        vector[i] = vector[minIndex];
        vector[minIndex] = temp;

        if (i !== 0 && i % 2 === 1) {
            res += vector[i] - vector[i -1]
        }
    }

    write(res);
};

insertionSort(vector);


let size = parseInt(prompt('input elements count'));
let vector = [];

for (let i = 0; i < size; i++) {
	let element = prompt('enter element');
	vector.push(element);
}

let shiftSize = parseInt(prompt('enter shift size'));

for (let i = 0; i < shiftSize; i++) {
	vector.push(vector[0]);
	vector.shift();
}

alert(vector.join(' '));


//var input = readline()
var k = readline()

var n = readline().split(' ')
n.sort((a,b) => { return a - b })
//print(n)
//print(n[0]+' '+n[1])
var a = 0, b = 0
for(var i=0; i<k; i++) {
         if(i%2 == 0) {
            a += parseInt(n[i])
         }
         else {
            b += parseInt(n[i])
         }
     }
    // print(a+' '+b)
print(Math.abs(a-b))


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  const arr = d.split(' ').map(Number).sort((a, b) => a - b);
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    if (i % 2) {
      ans += arr[i];
    }
    else {
      ans -= arr[i];
    }
  }

  console.log(Math.abs(ans));

  c++;
});


var n = readline(),
    a = readline().split(' ').map(v => +v);
a.sort((a,b) => a - b);
var s = 0;
while(n) {
    var m = 100,
        mi = 1;
    for(var i = 1; i < n; i++) {
        var lm = Math.abs(a[0] - a[i]);
        if(lm < m) {
            m = lm;
            mi = i;
        }
    }
    s += m;
    a.splice(mi, 1);
    a.splice(0, 1);
    n -= 2;
}
write(s);


let input = [];

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

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

RL.on('close', () => {
    let n = parseInt(input[0]);
    let num = []; input[1].split(' ').forEach(i => num.push(parseInt(i)));
    num.sort((a, b) => a-b);
    let answer = 0;
    for(let i = 1; i < n; i+=2){
        answer += num[i]-num[i-1];
    }
    console.log(answer);
});


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
    .replace(/\s*$/, "")
    .split("\n")
    .map((str) => str.replace(/\s*$/, ""));

  main();
});

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

function main() {
  const nd = readLine().split(" ");
  const length = parseInt(nd[0], 10);
  const array = readLine()
    .split(" ")
    .map((aTemp) => parseInt(aTemp, 10));

  let count = 0;
  for (let i = 0; i < length - 1; i++) {
    for (let j = 1; j < length; j++) {
      if (array[j - 1] > array[j]) {
        [array[j - 1], array[j]] = [array[j], array[j - 1]];
      }
    }
  }
  for (let g = 0; g < array.length; g += 2) {
    if (array[g + 1] > array[g]) {
      count += array[g + 1] - array[g];
    }
  }
  console.log(count);
}

// sortTeams(length, students);

// const input = prompt("Friends");

// const meetFriends = () => {
//   let friends = input.split(" ");
//   let distance = 0;

//   for (let i = 1; i < friends.length; i++) {
//     let current = friends[i];

//     let index = i;

//     while (index >= 0 && current < friends[index - 1]) {
//       friends[index] = friends[index - 1];
//       index--;
//     }
//     friends[index] = current;
//   }
//   distance = friends[2] - friends[0];
//   console.log(distance);
// };

// meetFriends(input);

// const input1 = parseInt(prompt("First length"))
// const input2 = prompt("First text")
// const input3 = parseInt(prompt("Second length"))
// const input4 = prompt("Second text")

// const chooseTwoNumbers = () => {
//   let first = input2.split(" ");
//   let second = input4.split(" ");

//   for (let i = 1; i < input1; i++) {
//     let current = first[i];

//     let index = i;

//     while (index >= 0 && current < first[index - 1]) {
//       first[index] = first[index - 1];
//       index--;
//     }
//     first[index] = current;
//   }
//   for (let i = 1; i < input3; i++) {
//     let current = second[i];

//     let index = i;

//     while (index >= 0 && current < second[index - 1]) {
//       second[index] = second[index - 1];
//       index--;
//     }
//     second[index] = current;
//   }

//   if (
//     first[input1 - 1] >= second[input3 - 1] &&
//     first[0] >= second[input3 - 1]
//   ) {
//     console.log("YES");
//   } else if (first[input1 - 1] <= second[0] && first[0] <= second[0]) {
//     console.log("YES");
//   } else {
//     console.log("NO");
//   }
// };

// chooseTwoNumbers();


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

    const input = lines[1];
    const vector = input.split(' ').map(
        n => parseInt(n)
    );

    const insertionSort = (vector) => {
        let res = 0;

        for (let i = 0; i < vector.length; i++) {
            let minIndex = i;

            for (let j = i + 1; j < vector.length; j++) {
                if (vector[j] < vector[minIndex]) {
                    minIndex = j;
                }
            }

            let temp = vector[i];
            vector[i] = vector[minIndex];
            vector[minIndex] = temp;

            if (i !== 0 && i % 2 === 1) {
                res += vector[i] - vector[i -1]
            }
        }

        console.log(res);
    };

    insertionSort(vector);
});

//////


//var input = readline()
var k = readline()

var n = readline().split(' ')
n.sort((a, b) => (a - b))

var a = 0, b = 0
for(var i=0; i<k; i+=2) {
     a += parseInt(n[i]);
}
for(var i=1; i<k; i+=2) {
    b += parseInt(n[i]);
}

print(Math.abs(a-b))


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

let l = 0;
rl.on('line', (input) => {
    if (l == 0) { l++ }
    else {
        rl.close();
        let strArray = input.split(" ")
        let s = strArray.map(function (item) {
            return parseInt(item, 10);
        });
        s = s.sort(function sortNumber(a, b) {
            return a - b;
        })
        let res = 0;
        for (let i = 0; i < input.length; i += 2) {
            let d = s[i + 1] - s[i]
            if (d > 0) {
                res += d
            }
        }
        console.log(res)
        return 0;
    }
});


var n = readline();
var ni = readline().split(' ');
var output = 0;

for(var i=0; i<n; i++){
    ni[i] = parseInt(ni[i]);
}

ni = ni.sort(compareNumeric);

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

for(var i=0; i<n; i=i+2){

	output = output + ni[i+1] - ni[i];

}

print(output);


let input ='';

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data',(data)=>input+=data)
process.stdin.on('end',()=>{
    let count = 0;
    let tmp = input.split('\n');
    let arr = tmp[1].split(' ').map((val)=>+val).sort((a,b)=>a-b);

    for(let i = 0; i < arr.length; i+=2){
        count+=Math.abs(arr[i]-arr[i+1])
    }
   console.log(count)
})


//Don't have to see. start------------------------------------------
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 = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
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){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
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;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  list.sort(function(a,b){
  	return a - b;
  });
  var output = 0;
  for(var i = 0; i < N; i += 2){
    output += list[i + 1] - list[i];
  }
  myout(output);
}


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

  let l=0;
  rl.on('line', (input) => {
      if (l==0) {l++}
      else {
           rl.close();
           let strArray = input.split(" ")
           let s = strArray.map(function(item) {
            return parseInt(item, 10);
        });
           s = s.sort(function sortNumber(a,b) {
            return a - b;
        })
           let res=0;
           for(let i=0;i<input.length; i+=2){
            let d = s[i+1]-s[i]
            if(d>0) {
                res+=d
            }
        }
        console.log(res)
    return 0;
}
});


let stdin = process.stdin;
stdin.setEncoding('utf8');
stdin.on('data', function (data) {
    let input = data.split('\n');
    let n = input[0].split(' ').map(function (a) { return parseInt(a); });
    let k = input[1].split(' ').map(function (a) { return parseInt(a); });
    let result = solution(n, k);
    console.log(result);
});

// End of interface

const solution = (n, studentsArray) => {
	let res = 0;
	studentsArray.sort(function(a, b){return a-b});
	for (let i = 0; i<n-1; i=i+2){
		res = res + (studentsArray[i+1]-studentsArray[i]);
	}
	return res;
};


String.prototype.insert = function (index, string) {
  if (index > 0)
    return this.substring(0, index) + string + this.substring(index, this.length);
  else
    return string + this;
};
String.prototype.reverse= function(){
    return this.split('').reverse().join('');
}

function solve(){
    var s = readline();
    var alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
    for(var i = 0; i <= s.length; ++i){
        for(var j = 0; j < alphabet.length; ++j){
            var s1 = s.insert(i,alphabet[j]);
            var s2 = s1.reverse();
            if(s1 == s2){
                print(s1);
                return;
            }
        }
    }
    print("NA");
}
solve();


(function() {

var alpha = "abcdefghijklmnopqrstuvwxyz";
var str = readline();

for(var i = 0; i <= str.length; i++) {
    for(var j = 0; j < alpha.length; j++) {
        var res = str.substr(0,i)+alpha[j]+str.substr(i);
        if(isPalin(res))
            return print(res);
    }
}

print("NA");

function isPalin(s) {
    for(var i = 0; i < s.length/2; i++) {
        if(s[i] !== s[s.length-1-i])
            return false;
    }
    return true;
}

})();


const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.question("", function {
    let ans = word.split('')
    let j = ans.length - 1;
    let ans2 = ans.join('');
    let found = false
    for(let i = 0; !found  && i < ans.length; i++){
        for(let j = 0; j < ans.length; j++){
            let ans1 = ans2.slice(0, i) + ans[j] + ans2.slice(i, ans.length )
            if(checkPolindrom(ans1)){
                found = true;
                console.log(ans1);
                break;
            }
        }
    }

    for(let i = 0; !found  && i < ans.length; i++){
        if(ans[i] !== ans[j]){
            let ans1 = ans2 + ans[j];
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
            ans1 = ans[j] + ans2;
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
            ans1 = ans[i] + ans2;
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
            ans1 = ans2 + ans[i];
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
        }
    }
    if(!found)
        console.log('NA')
    process.exit(0)
})

rl.on("close", function() {
    console.log("\nBYE BYE !!!");
    process.exit(0);
});

function checkPolindrom(ans1){
    var splitString = ans1.split("");
    var reverseArray = splitString.reverse();
    let check = reverseArray.join("");
    return check === ans1;
}


(function() {

var alpha = "abcdefghijklmnopqrstuvwxyz";
var str = readline();

for(var i = 0; i <= str.length; i++) {
    for(var j = 0; j < alpha.length; j++) {
        var res = s.substr(0,i)+alpha[j]+s.substr(i);
        if(isPalin(res))
            return print(res);
    }
}

print("NA");

function isPalin(s) {
    for(var i = 0; i < s.length/2; i++) {
        if(s[i] !== s[s.length-1-i])
            return false;
    }
    return true;
}

})();


//Don't have to see. start------------------------------------------
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↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
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){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
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;}}

//Don't have to see. end------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextCharArray();
	var output = "";
	var isOne = false;
	for(var i = 0; i < N; i++){
		if(list[i] == "0"){
			output += "0";
		}else{
			isOne = true;
		}
	}
	if(isOne){
		myout("1" + output);
	}else{
		myout("0");
	}

}


m=Number(readline()) ;
arr=readline() ;
ans="1"
for(j=0;j<m;j++)
    if(arr[j]=="0")
          ans+="0"
if(m>1)
    print(ans);
else
    print(arr)


var n = readline();
var g = readline().split("");

var zeros = 0;
var ones = 0;
for(i=0;i<g.length;i++){
    if(Number(g[i]) == 0)
        zeros++;
    else if(Number(g[i]) == 1)
        ones++;
}

var output = "";
if(ones != 0){
    for(i=0;i<zeros;i++){
        output += "0";
    }
    print("1" + output);
}else{
    print(0);
}


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (str) => {
  if (c === 0) {
    c++;
    return;
  }

  let ones = 0;
  let zeros = 0;

  for (let i = 0; i < str.length; i++) {
    if (str[i] === '1') {
      ones++;
    }
    else {
      zeros++;
    }
  }

  if (ones === 0) {
    console.log(0);
  }
  else {
    console.log(`1${'0'.repeat(zeros)}`);
  }

  c++;
});


var N = readline().split("");
var S = readline().split("");

var cnt = 0;

S.forEach((item) => {
    if (item === '0') {
        cnt++;
    }
});

var ans = "";
ans += S[0];

if (S[0] === '0') {
    cnt--;
}

for (var i = 0; i < cnt; i++) {
    ans += '0';
}

print(ans);


m=Number(readline()) ;
arr=readline() ;
ans="1"
for(j=0;j<m;j++)
{
    if(arr[j]=="0")
    {
        ans+="0"
    }
}
if(m>1)
    print(ans);
else
    print(arr)


var N = readline().split("");
var S = readline().split("");

var cnt = 0;

S.forEach((item) => {
    if (item === '0') {
        cnt++;
    }
});

print(S[0]);
if (S[0] === '0') {
    cnt--;
}

for (var i = 0; i < cnt; i++) {
    print('0');
}


/*a=readline().split(" ").map(Number) ;
n=a[0];
m=a[1];
*/

m=Number(readline()) ;
    arr=readline() ;
    ans="1"
   for(j=0;j<m;j++)
    {
        if(arr[j]=="0")
        {
          ans+="0"
        }

    }
if(m>2)
    print(ans);
else
    print("0")


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]);
	};
	return tokens;
}

function parse(number, inputBase) {
	var power = 1, total = 0;
	while (number != 0) {
		var digit = number%10;
		total += digit*power;
		number = (number-digit)/10;
		power *= inputBase;
	}
	return total;
}

function generate(number, base) {
	var digits = [];
	while (true) {
		digits.push(number%base);
		number = Math.floor(number/base);
		if (number == 0) {
			break;
		}
	}
	digits.reverse();
	return digits.join("");
}

function findLargestDigit(number) {
	var best = 0;
	while (number != 0) {
		best = Math.max(best, number%10);
		number = Math.floor(number/10);
	}
	return best;
}

function main() {
	var data = tokenizeIntegers(readline());
	var base = Math.max(findLargestDigit(data[0]),
			findLargestDigit(data[1])) + 1;
	var sum = parse(data[0], base) + parse(data[1], base);
	print(generate(sum, base).length);
}

main();


'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let a = lll[0]
let b = lll[1]

let min = String(a).split('').reduce((r, v) => Math.max(r, v), 0)
min = String(b).split('').reduce((r, v) => Math.max(r, v), min)
min++

let max = 0
for (let i = min; i < 14; i++) {
  let da = parseInt(a, i)
  let db = parseInt(b, i)
  let ds = da + db
  let bs = from10(ds, i)
  max = Math.max(max, String(bs).length)
}

print(max)

function from10 (x, b) {
  let res = ''
  let n = 0
  while (Math.pow(b, ++n) <= x) {}
  while (n--) {
    let a = x / Math.pow(b, n) | 0
    if (b > 9) {
      res += 'a'
    } else {
      res += a
    }
    x -= a * Math.pow(b, n)
  }
  return res
}


'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let a = lll[0]
let b = lll[1]

let min = String(a).split('').reduce((r, v) => Math.max(r, v), 0)
min = String(b).split('').reduce((r, v) => Math.max(r, v), min)
min++

let max = 0
for (let i = min; i < 14; i++) {
  let da = to10(a, i)
  let db = to10(b, i)
  let ds = da + db
  let bs = from10(ds, i)
  max = Math.max(max, String(bs).length)
}

print(max)

function to10 (x, b) {
  return String(x).split('').reduce((r, v, i) => r + v * Math.pow(b, i), 0)
}

function from10 (x, b) {
  let res = ''
  let n = 0
  while (Math.pow(b, ++n) <= x) {}
  while (n--) {
    let a = x / Math.pow(b, n) | 0
    if (b > 9) {
      res += 'a'
    } else {
      res += a
    }
    x -= a * Math.pow(b, n)
  }
  return res
}


'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let a = lll[0]
let b = lll[1]

let min = String(a).split('').reduce((r, v) => Math.max(r, v), 0)
min = String(b).split('').reduce((r, v) => Math.max(r, v), min)
min++

let max = 0
for (let i = min; i < 14; i++) {
  let ba = from10(a, i)
  let bb = from10(b, i)
  let da = to10(ba, i)
  let db = to10(bb, i)
  let ds = da + db
  let bs = from10(ds, i)
  max = Math.max(max, String(bs).length)
}

print(max)

function to10 (x, b) {
  return String(x).split('').reduce((r, v, i) => r + v * Math.pow(b, i), 0)
}

function from10 (x, b) {
  let res = ''
  let n = 0
  while (Math.pow(b, ++n) <= x) {}
  while (n--) {
    let a = x / Math.pow(b, n) | 0
    res += a
    x -= a * Math.pow(b, n)
  }
  return res
}


'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let a = lll[0]
let b = lll[1]

let min = String(a).split('').reduce((r, v) => Math.max(r, v), 0)
min = String(b).split('').reduce((r, v) => Math.max(r, v), min)

let max = 0
if (min == 1) {
  max = a + b
} else {
  for (let i = min; i < 14; i++) {
    let ba = parseInt(a, i)
    let bb = parseInt(b, i)
    let da = to10(ba, i)
    let db = to10(bb, i)
    let ds = da + db
    let bs = parseInt(ds, i)
    max = Math.max(max, String(bs).length)
  }
}

print(max)

function to10 (x, b) {
  return String(x).split('').reduce((r, v, i) => r + v * Math.pow(b, i), 0)
}


'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let a = lll[0]
let b = lll[1]

let min = String(a).split('').reduce((r, v) => Math.max(r, v), 0)
min = String(b).split('').reduce((r, v) => Math.max(r, v), min)
min++

let max = 0
for (let i = min; i < 14; i++) {
  let da = to10(a, i)
  let db = to10(b, i)
  let ds = da + db
  let bs = from10(ds, i)
  max = Math.max(max, String(bs).length)
}

print(max)

function to10 (x, b) {
  return String(x).split('').reduce((r, v, i) => r + v * Math.pow(b, i), 0)
}

function from10 (x, b) {
  let res = ''
  let n = 0
  if (b > 9) return parseInt(x, b)
  while (Math.pow(b, ++n) <= x) {}
  while (n--) {
    let a = x / Math.pow(b, n) | 0
    res += a
    x -= a * Math.pow(b, n)
  }
  return res
}


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]);
	};
	return tokens;
}

function parse(number, inputBase) {
	var power = 1, total = 0;
	while (number != 0) {
		var digit = number%10;
		total += digit*power;
		number = (number-digit)/10;
		power += inputBase;
	}
	return total;
}

function generate(number, base) {
	var digits = [];
	while (true) {
		digits.push(number%base);
		number = Math.floor(number/base);
		if (number == 0) {
			break;
		}
	}
	digits.reverse();
	return digits.join("");
}

function findLargestDigit(number) {
	var best = 0;
	while (number != 0) {
		best = Math.max(best, number%10);
		number = Math.floor(number/10);
	}
	return best;
}

function main() {
	var data = tokenizeIntegers(readline());
	var base = Math.max(findLargestDigit(data[0]),
			findLargestDigit(data[1])) + 1;
	var sum = parse(data[0], base) + parse(data[1], base);
	print(generate(sum, base).length);
}

main();


var line = readline().split(' ')
var a = line[0].split("")
var k = parseInt(line[1])

for (var i = 0; i + 1 < a.length; i++) {
	var p = i
	for (var j = 1; j <= k && i + j < a.length; j++) {
		var q = i + j
		if (a[q] > a[p]) p = q
	}

	for (var j = p - 1; j >= i; j--) {
		var t = a[j]
		a[j] = a[j + 1]
		a[j + 1] = t
	}

	k -= p - i
}

print(a.join(""))


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 data = tokenize(readline()),
		digits = data[0].split(''), n = digits.length,
		swapNum = parseInt(data[1]);
	for (var i = 0; i < digits.length; ++i) {
		digits[i] = parseInt(digits[i]);
	}
	for (var pos = 0; swapNum > 0 && pos < n; ++pos) {
		var max = digits[pos], best = pos,
			limit = Math.min(pos+swapNum, n-1);
		for (var seek = pos+1; seek <= limit; ++seek) {
			if (digits[seek] > max) {
				best = seek;
				max = digits[seek];
			}
		}
		if (best != pos) {
			for (var i = best; i > pos; --i) {
				digits[i] = digits[i-1];
			}
			digits[pos] = max;
			swapNum -= (best-pos);
		}
	}
	print(digits.join(''));
}

main();


var nm = readline().trim().split(' ');
var a=nm[0],k=parseInt(nm[1]);

var cursor = 0;
var iMaxi = 0;

while(k>0 && cursor<a.length){
    //print(';;;;cursor',cursor);
    var found = false;
    var maxi=a[cursor];
    for(var i=(cursor+1);i<=Math.min(cursor+k,a.length-1);i++){
        //print('com',maxi,a[i])
        if(maxi<a[i]){
          //  print(maxi,a[i])
            found=true;
            iMaxi=i;
            maxi = a[i];
        }
    }
    if(found){
      //  print("----",a.substring(0,cursor), maxi,a.substring(cursor,iMaxi), a.substring(iMaxi+1))
        a =a.substring(0,cursor)+ maxi+a.substring(cursor,iMaxi)+ a.substring(iMaxi+1);

       // print('nbr',iMaxi,cursor,iMaxi-cursor)
        k-=iMaxi-cursor;

    }
    cursor++;

//n    print("====",a)
}
print(a);


var line = readline().split(' ')
var a = line[0].split("")
var k = parseInt(line[1])

for (var i = 0; i + 1 < a.length; i++) {
	var p = i
	for (var j = 1; j <= k && i + j < a.length; j++) {
		var q = i + j
		if (a[q] > a[p]) p = q
	}

	var t = a[i]
	a[i] = a[p]
	a[p] = t

	k -= p - i
}

print(a.join(""))


var nm = readline().trim().split(' ').map((x)=>parseInt(x));
var a=nm[0]+"",k=nm[1];

var cursor = 0;
var iMaxi = 0;

while(k>0 && cursor<a.length){
    //print('cursor',cursor);
    var found = false;
    var maxi=a[cursor];
    for(var i=(cursor+1);i<=(cursor+k);i++){
      //  print('com',maxi,a[i])
        if(maxi<a[i]){
        //    print(maxi,a[i])
            found=true;
            iMaxi=i;
            maxi = a[i];
        }
    }
    if(found){
        //print("----",a.substring(0,cursor), maxi,a.substring(cursor,iMaxi), a.substring(iMaxi+1))
        a =a.substring(0,cursor)+ maxi+a.substring(cursor,iMaxi)+ a.substring(iMaxi+1);

        //print('nbr',iMaxi,cursor,iMaxi-cursor)
        k-=iMaxi-cursor;
        cursor=iMaxi+1;
    }else{
        cursor++;
    }
}
print(a);


'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const n = this.lines[this.lineIndex]
    return (this.lineIndex += 1), n
  }
  readIntegersOfLine() {
    const n = this.readLine().match(integerRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  readNumsOfLine() {
    const n = this.readLine().match(decimalRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  print(n) {
    stdout.write(n)
  }
  async init() {
    const n = await this.readLines()
    this.lines = n
  }
  readLines() {
    const n = []
    return new Promise(e => {
      stdin.on('data', e => n.push(e)),
        stdin.on('end', function () {
          const t = n.join('').split(os.EOL)
          e(t)
        })
    })
  }
}
async function __main__(n) {
  const e = new InputAndOutput()
  await e.init(), n(e)
}
const MOD = BigInt(1000000007),
  MAX_N = 200010,
  f = new Array(MAX_N)
function solve(n, e) {
  if (0 === e) return 1n
  return (
    (((fastPower(2n, BigInt(n) * BigInt(e), MOD) -
      fastPower(f[n], BigInt(e), MOD)) %
      MOD) +
      MOD) %
    MOD
  )
}
function fastPower(n, e, t) {
  let i = 1n
  for (let s = e, r = n; s > 0; s /= 2n, r = (r * r) % t)
    s % 2n === 1n && (i = (i * r) % t)
  return i
}
__main__(function (n) {
  ;(f[0] = 0n), (f[1] = 1n), (f[2] = 2n)
  for (let n = 3; n < MAX_N; ++n) f[n] = (f[n - 1] + f[n - 2]) % MOD
  const e = Number(n.readLine())
  for (let t = 1; t <= e; ++t) {
    const [e, t] = n.readIntegersOfLine(),
      i = solve(e, t)
    n.print(i + '\n')
  }
})


'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const n = this.lines[this.lineIndex]
    return (this.lineIndex += 1), n
  }
  readIntegersOfLine() {
    const n = this.readLine().match(integerRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  readNumsOfLine() {
    const n = this.readLine().match(decimalRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  print(n) {
    stdout.write(n)
  }
  async init() {
    const n = await this.readLines()
    this.lines = n
  }
  readLines() {
    const n = []
    return new Promise(e => {
      stdin.on('data', e => n.push(e)),
        stdin.on('end', function () {
          const t = n.join('').split(os.EOL)
          e(t)
        })
    })
  }
}
async function __main__(n) {
  const e = new InputAndOutput()
  await e.init(), n(e)
}
const MOD = BigInt(1000000007)
function solve(n, e) {
  if (0 === e) return 1n
  const t =
    1 & n
      ? fastPower(2n, BigInt(n - 1), MOD) + 1n
      : fastPower(2n, BigInt(n - 1), MOD)
  return fastPower((t + MOD) % MOD, BigInt(e), MOD)
}
function fastPower(n, e, t) {
  let s = 1n
  for (let i = e, r = n; i > 0; i /= 2n, r = (r * r) % t)
    i % 2n === 1n && (s = (s * r) % t)
  return s
}
__main__(function (n) {
  const e = Number(n.readLine())
  for (let t = 1; t <= e; ++t) {
    const [e, t] = n.readIntegersOfLine(),
      s = ((solve(e, t) % MOD) + MOD) % MOD
    n.print(s + '\n')
  }
})


'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const n = this.lines[this.lineIndex]
    return (this.lineIndex += 1), n
  }
  readIntegersOfLine() {
    const n = this.readLine().match(integerRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  readNumsOfLine() {
    const n = this.readLine().match(decimalRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  print(n) {
    stdout.write(n)
  }
  async init() {
    const n = await this.readLines()
    this.lines = n
  }
  readLines() {
    const n = []
    return new Promise(e => {
      stdin.on('data', e => n.push(e)),
        stdin.on('end', function () {
          const t = n.join('').split(os.EOL)
          e(t)
        })
    })
  }
}
async function __main__(n) {
  const e = new InputAndOutput()
  await e.init(), n(e)
}
const MOD = BigInt(1000000007),
  MAX_N = 200010,
  f = new Array(MAX_N)
function solve(n, e) {
  if (0 === e) return 1n
  const t = f[n - 1]
  if (1 & n) return fastPower(t + 1n, BigInt(e), MOD)
  let s = fastPower(t - 1n, BigInt(e), MOD),
    i = 1n
  for (let n = 1; n <= e; ++n) (s += i * f[e - n]), (i = (i * t) % MOD)
  return s
}
function fastPower(n, e, t) {
  let s = 1n
  for (let i = e, r = n; i > 0; i /= 2n, r = (r * r) % t)
    i % 2n === 1n && (s = (s * r) % t)
  return s
}
__main__(function (n) {
  f[0] = 1n
  for (let n = 1; n < MAX_N; ++n) f[n] = (2n * f[n - 1]) % MOD
  const e = Number(n.readLine())
  for (let t = 1; t <= e; ++t) {
    const [e, t] = n.readIntegersOfLine(),
      s = ((solve(e, t) % MOD) + MOD) % MOD
    n.print(s + '\n')
  }
})


'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
const MOD = BigInt(1000000007)
function solve(e, n) {
  if (0 === n) return 1n
  const t = fastPower(2n, BigInt(e - 1), MOD)
  let s = fastPower((t + MOD) % MOD, BigInt(n), MOD)
  if (0 == (1 & e)) return s
  for (let e = 1; e <= n; ++e)
    s += fastPower(t, BigInt(e - 1), MOD) * fastPower(2n, BigInt(n - e), MOD)
  return s
}
function fastPower(e, n, t) {
  let s = 1n
  for (let i = n, r = e; i > 0; i /= 2n, r = (r * r) % t)
    i % 2n === 1n && (s = (s * r) % t)
  return s
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      s = ((solve(n, t) % MOD) + MOD) % MOD
    e.print(s + '\n')
  }
})


'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
function fastModuloPower(e, n, t) {
  let r = 1n
  for (let s = n, i = e; s > 0; s >>= 1, i = (i * i) % t)
    1 & s && (r = (r * i) % t)
  return r
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
const MOD = BigInt(1000000007),
  MAX_N = 200010,
  f = new Array(MAX_N),
  h = new Array(MAX_N)
function solve(e, n) {
  if (0 === n) return 1n
  const t = 1 & e ? f[e - 1] + 1n : f[e - 1] - 1n,
    r = fastModuloPower(t, n, MOD)
  if (1 & e) return r
  for (let t = 0, r = 1n; t <= n; ++t, r = (r * f[e]) % MOD) h[t] = r
  let s = 0n
  for (let e = 1, r = 1n; e <= n; ++e)
    (s += (r * h[n - e]) % MOD), (r = (r * t) % MOD)
  return (((fastModuloPower(f[e], n, MOD) - s * f[e - 1]) % MOD) + MOD) % MOD
}
__main__(function (e) {
  f[0] = 1n
  for (let e = 1; e < MAX_N; ++e) f[e] = (2n * f[e - 1]) % MOD
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      r = solve(n, t)
    e.print(r + '\n')
  }
})


print(function(s) {

	var x = {};
	for (var i = 0; i <= 9; i++)
		x[readline()] = i;

	return s.replace(/[01]{10}/g, function(v) {
		return x[v];
	});

}(readline()));


;(function () {
	print(function () {
		var s = readline().split(''), l = [];
		for (var i = 0; i < 8; i++) {
			l.push(s.splice(0, 10).join(''));
		}

		var n = [], s = 10;
		while (s--) {
			n.push(readline());
		}

		l.forEach(function (e, i) {
			l[i] = n.indexOf(e);
		});

		return l.join('');
	}());
}.call(this));


function cmp(a,b)
{
    return a-b;
}

var s = readline();
var res=10
for (var i=0;i<=999999;i++)
{
    var z=i+''
    while(z.length<6)
    {
        z='0'+z
    }
    var a=+z[0]
    var b=+z[1]
    var c=+z[2]
    var d=+z[3]
    var e=+z[4]
    var f=+z[5]
    if (a+b+c==d+e+f)
    {
        var kol=6;
        for (var j=0;j<6;j++)
        {
            if (s[j]==z[j]){kol--;}
        }
        if (res>kol){res=kol;}
    }
}
print(res)