You are given two strings $$$s$$$ and $$$t$$$ consisting of lowercase Latin letters. The length of $$$t$$$ is $$$2$$$ (i.e. this string consists only of two characters).In one move, you can choose any character of $$$s$$$ and replace it with any lowercase Latin letter. More formally, you choose some $$$i$$$ and replace $$$s_i$$$ (the character at the position $$$i$$$) with some character from 'a' to 'z'.You want to do no more than $$$k$$$ replacements in such a way that maximizes the number of occurrences of $$$t$$$ in $$$s$$$ as a subsequence.Recall that a subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 200$$$; $$$0 \le k \le n$$$) — the length of $$$s$$$ and the maximum number of moves you can make. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. The third line of the input contains the string $$$t$$$ consisting of two lowercase Latin letters.

Print one integer — the maximum possible number of occurrences of $$$t$$$ in $$$s$$$ as a subsequence if you replace no more than $$$k$$$ characters in $$$s$$$ optimally.

NoteIn the first example, you can obtain the string "abab" replacing $$$s_1$$$ with 'a' and $$$s_4$$$ with 'b'. Then the answer is $$$3$$$.In the second example, you can obtain the string "ssddsdd" and get the answer $$$10$$$.In the fourth example, you can obtain the string "aaacaaa" and get the answer $$$15$$$.

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 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;
  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;
  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;
      }

      // 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 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;
  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);
})();


Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.

The first line of the input contains a positive integer n (1 ≤ n ≤ 2·109) — the length of Pasha's stick.

The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.

NoteThere is only one way to divide the stick in the first sample {1, 1, 2, 2}.Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.

var n = +readline();

if(n%2 == 1){
    write(0);
}else{
    n = n/2;
    if(n%2 == 1){
        write(Math.floor(n/2));
    }else{
        write(n/2 - 1);
    }
}

function main(n){

    if(n % 2 !== 0){
      print(0);
      return;
    }
    else if(n % 4 !== 0){
      print(Math.floor(n/4));
    }
    else{
      print((n/4) - 1);
    }
}

var n = parseInt(readline());

// var arr = readline().split(' ');
// for(var i = 0  ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n);

var n=~~readline();
var count=0;
if(n%2!=0) print("0");
else{
    var a=n/2;
    print (Math.ceil(a/2)-1);
}

w = ~~readline()
 c= 0
if(w%2==0) {
w /= 2
c =Math.ceil(w/2) -1

}
print(c)

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let stickLength;
let lines=0;
rl.on('line', (input,index) => {
    let res=input.split(" ");

        stickLength=Number(res[0]);

    lines++;
}).on('close', () => {
    getRectangleStick(stickLength);
});

function getRectangleStick(stickLength) {
    if(stickLength<=2000000000 && stickLength%2 === 0){
        if(stickLength%4===0){
            console.log(Math.trunc((stickLength-1)/4));
        }else{
            console.log(Math.trunc(stickLength/4));
        }
    }else{
        console.log(0);
    }
}

var n = +readline();
if(n%2 == 1) write(0);

n = n/2;
if(n%2 == 1){
    write(Math.floor(n/2));
}else{
    write(n/2 - 1);
}

function main(n){

    if(n % 2 !== 0){
      print(-1);
      return;
    }
    else if(n % 4 !== 0){
      print(Math.floor(n/2));
    }
    else{
      print((n/2) - 1);
    }
}

var n = parseInt(readline());

// var arr = readline().split(' ');
// for(var i = 0  ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n);

function main(n){

    if(n % 2 !== 0){
      print(-1);
      return;
    }
    else if(n % 4 !== 0){
      print(Math.floor(n/4));
    }
    else{
      print((n/4) - 1);
    }
}

var n = parseInt(readline());

// var arr = readline().split(' ');
// for(var i = 0  ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n);

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let stickLength;
let lines=0;
rl.on('line', (input,index) => {
    let res=input.split(" ");

        stickLength=Number(res[0]);

    lines++;
}).on('close', () => {
    getRectangleStick(stickLength);
});

function getRectangleStick(stickLength) {
    if(stickLength<=2000000000){
        if(stickLength%4===0){
            console.log(Math.trunc((stickLength-1)/4));
        }else{
            console.log(Math.trunc(stickLength/4));
        }
    }else{
        console.log(0);
    }
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let stickLength;
let lines=0;
rl.on('line', (input,index) => {
    let res=input.split(" ");

        stickLength=Number(res[0]);

    lines++;
}).on('close', () => {
    getRectangleStick(stickLength);
});

function getRectangleStick(stickLength) {
    if(stickLength%4===0){
        console.log(Math.trunc((stickLength-1)/4));
    }else{
        console.log(Math.trunc(stickLength/4));
    }
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let stickLength;
let lines=0;
rl.on('line', (input,index) => {
    let res=input.split(" ");

        stickLength=Number(res[0]);

    lines++;
}).on('close', () => {
    getRectangleStick(stickLength);
});

function getRectangleStick(stickLength) {
    if(stickLength<1000000){
        if(stickLength%4===0){
            console.log(Math.trunc((stickLength-1)/4));
        }else{
            console.log(Math.trunc(stickLength/4));
        }
    }else{
        console.log(0);
    }
}


Two chess pieces, a rook and a knight, stand on a standard chessboard 8 × 8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square.

The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide.

Print a single number which is the required number of ways.

'use strict'

let L = readline()
L = {x: ltd(L[0]), y: +L[1]}
let K = readline()
K = {x: ltd(K[0]), y: +K[1]}

let ps = 0
let d = []

for (let x = 1; x <= 8; x++) {
  for (let y = 1; y <= 8; y++) {
    if (!d[x]) d[x] = []
    d[x][y] = is(x, y) ? 1 : 0
    if (is(x, y)) {
      ps++
    }
  }
}
print(ps - 2)

function is (x, y) {
  if (x == K.x && y == K.y || x == L.x && y == L.y) return false
  if (x == L.x || y == L.y) return false
  if (x == K.x + 1 && y == K.y + 2
   || x == K.x + 2 && y == K.y - 1
   || x == K.x + 2 && y == K.y + 1
   || x == K.x + 1 && y == K.y - 2
   || x == K.x - 1 && y == K.y - 2
   || x == K.x - 2 && y == K.y - 1
   || x == K.x - 2 && y == K.y + 1
   || x == K.x - 1 && y == K.y + 2
  ) return false
  return true
}

function ltd (l) {
  switch (l) {
    case 'a': return 1
    case 'b': return 2
    case 'c': return 3
    case 'd': return 4
    case 'e': return 5
    case 'f': return 6
    case 'g': return 7
    case 'h': return 8
  }
}


There are $$$n$$$ students in a university. The number of students is even. The $$$i$$$-th student has programming skill equal to $$$a_i$$$. The coach wants to form $$$\frac{n}{2}$$$ teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).Students can solve problems to increase their skill. One solved problem increases the skill by one.The coach wants to know the minimum total number of problems students should solve to form exactly $$$\frac{n}{2}$$$ teams (i.e. each pair of students should form a team). Your task is to find this number.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of students. It is guaranteed that $$$n$$$ is even. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student.

Print one number — the minimum total number of problems students should solve to form exactly $$$\frac{n}{2}$$$ teams.

NoteIn the first example the optimal teams will be: $$$(3, 4)$$$, $$$(1, 6)$$$ and $$$(2, 5)$$$, where numbers in brackets are indices of students. Then, to form the first team the third student should solve $$$1$$$ problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve $$$4$$$ problems so the answer is $$$1 + 4 = 5$$$.In the second example the first student should solve $$$99$$$ problems to form a team with the second one.

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;
};

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;
    }
});

//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);
}

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)
})

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++;
});

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 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 n = +readline(), k = 0;
var arr = readline().split(' ').map(a => +a).sort((a,b) => a - b);
for(var i = 0; i < n - 1; i+=2) {
    k += arr[i + 1] - arr[i];
}
print(k);

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);

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);

//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))

//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))

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();

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

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 s = input.split(" ")
           s.sort()
           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 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);
    };
});

//////

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);


As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.

The first line contains two lowercase English letters — the password on the phone. The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows. The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.

Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).

NoteIn the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.In the third example the string "hahahaha" contains "ah" as a substring.

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let str = inputReader.readLine();
	let n = inputReader.readNumber();
	let arr = [];

	let bool = false;
	for (let i = 0; i < n; i++) {
		arr[i] = inputReader.readLine();
		if (arr[i] === str) {
			bool = true;
		}
	}

	if (n === 1) {
		let str1 = "" + arr[0] + arr[0];
		if (str[0] == str1[1] && str[1] == str1[2]) {
			bool = true;
		}
		//console.log(str1,str1[1],str[0]);
	} else if (!bool) {
		for (let i = 0; i < n; i++) {
			for (let j = 0; j < n; j++) {
				let res = arr[i] + arr[j];
				if (str[0] == res[1] && str[1] == res[2]) {
					bool = true;
					break;
				}
			}
			if (bool) break;
		}
	}
	if (bool) {
		console.log("YES");
	} else {
		console.log("NO");
	}

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readLine(){
		return _inputLines[_lineNumber++];
	}

	return {
		readNumber,
		readLine,
	}
}


The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to n in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house n, house 3 is opposite house n - 2, house 5 is opposite house n - 4 and so on.  Vasya needs to get to house number a as quickly as possible. He starts driving from the beginning of the street and drives his car to house a. To get from the beginning of the street to houses number 1 and n, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.Your task is: find the minimum time Vasya needs to reach house a.

The first line of the input contains two integers, n and a (1 ≤ a ≤ n ≤ 100 000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number n is even.

Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house a.

NoteIn the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.The second sample corresponds to picture with n = 8. House 5 is the one before last at Vasya's left.

		    var line = readline().split(' ');
			var n = line[0] ;
			var a = line[1] ;
			var result = 0 ;

			if (a%2 === 0) {
				result = -a/2+n/2+1 ;
			} else {
				result = a/2-0.5+1 ;
			}
			print(result) ;

var l = readline().split(' ');
var compute = function(n, a) {
    return (a % 2 === 0) ? (n - a) / 2 + 1 : (a + 1) / 2;
};
print(compute(+l[0],+l[1]));

var input = readline().split(" "),

    count = +input[0],
    target = +input[1],

    isEven = target % 2 == 0,

    time = isEven ? count / 2 - Math.floor(target / 2) + 1 : Math.floor(target / 2) + 1;

print(time);

var data = readline().split(" "),
n = data[0],
a = data[1];

var homes = {
	odd: [],
	even: [],
};

for(var i=0;i<n;i++){
	if( i%2!=0 ){
		homes.even.unshift(i+1);
	} else {
		homes.odd.push(i+1);
	}
}

if( a%2 == 0 ){
	for( var i=0; i<homes.even.length; i++ ){
		if( homes.even[i] == a ) print(i+1);
	}
} else {
	for( var i=0; i<homes.odd.length; i++ ){
		if( homes.odd[i] == a ) print(i+1);
	}
}

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

if (a % 2) {
	var house = a;
} else {
	var house = n - a;
}

var res = Math.floor(house/2) + 1;

print(res);

var readInt = () => parseInt(readline())
var readIntArray = () => readline().split(' ').map(item => parseInt(item))
function range(a, b) {
    var res = []
    for (var i = a; i <= b; i++) {
        res.push(i)
    }
    return res
}

var inputData = readIntArray()
var n = inputData[0]
var a = inputData[1]
if (a % 2 !== 0) {
    print(Math.floor(a / 2) + 1)
} else {
    print(Math.floor((n-a) / 2) + 1)
}

var input = readline().split(" "),

    count = +input[0],
    target = +input[1],

    isEven = target % 2 == 0,

    time = isEven ? count - Math.floor(target / 2) - 1 : Math.floor(target / 2) + 1;

print(time);

var data = readline().split(" "),
	n = data[0],
	a = data[1];

var homes = [];

for(var i=0;i<n;i++){
	homes.push(i+1);
}

if( a%2 == 0 ){
	homes = homes.filter(v=>(v%2==0));

	for( var i=0; i<homes.length; i++ ){
		if( homes[i] == a ) print(i+2);
	}
} else {
	homes = homes.filter(v=>(v%2!=0)).reverse();

	for( var i=0; i<homes.length; i++ ){
		if( homes[i] == a ) print(i+2);
	}
}


Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

The first line contains integer n (1 ≤ n ≤ 109).

In the first line print one integer k — number of different values of x satisfying the condition.  In next k lines print these values in ascending order.

NoteIn the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.In the second test case there are no such x.

function countSum(str) {

    var arr = str.split(''),
        sum = 0;

    for (var i = 0; i < arr.length; i++) {

        sum += parseInt(arr[i]);

    }

    return sum;

}

function classWatch() {

    var line = readline();
    var num = parseInt(line);
    var list = [];

    for (var i = num-(num.toString().length)*9; i < num; i++) {

        if (i + countSum(i.toString()) === num) {

            list.push(i);

        }

    }

    print(list.length);

    for (var j = 0; j < list.length; j++) {

        print(list[j]);

    }

}

classWatch();

var n=(readline());
var i,k=0;
var s=[],m=[];
s=n.split('');
n<18?i=n:i=9*s.length;
var p;
while(i>=0)
{
    p=n-i;
   var t=p;
   while(p)
{
    t+=(p%10);
    p=Math.floor(p/10);
}
if(t==n)
{
m.push(n-i);
k++;
}
i--;
}
print(k);
for(var e of m)
print(e);

function main() {
    var num = +readline();
    var Array = [];
    var min = num - num.toString().length * 9;
    min = min > 0 ? min : 0;
    for (var i = min; i < num; i++) {
        var sum = i;
        var iStr = i.toString();
        for (var j = 0; j < iStr.length; j++) {
            sum += +iStr[j];
        }
        if (sum === num) Array.push(i);
    }
    print(Array.length);
    for (var k = 0; k < Array.length; k++) {
        print(Array[k]);
    }
}

main();

var firstLine = readline();

var rezult = findMagicNumbers(+firstLine.split(' ')[0]);

print(rezult.length);
rezult.forEach(function(num) {
  print(num);
})

function findMagicNumbers(inputValue) {

  function findSumOfDigits(num) {
    var digits = String(num)
      .split('')
      .map(function(digit) {
        return Number(digit);
      });

    var sumOfDigits = digits.reduce(function(sum, digit) {
      return sum + digit;
    }, 0);

    return sumOfDigits;
  }

  var numbers = [];

  for (var i = 1; i < 82; i++) {
    var current = inputValue - i;

    if (current <= 0) {
      continue;
    }

    var sum = findSumOfDigits(current);

    if (sum + current === inputValue) {
      numbers.push(current);
    }
  }

  return numbers.reverse();
}

'use strict';
var n = parseInt(readline());
var res = new Array;
var nLength = parseInt(n.toString().length);
var x = n - 9*nLength;
x = x > 0 ? x : 0;
    for (var i = x; i < n; i++) {
            var sum = 0, t = i;
                while (t) {
                    sum += t % 10;
                    t = Math.floor(t / 10);
                }
                if (sum + i === n)
                res.push(i);
            }
    print(res.length);
    for (var i = 0; i < res.length; i++)
        print(res[i]);

function res(x){
    var i;
	var n = JSON.parse(x);
    var k = 0;
    var s = [];
    var m = [];
    s = n.toString().split('');
    n < 18 ? i = n : i = 9 * s.length;
    var p;
    while(i >= 0){
        var p = n - i;
        var t = p;
        while(p){
            t += (p % 10);
            p = Math.floor(p / 10);
        }
        if(t === n){
            m.push(n - i);
            k++;
        }
        i--;
    }
    print(k);
    for(var e of m)
    print(e);
}
res(readline());

var readline = readline();
//prompt("Enter Digit");
var n = +readline;
var resultToArray = [];
var j = 0;

if (n <= 101) {
  j = Math.floor(n / 1.7);
} else if (n <= 1001) {
  j = Math.floor(n / 1.4);
} else if (n <= 10001) {
  j = Math.floor(n / 1.3);
} else if (n <= 100001) {
  j = Math.floor(n / 1.2);
} else if (n <= 1000001) {
  j = Math.floor(n / 1.05);
} else if (n <= 10000001) {
  j = Math.floor(n / 1.025);
} else if (n <= 100000001) {
  j = Math.floor(n / 1.012);
} else if (n <= 1000000001) {
  j = Math.floor(n / 1.006);
}

for (var i = j; i < n; i++) {
  var tempVal = i,
    sumOfDigits = 0;
  while (tempVal) {
    sumOfDigits += tempVal % 10;
    tempVal = Math.floor(tempVal / 10);
  }
  var resultSum = i + sumOfDigits;
  if (resultSum === n) {
    resultToArray.push(i);
  }
}

print(resultToArray.length);
print(resultToArray.toString().replace(',', ' '));
    //console.log(resultToArray.length);
    //console.log(resultToArray.toString().replace(',', ' '));

var readline = readline();
//prompt("Enter Digit");
var n = +readline;
var resultToArray = [];
var j = 0;

if (n <= 101) {
  j = Math.floor(n / 1.7);
} else if (n <= 1001) {
  j = Math.floor(n / 1.4);
} else if (n <= 10001) {
  j = Math.floor(n / 1.3);
} else if (n <= 100001) {
  j = Math.floor(n / 1.2);
} else if (n <= 1000001) {
  j = Math.floor(n / 1.05);
} else if (n <= 10000001) {
  j = Math.floor(n / 1.025);
} else if (n <= 100000001) {
  j = Math.floor(n / 1.012);
} else if (n <= 1000000001) {
  j = Math.floor(n / 1.006);
}

for (var i = j; i < n; i++) {
  var tempVal = i,
    sumOfDigits = 0;
  while (tempVal) {
    sumOfDigits += tempVal % 10;
    tempVal = Math.floor(tempVal / 10);
  }
  var resultSum = i + sumOfDigits;
  if (resultSum === n) {
    resultToArray.push(i);
  }
}

print(resultToArray.length);
print(resultToArray.toString().replace(',', ' '));
    //console.log(resultToArrayay.length);
    //console.log(resultToArrayay.toString().replace(',', ' '));

var nStr = readline();
var n = +nStr;
var resultArr = [];
var j = 0;

if (n <= 101) {
  j = Math.floor(n / 1.7);
} else if (n <= 1001) {
  j = Math.floor(n / 1.4);
} else if (n <= 10001) {
  j = Math.floor(n / 1.3);
} else if (n <= 100001) {
  j = Math.floor(n / 1.2);
} else if (n <= 1000001) {
  j = Math.floor(n / 1.05);
} else if (n <= 10000001) {
  j = Math.floor(n / 1.025);
} else if (n <= 100000001) {
  j = Math.floor(n / 1.012);
} else if (n <= 1000000001) {
  j = Math.floor(n / 1.006);
}

for (var i = j; i < n; i++) {
  var tempI = i,
    sumOfDigits = 0;
  while (tempI) {
    sumOfDigits += tempI % 10;
    tempI = Math.floor(tempI / 10);
  }
  var resultSum = i + sumOfDigits;
  if (resultSum === n) {
    resultArr.push(i);
  }
}

print(resultArr.length);
print(resultArr.toString().replace(',', ' '));

var n = readline();
var len = n.toString().length;
function main(){
    var i = n;
    var numCounter = 0;
    var flag = n - len * 9;
    var numArr = [];
    for(i; i >= flag; i--){
        var subSum = 0;
        var numbers = i.toString().split('');
        numbers.forEach(element => {
            subSum += Number(element);
        });

        if(i+subSum == n){
            numCounter++
            numArr.unshift(i);
        }
    }
    print(numCounter);
    numArr.forEach(element => {
        print(element);
    });
}

main();

var number = parseInt(readline());
var res = new Array;

for (var i = number - 1; i > number - 9*number.toString().length && i > 0; i--) {
    var temp = i
    var sum = 0;
    while (temp) {
        sum += temp % 10;
        temp = Math.floor(temp / 10);
    }

    if (sum + i === number) res.unshift(i);
}

print(res.length);
for (var i = 0; i < res.length; i++ ) print(res[i]);

const
    num = readline()

var matches = 0,
    matchesValues = [];
    maxCharsSum = num.toString().length * 9,
    startValue = num - maxCharsSum < 0 ? 0 : num - maxCharsSum;
for (var i = startValue; i <= num; i++) {
    var tmpNum = i, sum = 0, tmp;

    while (tmpNum) {
        tmp = tmpNum % 10;
        tmpNum = (tmpNum - tmp) / 10;
        sum += tmp;
    }

    result = i + sum;
    if (result == num) {
        matches++;
        matchesValues.push(i);
    }
}

print(matches);
if (matches) {
    for (var j = 0; j < matchesValues.length; j++) {
        print(matchesValues[j]);
    }
}

function main() {
  var num = +readline();
  var numArray = [];
  var min = num - num.toString().length * 9;
  min = min > 0 ? min : 0;
  for (var i = min; i < num; i++) {
    var sum = i;
    var iStr = i.toString();
    for (var y = 0; y < iStr.length; y++) {
      sum += +iStr[y];
    }
    if (sum === num) numArray.push(i);
  }
  print(numArray.length);
  for (var j = 0; j < numArray.length; j++) {
    print(numArray[j]);
  }
}

main();

// http://codeforces.com/contest/875/submission/35182257

var n = parseInt(readline());
var minNumber = n - n.toString().length * 9;
var result = [];
for (var i = n; i > minNumber; i--) {
    if (i + getDigitsSum(i.toString()) === n) {
        result.unshift(i);
    }
}

print(result.length);
print(result.join(' '));

function getDigitsSum(num) {
    var result = 0;
    for (var i = 0; i < num.length; i++) {
        result += parseInt(num[i]);
    }
    return result;
}

var n=(readline());
var i,k=0;
var s=[],m=[];
if(n==1)
{
    m.push(n);
    k++;
}
s=n.split('');
s<9?i=n:i=9*s.length;
var p;
while(i>=0)
{
    p=n-i;
   var t=p;
   while(p)
{
    t+=(p%10);
    p=Math.floor(p/10);
}
if(t==n)
{
m.push(n-i);
k++;
}
i--;
}
print(k);
for(var e of m)
print(e);

function main() {
    var num = +readline();
    print('\n');
    var Array = [];
    var min = num - num.toString().length * 9;

    min = min > 0 ? min : 0;

    for (var i = min; i < num; i++) {
        var sum = i;
        var iStr = i.toString();
        for (var j = 0; j < iStr.length; j++) {
            sum += +iStr[j];
        }
        if (sum === num) Array.push(i);
    }

    print(Array.length);
    for (var k = 0; k < Array.length; k++) {
        print(Array[j]);
    }
}

main();

var n = parseInt(readline());

function getSum(number) {
    var sDigits = String(number).split('');
    var digits = sDigits.map(function(item) {
        return parseInt(item);
    })

    var result = digits.reduce(function(sum, current) {
        return sum + current;
    }, 0);

    return result;
}

function getRes() {
    var count = 0;
    for(var i = 10; i <=100; i++) {
        if((getSum(i) + i) == n) {
            count++;
            print(count);
            print(i);
        }

        else if(i==100 && count == 0) {
            print(0);
        }
    }
}

getRes();

var n = parseInt(readline());
print('\n');

function getSum(number) {
    var sDigits = String(number).split('');
    var digits = sDigits.map(function(item) {
        return parseInt(item);
    })

    var result = digits.reduce(function(sum, current) {
        return sum + current;
    }, 0);

    return result;
}

function getRes() {
    var count = 0;
    for(var i = 10; i <=100; i++) {
        if((getSum(i) + i) == n) {
            count++;
            print(count);
            print(i);
        }

        else if(i==100 && count == 0) {
            print(0);
        }
    }
}

getRes();

var n = parseInt(readline());
print('\n');

function getSum(number) {
    var sDigits = String(number).split('');
    var digits = sDigits.map(function(item) {
        return parseInt(item);
    })

    var result = digits.reduce(function(sum, current) {
        return sum + current;
    }, 0);

    return result;
}

function getRes() {
    var count = 0;
    for(var i = 0; i <=100; i++) {
        if((getSum(i) + i) == n) {
            count++;
            print(count);
            print(i);
        }

        else if(i==100 && count == 0) {
            print(0);
        }
    }
}

getRes();

function main() {
    var num = parseInt(readline());
    print('\n');
    var Array = [];
    var min = num - num.toString().length * 9;

    min = min > 0 ? min : 0;

    for (var i = min; i < num; i++) {
        var sum = i;
        var iStr = i.toString();
        for (var j = 0; j < iStr.length; j++) {
            sum += +iStr[j];
        }
        if (sum === num) Array.push(i);
    }

    print(Array.length);
    for (var k = 0; k < Array.length; k++) {
        print(Array[j]);
    }
}

main();

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];

print(getRezult(numRez));
print(0);

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var firstLine = readline();

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];
const rezult = getRezult(numRez)

print(rezult.length);
print(rezult);

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var firstLine = readline();

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];
var rezult = getRezult(numRez)

print(rezult.length >= 0 ? rezult.length : '');
print(rezult);

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  return getRezult(--input);

  return res;
}

var firstLine = readline();

var rezult = findMagicNumbers(+firstLine.split(' ')[0]);

print(rezult.length);
print(rezult.join(' '));

function findMagicNumbers(inputValue) {
  var numbers = [];

  for (var i = 1; i < 82; i++) {
    var current = inputValue - i;
    var sum = ('' + current).split('').reduce((sumTemp, num) => sumTemp + num, 0);

    if (sum + current === inputValue) {
      number.push(sum);
    }
  }

  return numbers;
}

var firstLine = readline();

var rezult = findMagicNumbers(+firstLine.split(' ')[0]);

print(rezult.length);
print(rezult.join(' '));

function findMagicNumbers(inputValue) {

  function findSumOfDigits(num) {
    var digits = String(num)
      .split('')
      .map(function(digit) {
        return Number(digit);
      });

    var sumOfDigits = digits.reduce(function(sum, digit) {
      return sum + digit;
    }, 0);

    return sumOfDigits;
  }

  var numbers = [];

  for (var i = 1; i < 82; i++) {
    var current = inputValue - i;

    if (current <= 0) {
      continue;
    }

    var sum = findSumOfDigits(current);

    if (sum + current === inputValue) {
      numbers.push(current);
    }
  }

  return numbers;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];

print(res.legth, getRezult(numRez));

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.round(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;
  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForFirst);

  return pathOfFirst < pathOfSecond ? pathOfFirst : pathOfSecond;
}

var firstLine = readline();

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];

print(getRezult(numRez));
print(0);

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var firstLine = readline();

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];
var rezult = getRezult(numRez)

print(rezult.length || '');
print(rezult);

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var firstLine = readline();

var rezult = findMagicNumbers(+firstLine.split(' ')[0]);

print(rezult.length);
print(rezult.join(' '));

function findMagicNumbers(inputValue) {
  var numbers = [];

  for (var i = 1; i < 82; i++) {
    var current = inputValue - i;
    var sum = ('' + current).split('').reduce((sumTemp, num) => sumTemp + num, 0);

    if (sum === current) {
      number.push(sum);
    }
  }

  return numbers;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];

print(res.length, getRezult(numRez));

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var inside = readline();

print('\n');
var num = +inside.split(' ')[0]

print(getRezult(num))
var count = 0;
function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  var res = [];
  parse.push(+input);

  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum === num) {
    res.push(input);
  } else {
    count++;

    if (count === num) {
      return 0;
    }
    getRezult(--input);
  }

  return res;
}

var firstLine = readline();

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];
var rezult = getRezult(numRez)

print(rezult.length);
print(rezult);

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];

print(getRezult(numRez));

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

var firstLine = readline();

var rezult = findMagicNumbers(+firstLine.split(' ')[0]);

print(rezult.length);
rezult.forEach(function(num) {
  print(num);
})

function findMagicNumbers(inputValue) {

  function findSumOfDigits(num) {
    var digits = String(num)
      .split('')
      .map(function(digit) {
        return Number(digit);
      });

    var sumOfDigits = digits.reduce(function(sum, digit) {
      return sum + digit;
    }, 0);

    return sumOfDigits;
  }

  var numbers = [];

  for (var i = 1; i < 82; i++) {
    var current = inputValue - i;

    if (current <= 0) {
      continue;
    }

    var sum = findSumOfDigits(current);

    if (sum + current === inputValue) {
      numbers.push(current);
    }
  }

  return numbers;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

print(tort(firstLine.split(' ')[0], firstLine.split(' ')[1], firstLine.split(' ')[2]));

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      var curr = Math.min(Math.floor(x / i), Math.floor(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

var count = 0;
var numRez = firstLine.split(' ')[0];
var res = [];

print(0 ,getRezult(numRez));

function getRezult (num) {
  var input = `${num}`;
  var parse = [];
  var sum = 0;
  parse.push(+input);
  debugger;
  for (var i =0; i < input.length; i++) {
    parse.push(+input[i]);
  }

  for (var j =0; j < parse.length; j++) {
     sum += parse[j];
  }

  if(sum == numRez) {
    res.push(input);
  } else {
    count++;
  }

  if (count == numRez) {
    return 0;
  }
  getRezult(--input);

  return res;
}

'use strict';
var n = parseInt(readline());
var res = new Array;
var nLength = n.toString().length;
        for (var i = n - 9*nLength; i <(n - 1) && i > 0; i++) {
            var sum = 0, t = i;
                while (t) {
                    sum += t % 10;
                    t = Math.floor(t / 10);
                }
                if (sum + i === n)
                res.push(i);
            }
    print(res.length);
    for (var i = 0; i < res.length; i++)
        print(res[i]);

'use strict';
var n = parseInt(readline());
var res = new Array;
var nLength = n.toString().length;
if (n === 1) {
    res.length = 1;
    print(res.length);
    res[0] = 1;
    print(res[0]);
}
else
    if (n >  1) {
        for (var i = n - 9*nLength; i <n - 1; i++) {
            var sum = 0, t = i;
                while (t) {
                    sum += t % 10;
                    t = Math.floor(t / 10);
                }
                if (sum + i === n)
                res.push(i);
            }
    print(res.length);
    for (var i = 0; i < res.length; i++)
        print(res[i]);
}

function tes(n){
    var i;
    var k = 0;
    var s = [];
    var m = [];
    s = n.toString().split('');
    n < 18 ? i = n : i = 9 * s.length;
    var p;
    while(i >= 0){
        var p = n - i;
        var t = p;
        while(p){
            t += (p % 10);
            p = Math.floor(p / 10);
        }
        if(t === n){
            m.push(n - i);
            k++;
        }
        i--;
    }
    print(k);
    for(var e of m)
    print(e);
}
tes(readline());

var firstEnteredDigit = readline();
//prompt("Enter digit");
var n =  firstEnteredDigit;
var resultArray = [];
var j = 0;

if (n <= 101) {
  j = Math.floor(n / 1.7);
} else if (n <= 1001) {
  j = Math.floor(n / 1.4);
} else if (n <= 10001) {
  j = Math.floor(n / 1.3);
} else if (n <= 100001) {
  j = Math.floor(n / 1.2);
} else if (n <= 1000001) {
  j = Math.floor(n / 1.05);
} else if (n <= 10000001) {
  j = Math.floor(n / 1.025);
} else if (n <= 100000001) {
  j = Math.floor(n / 1.012);
} else if (n <= 1000000001) {
  j = Math.floor(n / 1.006);
}

for (var i = j; i < n; i++) {
  var tempVal = i,
    sumOfDigits = 0;
  while (tempVal) {
    sumOfDigits += tempVal % 10;
    tempVal = Math.floor(tempVal / 10);
  }
  var resultSum = i + sumOfDigits;
  if (resultSum === n) {
    resultArray.push(i);
  }
}

print(resultArray.length);
print(resultArray.toString().replace(',', ' '));
    //console.log(resultArray.length);
    //console.log(resultArray.toString().replace(',', ' '));

var nStr = readline()
var n = +nStr;
var resultArr = [];

for (var i = Math.floor(n / 2); i < n; i++) {
  var sumOfDigits = 0;
  while (tempI) {
	var tempI = i
    sumOfDigits += tempI % 10;
    tempI = Math.floor(tempI / 10);
}
  var resultSum = i + sumOfDigits;
  if (resultSum === n) {
    resultArr.push(i);
  }
}

print(resultArr.length);
print(resultArr.toString().replace(',', ' '));

var nStr = readline();
var n = +nStr;
var resultArr = [];
var j = 0;

if (n <= 101) {
  j = Math.floor(n / 1.5);
} else if (n <= 1001) {
  j = Math.floor(n / 1.4);
} else if (n <= 10001) {
  j = Math.floor(n / 1.3);
} else if (n <= 100001) {
  j = Math.floor(n / 1.2);
} else if (n <= 1000001) {
  j = Math.floor(n / 1.05);
} else if (n <= 10000001) {
  j = Math.floor(n / 1.025);
} else if (n <= 100000001) {
  j = Math.floor(n / 1.012);
} else if (n <= 1000000001) {
  j = Math.floor(n / 1.006);
}

for (var i = j; i < n; i++) {
  var tempI = i,
    sumOfDigits = 0;
  while (tempI) {
    sumOfDigits += tempI % 10;
    tempI = Math.floor(tempI / 10);
  }
  var resultSum = i + sumOfDigits;
  if (resultSum === n) {
    resultArr.push(i);
  }
}

print(resultArr.length);
print(resultArr.toString().replace(',', ' '));

var nStr = readline();
var n = +nStr;
var resultArr = [];
var j = 0;

if(n <= 101) j = Math.floor(n / 1.5);
if(n <= 1001) j = Math.floor(n / 1.4);
if(n <= 10001) j = Math.floor(n / 1.3);
if(n <= 100001) j = Math.floor(n / 1.2);
if(n > 100001) j = Math.floor(n / 1.1);

for (var i = j; i < n; i++) {
  var tempI = i, sumOfDigits = 0;
  while (tempI) {
    sumOfDigits += tempI % 10;
    tempI = Math.floor(tempI / 10);
  }
  var resultSum = i + sumOfDigits;
  if (resultSum === n) {
    resultArr.push(i);
  }
}

print(resultArr.length);
print(resultArr.toString().replace(',', ' '));

var n = readline();
var len = n.toString().length;
function main(){
    var i = n;
    var flag = n - len * 9;
    for(i; i >= flag; i--){
        var subSum = 0;
        var numbers = i.toString().split('');
        numbers.forEach(element => {
            subSum += Number(element);
        });

        if(i+subSum == n){
            print(i+subSum);
        }
    }
}

main();

var n = readline();
var len = n.toString().length;
function main(){
    var i = n;
    var numCounter = 0;
    var flag = n - len * 9;
    var numArr = [];
    for(i; i >= flag; i--){
        var subSum = 0;
        var numbers = i.toString().split('');
        numbers.forEach(element => {
            subSum += Number(element);
        });

        if(i+subSum == n){
            numCounter++
            numArr.unshift(subSum);
        }
    }
    print(numCounter);
    numArr.forEach(element => {
        print(element);
    });
}

main();

var number = parseInt(readline());
var res = new Array;

for (var i = number - 1; i > number - 9*number.toString().length && i > 0; i--) {
    var temp = i
    var sum = 0;
    while (temp) {
        sum += temp % 10;
        temp = Math.floor(temp / 10);
    }

    if (sum + i === number) res.push(i);
}

print(res.length);
print(res);

var number = parseInt(readline());
var res = new Array;

for (var i = number - 1; i > number - 9*number.toString().length && i > 0; i--) {
    var temp = i
    var sum = 0;
    while (temp) {
        sum += temp % 10;
        temp = Math.floor(temp / 10);
    }

    if (sum + i === number) res.push(i);
}

print(res.length);
for (var i = 0; i < res.length; i++ ) print(res[i]);

const
    controlNum = readline()

var matches = 0,
    matchesValues = [],
    num = controlNum;
while (num) {
   var tmpNum = num, sum = 0, tmp;

    while (tmpNum) {
        tmp = tmpNum % 10;
        tmpNum = (tmpNum - tmp) / 10;
        sum += tmp;
    }

    result = num + sum;
    if (result == controlNum) {
        matches++;
        matchesValues.push(num);
        break;
    }
    num--
}

print(matches);
if (matches) {
    for (var j = 0; j < matchesValues.length; j++) {
        print(matchesValues[j]);
    }
}


Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

Print the maximum possible height of the pyramid in the single line.

//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 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 sum = 0;
  for(var i = 1; i < 100000; i++){
    sum += i;
    if(N >= sum){
      N -= sum;
    }else{
      myout(i - 1);
      return;
    }
  }
}

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

rl.on('line', (d) => {
  const n = +d;
  let sum = 0;
  let ans = 0;
  let c = 1;

  while (sum < n) {
    let s = 0;
    for (let j = 1; j <= c; j++) {
      s += j;
    }

    sum += s;
    c++;

    if (sum > n) {
      break;
    }
    else {
      ans++;
    }
  }

  console.log(ans);

});

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

rl.on('line', (d) => {
  let n = +d;

  let curr = 1;
  let x = 1;

  while (n >= curr) {
    n -= curr;
    x++;
    curr += x;
  }

  console.log(x - 1);

  // let sum = 0;
  // let ans = 0;
  // let c = 1;

  // while (sum < n) {
  //   let s = 0;
  //   for (let j = 1; j <= c; j++) {
  //     s += j;
  //   }

  //   sum += s;
  //   c++;

  //   if (sum > n) {
  //     break;
  //   }
  //   else {
  //     ans++;
  //   }
  // }

  // console.log(ans);

});

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [n] = input[0].split(' ').map(x => parseInt(x));
  let prev = 0;

  if (n === 1) { console.log(1); return; }

  for (let i = 1; i < 1000; i += 1) {
    let sum = (i*(i+1))/2;
    prev += sum;

    if (prev > n) {
      console.log(i-1); return;
    }
  }
});

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

/**
 *
 * @param {*} str
 * @param {*} seperator
 */
function splitter(str, seperator = '') {
    return str.trim().split(seperator);
}

/**
 *
 * @param {*} arr
 */
function strToNumArr(arr = []) {
    return arr.map(num => Number(num));
}

/**
 *
 * @param {*} num1
 * @param {*} num2
 */
function matrixArray(num1, num2) {
    return Array(num1).fill(Array(num2));
}

let log = function () {
    return Function.prototype.bind.call(console.log, console, '');
}();

function removeEmptyItem(arr, index) {
    return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));
}

function range(min, max) {

    let arr = [];
    for (let index = min; index < max; index++) {
        arr.push(index);

    }
    return arr;
}

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let n = +str.trim();
    let count = 0;
    let inc = 0;
    while (count <= n) {
        inc++;
        count += (inc * (inc + 1)) / 2;
    }
    return (inc - 1).toString();
}

var n = parseInt(readline());
var it = 0;
var level = 0;
for(;;){
	if ((n - (it + level + 1)) > -1){
		level++;
		it += level;
		n-=it;
	}else{break;}
}
print(level);

///////////////////////////////////////////////////////////////////////////////
function readNumber () { return Number(readline()); }
function readNumbersArray () { return readline().split(' ').map(Number); }
function algebraicSum (startValue, finishValue, size) { return (startValue + finishValue) * size / 2; }
///////////////////////////////////////////////////////////////////////////////

var n = readNumber();
var level = 0;
var levelLength = 1;

while (n > 0) {
	level++;
	levelLength = algebraicSum(1, level, level);
	n -= levelLength;
}

print(level - (n !== 0));

var n =Number(readline());
var level = 0;
var levelUsedCount = 0;
var usedCount = 0;
do{
    level++;
    levelUsedCount+=level;
    usedCount+=levelUsedCount;
} while(usedCount+levelUsedCount+level < n)
print(level);

var n =Number(readline());
var level = 0;
var levelUsedCount = 0;
var usedCount = 0;
do{
    level++;
    levelUsedCount+=level;
    usedCount+=levelUsedCount;
} while(usedCount+levelUsedCount+level+1 <= n)
print(level);

var n = readline();
var height = 0;
var requiredCubes = 0;
var tmpHeight = 1;

while(n >= 0) {
	requiredCubes += tmpHeight;
	n -= requiredCubes;

	if(n < 0)
		break;

	height++;
	tmpHeight++;
}

print(height);

var n = readline();
var height = 0;
var requiredCubes = 0;
var tmpHeight = 0;

while(n >= 0) {
	tmpHeight++;
	requiredCubes += tmpHeight;
	n -= requiredCubes;

	if(n < 0)
		break;

	height++;
}

print(height);

var n = parseInt(readline());
var height = 0;
var requiredCubes = 0;
var tmpHeight = 0;

while(n >= 0) {
	tmpHeight++;
	requiredCubes += tmpHeight;
	n -= requiredCubes;

	if(n < 0)
		break;

	height++;
}

print(height);

var n = parseInt(readline());
var height = 0;
var requiredCubes = 0;
var tmpHeight = 0;

while(n >= requiredCubes) {
	tmpHeight++;
	requiredCubes += tmpHeight;

	if(n >= requiredCubes) {
		height++;
		n -= requiredCubes;
	}
}

print(height);

var n = readline();
height = 0;
sum = 0;
i = 1;
while(n > 0){
    sum += i;
    n -= sum;
    if(n < 0){
        break;
    }
    height++;
    i++;
}
print(height);

var n = parseInt(readline());
var height = 0;
var requiredCubes = 0;
var tmpHeight = 1;

while(n >= 0) {
	requiredCubes += tmpHeight;
	n -= requiredCubes;

	if(n < 0)
		break;

	height++;
	tmpHeight++;
}

print(height);

var number=readline();
var num=0;
var collect=0
var i=0;
// for(i=0;i<number;i++){
    if(number>1){
        while(collect<=number){
            i++
            // console.log("i  "+i);
        num=(i*(i+1))/2;
            // console.log(num);
        collect=collect+num;
        }
        // console.log(collect);
    // }
    // console.log(i-1);
    print(i-1);
    }
    else{
        // console.log(1);
        print(1);
    }

var n = readline();
var res = 0;
var coub = 0;
	for (var i=1; i<+n; i++){

		res += i;
		coub += res;
		if (coub+res+i>=n)
		break;
	}
print(i);

var n = parseInt(readline());
var spent = 0, i = 0, stack = 0;
while(spent <= n){
  i+=1;
  stack += i;
  spent += stack;
}
print(i - 1);

var ans = 0;
var n = parseInt(readline());
var tmp = 0;
var sum = 0;
for (var i=1;sum<=n;i++){
	tmp = tmp + i;
	sum = sum + tmp;
	ans ++;
}
print(ans-1);

function main(){

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

    var row_count = 0;
    var total_cubes = 0;
    var previous_total = 0;

    for(i=1;i<n+1;i++){
	row_count+=i;
	total_cubes += row_count;

	if(n===total_cubes){
	    print(i);
	    return;
	}

	if(n<total_cubes){
	    print(i-1);
	return;
	}
    }

}

main();

function nthSum(index) {
  return (index * (index + 1)) / 2;
}

function main() {
  var cubes = parseInt(readline(), 10);
  var rows = 0;
  var rowIndex = 1;

  while (cubes >= nthSum(rowIndex)) {
    cubes -= nthSum(rowIndex);
    rows++;
    rowIndex++;
  }

  print(rows);
}

main();

var n = parseInt(readline());

var x=0;
var y=0;
var i=0;
while(n>=y){
    i=i+1;
    x+=i;
    y+=x;
}
print(i-1);

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

rl.on('line', (d) => {
  const n = +d;
  let sum = 0;
  let ans = 0;

  if (n <= 2) {
    console.log(1);
    return;
  }

  for(let i = 1; i <= n; i++) {
    sum += sum + i;

    if (sum >= n) {
      ans = i;
      break;
    }
  }

  console.log(ans);

});

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

rl.on('line', (d) => {
  const n = +d;
  let sum = 0;
  let ans = 0;

  for(let i = 1; i <= n; i++) {
    sum += sum + i;

    if (sum >= n) {
      ans = i;
      break;
    }
  }

  console.log(ans);

});

var n = parseInt(readline());
var it = 0;
var level = 0;
while(n >= it){
	level++;
	it += level;
    n-=it;
	print(it);
}
print(level);

var n = parseInt(readline());
var it = 0;
var level = 0;
while(n >= it){
	level++;
	it += level;
    n-=it;
}
print(level);

var n =Number(readline());
var level = 0;
var levelUsedCount = 0;
var usedCount = 0;
do{
    level++;
    levelUsedCount+=level;
    usedCount+=levelUsedCount;
} while(usedCount+levelUsedCount+level+1 < n)
print(level);

var n = readline();
var res = 0;
var coub = 0;
	for (var i=1; i<+n; i++){

		res += i;
		coub += res;
		if (coub+res>=+n)
		break;
	}
print(i);

var n = parseInt(readline());
var i;
var sum = 1;
for (i=0;n>0;i++){
	n = n - sum;
	sum = sum + 2;
}
print(i);

var n = parseInt(readline());
var i;
var sum = 1;
for (i=1;n>0;i++){
	n = n - sum;
	sum = sum + 2;
}
print(i);

var n = parseInt(readline());
var ans = 0;
var sum = 0;
for (var i=1;i<=n;i++){
	sum = sum + i;
	ans = ans + sum;
}
print(ans);

var n = parseInt(readline());
var i;
var sum = 1;
for (i=0;n-sum>=0;i++){
	n = n - sum;
	sum = sum + i + 1;
}
print(i);

var n = parseInt(readline());
var ans = 0;
var sum = 1;
for (var i=1;i<=n;i++){
	ans = ans + sum;
	sum = sum + 2;
}
print(ans);

var ans = 0;
var n = parseInt(readline());
var tmp = 0;
var sum = 0;
for (var i=1;sum<=n;i++){
	tmp = tmp + i;
	sum = sum + tmp;
	ans ++;
}
print(ans);

"use strict";

var n = +readline();

var result = 0;
for (let i = 1, s = 0; s < n; ++i, s += i) {
  n -= s;
  ++result;
}

write(result);
"use strict";

var n = +readline();

var result = 0;
for (let i = 1, s = 1; s <= n; ++i, s += i) {
  n -= s;
  ++result;
}

write(result);

var n = readline();
var result;
var x=0;
for(var i=1;i<n;i++){
    x+=i;
    if (n-x<0){
        print(i-1);
        break;
    }
    n=n-x;
}