Salem gave you $$$n$$$ sticks with integer positive lengths $$$a_1, a_2, \ldots, a_n$$$.For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $$$a$$$ to $$$b$$$ is $$$|a - b|$$$, where $$$|x|$$$ means the absolute value of $$$x$$$.A stick length $$$a_i$$$ is called almost good for some integer $$$t$$$ if $$$|a_i - t| \le 1$$$.Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer $$$t$$$ and the total cost of changing is minimum possible. The value of $$$t$$$ is not fixed in advance and you can choose it as any positive integer. As an answer, print the value of $$$t$$$ and the minimum cost. If there are multiple optimal choices for $$$t$$$, print any of them.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of sticks. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 100$$$) — the lengths of the sticks.

Print the value of $$$t$$$ and the minimum possible cost. If there are multiple optimal choices for $$$t$$$, print any of them.

NoteIn the first example, we can change $$$1$$$ into $$$2$$$ and $$$10$$$ into $$$4$$$ with cost $$$|1 - 2| + |10 - 4| = 1 + 6 = 7$$$ and the resulting lengths $$$[2, 4, 4]$$$ are almost good for $$$t = 3$$$.In the second example, the sticks lengths are already almost good for $$$t = 2$$$, so we don't have to do anything.

function ansa(n,arr){

  var ans = []
  ans[0] = Infinity
  for(var i = 1 ; i < 101 ; i++){

    ans[i] = 0

    for(var j = 0 ; j < n ; j++){

      ans[i] += Math.abs(arr[j] - i);
      if(Math.abs(arr[j] - i) !== 0) ans[i]--

    }
  }
  var min =  Math.min(...ans);
  print(ans.indexOf(min) + " " + min)
}

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

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

let l = 0;
rl.on('line', (input) => {
    if (l === 0) {} else {
        rl.close();
        let hm = {}
        let arr = input.split(" ").map(x=>parseInt(x))
        let mn1 = 9999999
        let nr = 0
        for(let i=1;i<=100;i++){
            let s=0
                for(let j=0;j<arr.length;j++){
                   s+=Math.min(Math.min(Math.abs(i-arr[j]), Math.abs(i-arr[j]-1)),Math.abs(i-arr[j]+1))
                }
                if(s<mn1){
                    mn1=s;
                    nr=i
                }
        }
        console.log(nr,mn1)
        return
    }
    l++
})

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let [min, t] = [Infinity, 1];

  for (let i = 1; i <= 1000; i++) {
    const target = i;
    let count = 0;
    for (let j = 0; j < len; j++) {
      const current = arr[j];
      const diff = Math.abs(target - current);
      if (diff > 1) {
        count += diff - 1;
      }
    }
    if (count < min) {
      min = count;
      t = target;
    }
  }

  console.log(`${t} ${min}`);
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let [min, t] = [Infinity, 1];

  for (let i = 0; i < len; i++) {
    const target = arr[i];
    let count = 0;
    for (let j = 0; j < len; j++) {
      const current = arr[j];
      const diff = Math.abs(target - current);
      if (diff > 1) {
        count += diff - 1;
      }
    }
    if (count < min) {
      min = count;
      t = target;
    }
  }

  console.log(`${t} ${min}`);
}


Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates  that is defined as the maximal number of non-overlapping substrings equal to p that can be found in s'. He wants to make this number as big as possible.More formally, let's define  as maximum value of  over all s' that can be obtained by removing exactly x characters from s. Dreamoon wants to know  for all x from 0 to |s| where |s| denotes the length of string s.

The first line of the input contains the string s (1 ≤ |s| ≤ 2 000). The second line of the input contains the string p (1 ≤ |p| ≤ 500). Both strings will only consist of lower case English letters.

Print |s| + 1 space-separated integers in a single line representing the  for all x from 0 to |s|.

NoteFor the first sample, the corresponding optimal values of s' after removal 0 through |s| = 5 characters from s are {"aaaaa", "aaaa", "aaa", "aa", "a", ""}. For the second sample, possible corresponding optimal values of s' are {"axbaxxb", "abaxxb", "axbab", "abab", "aba", "ab", "a", ""}.


Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree T:  Set pointer to the root of a tree.  Return success if the value in the current vertex is equal to the number you are looking for  Go to the left child of the vertex if the value in the current vertex is greater than the number you are looking for  Go to the right child of the vertex if the value in the current vertex is less than the number you are looking for  Return fail if you try to go to the vertex that doesn't exist Here is the pseudo-code of the described algorithm: bool find(TreeNode t, int x) {    if (t == null)        return false;    if (t.value == x)        return true;    if (x < t.value)        return find(t.left, x);    else        return find(t.right, x);}find(root, x);The described algorithm works correctly if the tree is binary search tree (i.e. for each node the values of left subtree are less than the value in the node, the values of right subtree are greater than the value in the node). But it can return invalid result if tree is not a binary search tree.Since the given tree is not necessarily a binary search tree, not all numbers can be found this way. Your task is to calculate, how many times the search will fail being running on every value from the tree.If the tree has multiple vertices with the same values on them then you should run algorithm on every one of them separately.

First line contains integer number n (1 ≤ n ≤ 105) — number of vertices in the tree. Each of the next n lines contains 3 numbers v, l, r (0 ≤ v ≤ 109) — value on current vertex, index of the left child of the vertex and index of the right child of the vertex, respectively. If some child doesn't exist then number  - 1 is set instead. Note that different vertices of the tree may contain the same values.

Print number of times when search algorithm will fail.

NoteIn the example the root of the tree in vertex 2. Search of numbers 5 and 15 will return fail because on the first step algorithm will choose the subtree which doesn't contain numbers you are looking for.

  var n = parseInt(readline());
  var v = new Array(n + 1);
  var l = new Array(n + 1);
  var r = new Array(n + 1);
  var p = new Array(n + 1);
  for(var i = 1; i <= n; i += 1) {
    var tmp = readline().split(' ').map(x => parseInt(x));
    v[i] = tmp[0];
    l[i] = tmp[1];
    if(l[i] !== -1) {
      p[l[i]] = i;
    }
    r[i] = tmp[2];
    if(r[i] !== -1) {
      p[r[i]] = i;
    }
  }
  var root = 1;
  while(p[root] !== undefined) {
    root = p[root];
  }
  var res = 0;
  var ret = [];
  var stack = [
    {
      node: root,
      lb: -1,
      ub: 1000000009
    }
  ];
  while(stack.length > 0) {
    var tmp = stack.pop();
    var node = tmp.node;
    var lb = tmp.lb;
    var ub = tmp.ub;
    if(lb <= v[node] && v[node] <= ub) {
      ret[v[node]] = 1;
    }
    if(l[node] !== -1) {
      stack.push({
        node: l[node],
        lb: lb,
        ub: Math.min(ub, v[node] - 1)
      });
    }
    if(r[node] !== -1) {
      stack.push({
        node: r[node],
        lb: Math.max(lb, v[node] + 1),
        ub: ub
      });
    }
  }
  for(var i = 1; i <= n; i += 1) {
    if(ret[v[i]] === undefined) {
      res += 1;
    }
  }
  print(res);

  var n = parseInt(readline());
  var v = [];
  var l = [];
  var r = [];
  var p = [];
  for(var i = 1; i <= n; i += 1) {
    var tmp = readline().split(' ').map(x => parseInt(x));
    v[i] = tmp[0];
    l[i] = tmp[1];
    if(l[i] !== -1) {
      p[l[i]] = i;
    }
    r[i] = tmp[2];
    if(r[i] !== -1) {
      p[r[i]] = i;
    }
  }
  var root = 1;
  while(p[root] !== undefined) {
    root = p[root];
  }
  var res = 0;
  for(var ii = 1; ii <= n; ii += 1) {
    var i = ii;
    var flag = true;
    var min = v[i];
    var max = v[i];
    var path = [];
    while((flag || true) && p[i] !== undefined) {
      path.push(i);
      if(i === l[p[i]]) {
        if(min <= v[p[i]]) {
          min = Math.max(v[p[i]], min);
          max = Math.min(v[i], max);
        } else {
          flag = false;
        }
      } else {
        if(max >= v[p[i]]) {
          min = Math.max(v[i], min);
          max = Math.min(v[p[i]], max);
        } else {
          flag = false;
        }
      }
      i = p[i];
    }
    res += flag ? 0 : 1;
    // console.log(path.map(i => `${i}: ${v[i]}`).join('--'), flag);
  }
  print(res);

 var n = parseInt(readline());
  var v = [];
  var l = [];
  var r = [];
  var p = [];
  for(var i = 1; i <= n; i += 1) {
    var tmp = readline().split(' ').map(x => parseInt(x));
    v[i] = tmp[0];
    l[i] = tmp[1];
    if(l[i] !== -1) {
      p[l[i]] = i;
    }
    r[i] = tmp[2];
    if(r[i] !== -1) {
      p[r[i]] = i;
    }
  }
  var root = 1;
  while(p[root] !== undefined) {
    root = p[root];
  }
  var res = 0;
  for(var ii = 1; ii <= n; ii += 1) {
    var i = ii;
    if(l[i] === -1 && r[i] === -1) {
      var flag = true;
      var min = v[i];
      var max = v[i];
      while(flag && p[i] !== undefined) {
        if(i === l[p[i]]) {
          if(min <= v[p[i]]) {
            i = p[i];
            min = Math.max(v[p[i]], min);
            max = Math.min(v[i], max);
          } else {
            flag = false;
          }
        } else {
          if(max >= v[p[i]]) {
            i = p[i];
            min = Math.max(v[i], min);
            max = Math.min(v[p[i]], max);
          } else {
            flag = false;
          }
        }
      }
      res += flag ? 0 : 1;
    }
  }
  print(res);

  var n = parseInt(readline());
  var v = [];
  var l = [];
  var r = [];
  var p = [];
  for(var i = 1; i <= n; i += 1) {
    var tmp = readline().split(' ').map(x => parseInt(x));
    v[i] = tmp[0];
    l[i] = tmp[1];
    if(l[i] !== -1) {
      p[l[i]] = i;
    }
    r[i] = tmp[2];
    if(r[i] !== -1) {
      p[r[i]] = i;
    }
  }
  var root = 1;
  while(p[root] !== undefined) {
    root = p[root];
  }
  var res = 0;
  for(var i = 1; i <= n; i += 1) {
    var node = root;
    while(true) {
      if(node > n || node <= 0) {
        res += 1;
        break;
      }
      if(v[node] === v[i]) {
        if(node !== i) {
          res += 1;
        }
        break;
      }
      if(v[i] < v[node]) {
        node = l[node];
      } else {
        node = r[node];
      }
    }
  }
  print(res);


You are given a binary string (i. e. a string consisting of characters 0 and/or 1) $$$s$$$ of length $$$n$$$. You can perform the following operation with the string $$$s$$$ at most once: choose a substring (a contiguous subsequence) of $$$s$$$ having exactly $$$k$$$ characters 1 in it, and shuffle it (reorder the characters in the substring as you wish).Calculate the number of different strings which can be obtained from $$$s$$$ by performing this operation at most once.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 5000$$$; $$$0 \le k \le n$$$). The second line contains the string $$$s$$$ of length $$$n$$$, consisting of characters 0 and/or 1.

Print one integer — the number of different strings which can be obtained from $$$s$$$ by performing the described operation at most once. Since the answer can be large, output it modulo $$$998244353$$$.

NoteSome strings you can obtain in the first example:  to obtain 0110110, you can take the substring from the $$$1$$$-st character to the $$$4$$$-th character, which is 1100, and reorder its characters to get 0110;  to obtain 1111000, you can take the substring from the $$$3$$$-rd character to the $$$7$$$-th character, which is 00110, and reorder its characters to get 11000;  to obtain 1100101, you can take the substring from the $$$5$$$-th character to the $$$7$$$-th character, which is 110, and reorder its characters to get 101. In the second example, $$$k = 0$$$ so you can only choose the substrings consisting only of 0 characters. Reordering them doesn't change the string at all, so the only string you can obtain is 10010.

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
// const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const s = lines[l++]
        output[i] = solve(n, k, s)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, s) {
    const ps = []
    for (let i = 0; i < s.length; i++) {
        if (s[i] === '1') ps.push(i)
    }
    if (ps.length < k) return 1

    const cache = combo(n)
    let ans = 1
    let j = 0
    for (let i = 0; i < s.length; i++) {
        const d = (j + k < ps.length ? ps[j + k] : n) - 1 - i
        let c
        if (s[i] === '1') {
            c = Math.min(ps.length - j, k)
        } else {
            c = Math.min(ps.length - j - 1, k - 1)
        }
        // const c = Math.min(ps.length - j, s[i] === '1' ? k : k - 1)
        if (d > 0 && c >= 0 && d >= c && j < ps.length) {
            ans = add(ans, cache[d][c])
        }
        // console.log(d, c)
        if (s[i] === '1') {
            j++
        }
    }
    return ans
}
const MOD = 998244353
function add(a, b) {
    return (a + b) % MOD
}
function combo(n) {
    const r = []
    for (let i = 1; i <= n; i++) {
        r[i] = []
        for (let j = 0; j <= n; j++) {
            if (i === 1 || !j || i <= j) {
                r[i][j] = 1
                continue
            }
            r[i][j] = add(r[i - 1][j - 1], r[i - 1][j])
        }
    }
    return r
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

let a;
const mod = 998244353;
function cnk(n, k) {
    if (k > n - k)
        k = n - k;
    return a[n][k];
}

function precalc(n) {
   a = new Array(n + 1);
   a[0] = new Array(1);
   a[0][0] = 1;
   for(let i = 1; i <= n; i++) {
       a[i] = new Array(Math.floor(i / 2) + 1);
       for(let j = 0; j <= Math.floor(i / 2); j++) {
           if (j === 0) {
               a[i][j] = 1;
           } else {
               a[i][j] = cnk(i-1,j-1);
               if (i > j) {
                   a[i][j] = (a[i][j] + cnk(i-1,j)) % mod;
               }
           }
       }
   }
}

let solve = async () => {
    const [n,k] = (await getLine()).split(' ').map(num => parseInt(num));
    precalc(n);
    const nk = cnk(4,2);
    const s = await getLine();
    let l,r;
    if (k===0) {
        console.log('1');
        return;
    }
    for(l = 0; l < s.length && s.charAt(l) === '0'; l++);
    if (l >= s.length) {
        console.log('1');
        return;
    }

    if (k === 1)
        r = l;
    else {
        let count = k - 1;
        for (r = l + 1; r < s.length && count > 0;)
            if (s.charAt(r) === '1') {
                count--;
                if (count > 0) {
                    r++;
                }
            } else r++;
        if (r >= s.length) {
            console.log('1');
            return;
        }
    }

    let res = 1;
    while (r < s.length) {
        let ll = l;
        let rr = r;
        while (rr + 1 < s.length && s.charAt(rr + 1) === '0') {
            rr++;
        }
        while (ll - 1 >= 0 && s.charAt(ll - 1) === '0') {
            ll--;
            res = (res + cnk(rr - ll, k - 1)) % mod;
        }
        ll = l + 1;
        while (rr - ll >= k - 1) {
            res = (res + cnk(rr - ll, k - 1)) % mod;
            ll++;
        }

        if (rr === s.length - 1) {
            res = (res + cnk(rr - l,k - 1) + mod - 1) % mod;
        }

        r++;
        while (r < s.length && s.charAt(r) === '0') r++;
        l++;
        while (l < s.length && s.charAt(l) === '0') l++;
    }

    console.log(res);

}

solve();

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
// const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const s = lines[l++]
        output[i] = solve(n, k, s)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, s) {
    const ps = []
    for (let i = 0; i < s.length; i++) {
        if (s[i] === '1') ps.push(i)
    }
    if (ps.length < k) return 1

    const cache = combo(n)
    let ans = 1
    let j = 0
    for (let i = 0; i < s.length; i++) {
        const d = (j + k < ps.length ? ps[j + k] : n) - 1 - i
        let c
        if (s[i] === '1') {
            c = Math.min(ps.length - j, k)
        } else {
            c = Math.min(ps.length - j - 1, k - 1)
        }
        // const c = Math.min(ps.length - j, s[i] === '1' ? k : k - 1)
        if (d > 0 && c >= 0 && j < ps.length) {
            ans = add(ans, cache[d][c])
        }
        // console.log(d, c)
        if (s[i] === '1') {
            j++
        }
    }
    return ans
}
const MOD = 998244353
function add(a, b) {
    return (a + b) % MOD
}
function combo(n) {
    const r = []
    for (let i = 1; i <= n; i++) {
        r[i] = []
        for (let j = 0; j <= n; j++) {
            if (i === 1 || !j || i <= j) {
                r[i][j] = 1
                continue
            }
            r[i][j] = add(r[i - 1][j - 1], r[i - 1][j])
        }
    }
    return r
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
// const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const s = lines[l++]
        output[i] = solve(n, k, s)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, s) {
    const ps = []
    for (let i = 0; i < s.length; i++) {
        if (s[i] === '1') ps.push(i)
    }
    if (ps.length < k) return 1

    const cache = combo(n)
    let ans = 1
    let j = 0
    for (let i = 0; i < s.length; i++) {
        const d = (j + k < ps.length ? ps[j + k] : n) - 1 - i
        let c
        if (s[i] === '1') {
            c = Math.min(ps.length - j, k)
        } else {
            c = Math.min(ps.length - j - 1, k - 1)
        }
        // const c = Math.min(ps.length - j, s[i] === '1' ? k : k - 1)
        if (d > 0 && j < ps.length) {
            ans = add(ans, cache[d][c])
        }
        // console.log(d, c)
        if (s[i] === '1') {
            j++
        }
    }
    return ans
}
const MOD = 998244353
function add(a, b) {
    return (a + b) % MOD
}
function combo(n) {
    const r = []
    for (let i = 1; i <= n; i++) {
        r[i] = []
        for (let j = 0; j <= n; j++) {
            if (i === 1 || !j || i <= j) {
                r[i][j] = 1
                continue
            }
            r[i][j] = add(r[i - 1][j - 1], r[i - 1][j])
        }
    }
    return r
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

let a;
const mod = 998244353;
function cnk(n, k) {
    if (k > n - k)
        k = n - k;
    return a[n][k];
}

function precalc(n) {
   a = new Array(n + 1);
   a[0] = new Array(1);
   a[0][0] = 1;
   for(let i = 1; i <= n; i++) {
       a[i] = new Array(Math.floor(i / 2) + 1);
       for(let j = 0; j <= Math.floor(i / 2); j++) {
           if (j === 0) {
               a[i][j] = 1;
           } else {
               a[i][j] = cnk(i-1,j-1);
               if (i > j) {
                   a[i][j] = (a[i][j] + cnk(i-1,j)) % mod;
               }
           }
       }
   }
}

let solve = async () => {
    const [n,k] = (await getLine()).split(' ').map(num => parseInt(num));
    precalc(n);
    const nk = cnk(4,2);
    const s = await getLine();
    let l,r;
    for(l = 0; l < s.length && s.charAt(l) === '0'; l++);
    if (l >= s.length) {
        console.log('1');
        return;
    }
    if (k === 1)
        r = l;
    else {
        let count = k - 1;
        for (r = l + 1; r < s.length && count > 0;)
            if (s.charAt(r) === '1') {
                count--;
                if (count > 0) {
                    r++;
                }
            }
        if (r >= s.length) {
            console.log('1');
            return;
        }
    }

    let res = 1;
    while (r < s.length) {
        /* let ll = l;
         while (true) {
            let rr = r;
            while (true) {
                res = (res + cnk(rr - ll - 1, k - 2)) % mod;
                if (rr === r && ll === l) {
                    res = (res + mod - 1) % mod;
                }
                rr++;
                if (rr >= s.length || s.charAt(rr) === '1')
                    break;
            }
            ll--;
            if (ll < 0 || s.charAt(ll) === '1')
                break;
        } */
        let ll = l;
        let rr = r;
        while (rr + 1 < s.length && s.charAt(rr + 1) === '0') {
            rr++;
        }
        while (ll - 1 >= 0 && s.charAt(ll - 1) === '0') {
            ll--;
            res = (res + cnk(rr - ll, k - 1)) % mod;
        }
        ll = l + 1;
        while (rr - ll >= k - 1) {
            res = (res + cnk(rr - ll, k - 1)) % mod;
            ll++;
        }

        if (rr === s.length - 1) {
            res = (res + cnk(rr - l,k - 1) + mod - 1) % mod;
        }

        r++;
        while (r < s.length && s.charAt(r) === '0') r++;
        l++;
        while (l < s.length && s.charAt(l) === '0') l++;
    }

    console.log(res);

}

solve();


Berland annual chess tournament is coming!Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins.Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?

The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).

If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".

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

var n = +readline();
var s = readline();

var a = s.split(' ').map(function(v){return +v;});
a.sort(cmp);
if (a[n-1]===a[n])
{
    print("NO");
}
else
{
    print("YES");
}

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);}).filter(function(elem){
    return !isNaN(elem);
});
players.sort(function(a,b){
    return a<b?-1:(a>b?1:0);
});

print((players[n-1] == players[n])?'NO':'YES');

var n = parseInt(readline());
var players = readline().split(' ');
for(var i in players){
    players[i] = parseInt(players[i]);
}
players.sort(function(a,b){
    return a<b?-1:(a>b?1:0);
});

print((players[n-1] == players[n])?'NO':'YES');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});
players.sort(function(a,b){
    return a<b?-1:(a>b?1:0);
});

print((players[n-1] == players[n])?'NO':'YES');

var length = readline().split(" ").map(function(x) { return parseInt(x); })[0];
var raitings = readline().split(" ").map(function(x) { return parseInt(x); });
raitings.sort(function(a,b) { return a - b;});
var mid = raitings.length / 2;
print(raitings[mid - 1] < raitings[mid] ? "YES" : "NO")

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});

players.sort(function(a,b){
    return a>=b;
});
var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);

print((result1<result2 && players[n]>=players[n-1])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});
players.sort(function(a,b){
    return a>=b;
});
write((players[n]==players[n-1])?'NO':'YES');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});

players.sort(function(a,b){
    return a>=b;
});
var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);

print((result1<result2 && players[n]<players[n-1])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});
players.sort();
print((players[n]>players[n-1])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});

players.sort(function(a,b){
    return a>=b;
});
var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);

print((result1<result2 && players[n]==players[n-1])?'NO':'YES');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);}).filter(function(elem){
    return !isNaN(elem);
});
players.sort(function(a,b){
    return a>=b;
});
var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);
/*print((players[n-1] == players[n])?'NO':'YES');
*/
if((result1 < result2) && (players[n-1] < players[n])){
    print("YES");
}else{
    print("NO");
}

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);}).filter(function(elem){
    return !isNaN(elem);
});
players.sort(function(a,b){
    return a>=b;
});
var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);

print((result1<result2 && players[n-1] < players[n])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);}).filter(function(elem){
    return !isNaN(elem);
});
players.sort(function(a,b){
    return a>=b;
});
/*var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);*/

print((players[n-1] == players[n])?'NO':'YES');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});
players.sort(function(a,b){
    return a>=b;
});
print((players[n]>players[n-1])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});

players.sort(function(a,b){
    return a>b;
});

write((players[n]>players[n-1])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});
players.sort(function(a,b){
    return a>=b;
});
print((players[n]==players[n-1])?'NO':'YES');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});

players.sort(function(a,b){
    return a>=b;
});
var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);

print((result1<result2 && players[n]>players[n-1])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});
players.sort(function(a,b){
    return a>b;
});
print((players[n]>players[n-1])?'YES':'NO');

var n = parseInt(readline());
var players = readline().split(' ').map(function(term) { return parseInt(term);});

players.sort(function(a,b){
    return a>=b;
});
var result1 = players.slice(0,n).reduce(function(sum, elem){return sum+elem},0);
var result2 = players.slice(n).reduce(function(sum, elem){return sum+elem},0);

print((result1<result2 && players[n-1] < players[n])?'YES':'NO');

var length = readline().split(" ").map(function(x) { return parseInt(x); })[0];
var raitings = readline().split(" ").map(function(x) { return parseInt(x); });
raitings.sort();
var mid = raitings.length / 2;
print(raitings[mid - 1] < raitings[mid] ? "YES" : "NO")


Ashish has an array $$$a$$$ of consisting of $$$2n$$$ positive integers. He wants to compress $$$a$$$ into an array $$$b$$$ of size $$$n-1$$$. To do this, he first discards exactly $$$2$$$ (any two) elements from $$$a$$$. He then performs the following operation until there are no elements left in $$$a$$$:   Remove any two elements from $$$a$$$ and append their sum to $$$b$$$. The compressed array $$$b$$$ has to have a special property. The greatest common divisor ($$$\mathrm{gcd}$$$) of all its elements should be greater than $$$1$$$.Recall that the $$$\mathrm{gcd}$$$ of an array of positive integers is the biggest integer that is a divisor of all integers in the array.It can be proven that it is always possible to compress array $$$a$$$ into an array $$$b$$$ of size $$$n-1$$$ such that $$$gcd(b_1, b_2..., b_{n-1}) > 1$$$. Help Ashish find a way to do so.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 1000$$$). The second line of each test case contains $$$2n$$$ integers $$$a_1, a_2, \ldots, a_{2n}$$$ ($$$1 \leq a_i \leq 1000$$$) — the elements of the array $$$a$$$.

For each test case, output $$$n-1$$$ lines — the operations performed to compress the array $$$a$$$ to the array $$$b$$$. The initial discard of the two elements is not an operation, you don't need to output anything about it. The $$$i$$$-th line should contain two integers, the indices ($$$1$$$ —based) of the two elements from the array $$$a$$$ that are used in the $$$i$$$-th operation. All $$$2n-2$$$ indices should be distinct integers from $$$1$$$ to $$$2n$$$. You don't need to output two initially discarded elements from $$$a$$$. If there are multiple answers, you can find any.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let _ = readLine();
    let arr = readLine()
      .split(" ")
      .map((num) => parseInt(num));
    solve(arr);
  }

  function solve(arr) {
    const evenMap = {};
    const oddMap = {};

    arr.forEach((num, index) => {
      if (num % 2 === 0) evenMap[index + 1] = num;
      else oddMap[index + 1] = num;
    });

    let evenKeys = Object.keys(evenMap);
    let oddKeys = Object.keys(oddMap);

    for (let i = 0; i < arr.length / 2 - 1; i++) {
      if (evenKeys.length >= 2) console.log(`${evenKeys.pop()} ${evenKeys.pop()}`);
      else console.log(`${oddKeys.pop()} ${oddKeys.pop()}`);
    }
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var input = '';
process.stdin.on('data', function (line) {
    input += line;
});
process.stdin.on('end', function () {
    var lines = input.split('\n');
    var tests = parseInt(lines.shift(), 10);
    var _loop_1 = function () {
        var n = parseInt(lines.shift(), 10);
        var arr = lineToNumArray(lines.shift());
        var indices = [[], []];
        arr.forEach(function (element, index) { return indices[element % 2].push(index); });
        if (indices[0].length % 2) {
            indices[0].shift();
            indices[1].shift();
        }
        else {
            var parity = Number(!indices[0].length);
            indices[parity].shift();
            indices[parity].shift();
        }
        indices.forEach(function (parity) {
            while (parity.length) {
                console.log(1 + parity.pop(), 1 + parity.pop());
            }
        });
    };
    while (tests--) {
        _loop_1();
    }
});
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(function (element) { return parseInt(element, 10); });
}

const processData = (lines) => {
  let acc = 0
  const n = +lines[acc]
  acc++
  for (let i=0; i<n; i++) {
    let n = +lines[acc]
    acc++
    const arr = lines[acc].split(' ').map(x => x%2)
    acc++
    const map = {
      0: [],
      1: []
    }
    for (let i =0; i<arr.length; i++) {
      map[arr[i]].push(i)
    }

    let cursor = [0, 0]

    while (n > 1) {
      const l = map[cursor[0]].length
      if (l <= cursor[1]+1) {
        cursor[0] = 1
        cursor[1] = 0
      }
      console.log(map[cursor[0]][cursor[1]]+1, map[cursor[0]][cursor[1]+1]+1)
      cursor[1] += 2
      n--
    }
  }
}

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*/
  processData(lines)
})

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var n = +readline();
    var arr = readNumArray();
    var lastEven = 0;
    var lastOdd = 0;
    var counter = 0;
    for (var j = 1; j <= 2 * n; j++) {
      if (arr[j - 1] % 2) {
        if (lastOdd) {
          print(lastOdd + " " + j);
          lastOdd = 0;
          counter++;
        } else {
          lastOdd = j;
        }
      } else {
        if (lastEven) {
          print(lastEven + " " + j);
          lastEven = 0;
          counter++;
        } else {
          lastEven = j;
        }
      }
      if (counter === n - 1) {
        break;
      }
    }
  }
}

main();

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let _ = readLine();
    let arr = readLine()
      .split(" ")
      .map((num) => parseInt(num));
    solve(arr);
  }

  function solve(arr) {
    const map = { even: [], odd: [] };
    arr.forEach((num) => {
      if (num % 2 === 0) map["even"].push(num);
      else map["odd"].push(num);
    });
    for (let i = 0; i < arr.length / 2 - 1; i++) {
      if (map["even"].length >= 2) console.log(`${map["even"].pop()} ${map["even"].pop()}`);
      else console.log(`${map["odd"].pop()} ${map["odd"].pop()}`);
    }
  }
}


Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.

The first line contains integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate.

Print a single number — the maximum number of trees that you can cut down by the given rules.

NoteIn the first sample you can fell the trees like that:   fell the 1-st tree to the left — now it occupies segment [ - 1;1]  fell the 2-nd tree to the right — now it occupies segment [2;3]  leave the 3-rd tree — it occupies point 5  leave the 4-th tree — it occupies point 10  fell the 5-th tree to the right — now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].

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

    this.find = function( val , fl ) {
    	var lo , hi , mi , res , sz1 , sz2 ;
    	sz1 = this.brr.length ;
    	sz2 = this.crr.length ;
    	lo = 0 ;
    	if( fl == false ) {
    		hi = sz1 - 1 ;
    	}
    	else {
    		hi = sz2 - 1 ;
    	}
    	res = -1 ;
    	while( lo <= hi ) {
    		mi = Math.floor( ( lo + hi ) / 2 ) ;
    		if( fl == false ) {
    			if( this.brr[ mi ].index < val ) {
    				lo = mi + 1 ;
    				res = Math.max( res , mi ) ;
    			}
    			else {
    				hi = mi - 1 ;
    			}
    		}
    		else {
    			if( this.crr[ mi ].index + this.crr[ mi ].height < val ) {
    				lo = mi + 1 ;
    				res = Math.max( res , mi ) ;
    			}
    			else {
    				hi = mi - 1 ;
    			}
    		}
    	}
    	if( res != -1 ) {
    		if( fl == false ) {
    			res = this.brr[ res ].arrayIndex ;
    		}
    		else {
    			res = this.crr[ res ].arrayIndex ;
    		}
    	}
    	return res ;
    } ;

    this.solveCase = function() {
        var res , i , j ;
        res = 0 ;
        this.arr = this.arr.sort( function( left , right ) { return left.index - right.index ; } ) ;
        this.brr = [] ;
        for( i = 0 ; i < this.n ; i++ ) {
        	if( i == 0 ) {
        		this.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        	else if( this.arr[ i ].index - this.arr[ i ].height > this.arr[ i - 1 ].index ) {
        		this.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        }
        this.crr = [] ;
        for( i = 0 ; i < this.n ; i++ ) {
        	if( i == this.n - 1 ) {
        		this.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        	else if( this.arr[ i ].index + this.arr[ i ].height < this.arr[ i + 1 ].index ) {
        		this.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        }
        for( i = 0 ; i < this.n ; i++ ) {
        	this.memo[ i ][ 0 ] = 1 ;
        	this.memo[ i ][ 1 ] = 1 ;
        	if( i > 0 ) {
        		j = this.find( this.arr[ i ].index - this.arr[ i ].height , false ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 0 ] + 1 ) ;
        		}
        		j = this.find( this.arr[ i ].index - this.arr[ i ].height , true ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 1 ] + 1 ) ;
        		}
        		j = this.find( this.arr[ i ].index , false ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 0 ] + 1 ) ;
        		}
        		j = this.find( this.arr[ i ].index , true ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 1 ] + 1 ) ;
        		}
	        	this.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ i - 1 ][ 0 ] ) ;
	        	this.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ i - 1 ][ 1 ] ) ;
        	}
        	res = Math.max( res , this.memo[ i ][ 0 ] ) ;
	        res = Math.max( res , this.memo[ i ][ 1 ] ) ;
        }
        print( res );
    };

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

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

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

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

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

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

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

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

function toi(x){return parseInt(x);}
var n=+readline();
if(n==1){
    print("1")
    quit();
}
var treex=[];
var treeh=[];
for(var i=0;i<n;i++){
    var tmp=readline().split(" ").map(toi);
    treex.push(tmp[0]);
    treeh.push(tmp[1]);
}
var res=1;
var pH=0;
for(var i=1;i<n-1;i++){
    if(pH+treeh[i]<treex[i]-treex[i-1]){//left
	pH=0;
	res++;
    }else if(treeh[i]<treex[i+1]-treex[i]){//right
	pH=treeh[i];
	res++;
    }else{
	pH=0;
    }
}
res++;
print(res);

var n = +readline();

const FALL = {
    yes: {},
    maybe: {},
    no: {}
};

var fallType = function (fallTree, blockTree) {
    var distance = Math.abs(fallTree.x - blockTree.x);

    if (fallTree.h + blockTree.h < distance) {
        return FALL.yes;
    }

    if (fallTree.h < distance) {
        return blockTree.h >= distance ? FALL.yes : FALL.maybe;
    }

    return FALL.no;
};

var Tree = function (data) {
    this.x = +data[0];
    this.h = +data[1];
};

Tree.prototype.calculate = function (leftTree, rightTree) {
    this.left = fallType(this, leftTree);
    this.right = fallType(this, rightTree);
};

Tree.prototype.canFall = function () {
    return this.left === FALL.yes || this.right === FALL.yes;
};

Tree.prototype.cantFall = function () {
    return this.left === FALL.no && this.right === FALL.no;
};

var trees = [new Tree([-Infinity, 0])];
for (var i = 0; i < n; ++i) {
    trees.push(new Tree(readline().split(' ')));
}
trees.push(new Tree([+Infinity, 0]));

for (var i = 1; i <= n; ++i) {
    trees[i].calculate(trees[i - 1], trees[i + 1]);
}

var result = 0;
var state = 0;

for (var i = 1; i <= n; ++i) {
    switch (state) {
        case 0:
            if (trees[i].canFall()) {
                ++result;
                state = 0;
            } else {
                if (trees[i].cantFall()) {
                    state = 0;
                } else {
                    if (trees[i].left === FALL.no) {
                        ++result;
                        state = 1;
                    } else {
                        ++result;
                    }
                }
            }
            break;
        case 1:
            if (trees[i].canFall()) {
                ++result;
                state = 0;
            } else {
                if (trees[i].cantFall()) {
                    state = 0;
                } else {
                    if (trees[i].right === FALL.no) {
                        state = 0;
                    } else {
                        ++result;
                    }
                }
            }
            break;
    }
}

write(result);

var n = +readline();

const FALL = {
  yes: {},
  maybe: {},
  no: {}
}

var fallType = function(fallTree, blockTree) {
  var distance = Math.abs(fallTree.x - blockTree.x);

  if (fallTree.h + blockTree.h < distance) {
      return FALL.yes;
  }

  if (fallTree.h < distance) {
      if (blockTree.h >= distance) {
          return FALL.yes;
      }
      else {
          return FALL.maybe;
      }
  }

  return FALL.no;
}

var Tree = function(data) {
  this.x = +data[0];
  this.h = +data[1];
};

Tree.prototype.calculate = function(leftTree, rightTree) {
  this.left = fallType(this, leftTree);
  this.right = fallType(this, rightTree);
};

Tree.prototype.canFall = function() {
  return this.left === FALL.yes || this.right === FALL.yes;
};

Tree.prototype.cantFall = function() {
  return this.left === FALL.no && this.right === FALL.no;
};

Tree.prototype.maybeFall = function() {
  return this.left === FALL.maybe || this.right === FALL.maybe;
};

var trees = [new Tree([-Infinity, 0])];
for (var i = 0; i < n; ++i) {
  trees.push(new Tree(readline().split(' ')));
}
trees.push(new Tree([+Infinity, 0]));

for (var i = 1; i <= n; ++i) {
  trees[i].calculate(trees[i-1], trees[i+1]);
}

var result = 0;
var state = 0;

for (var i = 1; i <= n; ++i) {
  switch (state) {
      case 0:
        if (trees[i].canFall()) {
            ++result;
            state = 0;
        } else {
            if (trees[i].cantFall()) {
                state = 0;
            } else {
                if (trees[i].left === FALL.no) {
                    ++result;
                    state = 1;
                } else {
                    ++result;
                }
            }
        }
        break;
      case 1:
        if (trees[i].canFall()) {
            ++result;
            state = 0;
        } else {
            if (trees[i].cantFall()) {
                state = 0;
            } else {
                if (trees[i].right === FALL.no) {
                    state = 0;
                } else {
                    ++result;
                }
            }
        }
        break;
  }
}

write(result);

var n = +readline();

const FALL = {
    yes: {},
    maybe: {},
    no: {}
};

var fallType = function (fallTree, blockTree) {
    var distance = Math.abs(fallTree.x - blockTree.x);

    if (fallTree.h + blockTree.h < distance) {
        return FALL.yes;
    }

    if (fallTree.h < distance) {
        return blockTree.h >= distance ? FALL.yes : FALL.maybe;
    }

    return FALL.no;
};

var Tree = function (data) {
    this.x = +data[0];
    this.h = +data[1];
};

Tree.prototype.calculate = function (leftTree, rightTree) {
    this.left = fallType(this, leftTree);
    this.right = fallType(this, rightTree);
};

Tree.prototype.canFall = function () {
    return this.left === FALL.yes || this.right === FALL.yes;
};

Tree.prototype.cantFall = function () {
    return this.left === FALL.no && this.right === FALL.no;
};

var trees = [new Tree([-Infinity, 0])];
for (var i = 0; i < n; ++i) {
    trees.push(new Tree(readline().split(' ')));
}
trees.push(new Tree([+Infinity, 0]));

for (var i = 1; i <= n; ++i) {
    trees[i].calculate(trees[i - 1], trees[i + 1]);
}

var result = 0;
var state = 0;

for (var i = 1; i <= n; ++i) {
    switch (state) {
        case 0:
            if (trees[i].canFall()) {
                ++result;
            } else if (trees[i].cantFall()) {
                // nothing do to here
            } else if (trees[i].left === FALL.no) {
                ++result;
                state = 1;
            } else {
                ++result;
            }
            break;
        case 1:
            if (trees[i].canFall()) {
                ++result;
                state = 0;
            } else if (trees[i].cantFall()) {
                state = 0;
            } else if (trees[i].right === FALL.no) {
                state = 0;
            } else {
                ++result;
            }

            break;
    }
}

write(result);

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

    this.solveCase = function() {
        var res , i , j , fl , cn , temp , a , b , c , d ;
        res = 0 ;
        this.arr = this.arr.sort( function( left , right ) { return left.index - right.index ; } ) ;
        a = -2000000000 ;
        b = -2000000000 ;
        aa = 0 ;
        bb = 0 ;
        for( i = 0 ; i < this.n ; i++ ) {
        	c = this.arr[ i ].index ;
        	d = this.arr[ i ].height ;
        	if( a < c - d ) {
        		a = c ;
        		aa += 1 ;
        	}
        	else if( b < c - d ) {
        		a = c ;
        		aa += 1 ;
        	}
        	if( b < c ) {
        		b = c + d ;
        		bb += 1 ;
        	}
        	else if( a < c ) {
        		b = c + d ;
        		bb += 1 ;
        	}
        	res = Math.max( res , aa ) ;
        	res = Math.max( res , bb ) ;
        }
        print( res - 1 );
    };

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

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

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

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

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

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

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

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

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

    this.find = function( val , fl ) {
    	var lo , hi , mi , res , sz1 , sz2 ;
    	sz1 = this.brr.length ;
    	sz2 = this.crr.length ;
    	lo = 0 ;
    	if( fl == false ) {
    		hi = sz1 - 1 ;
    	}
    	else {
    		hi = sz2 - 1 ;
    	}
    	res = -1 ;
    	while( lo <= hi ) {
    		mi = Math.floor( ( lo + hi ) / 2 ) ;
    		if( fl == false ) {
    			if( this.brr[ mi ].index < val ) {
    				lo = mi + 1 ;
    				res = Math.max( res , mi ) ;
    			}
    			else {
    				hi = mi - 1 ;
    			}
    		}
    		else {
    			if( this.crr[ mi ].index + this.crr[ mi ].height < val ) {
    				lo = mi + 1 ;
    				res = Math.max( res , mi ) ;
    			}
    			else {
    				hi = mi - 1 ;
    			}
    		}
    	}
    	if( res != -1 ) {
    		if( fl == false ) {
    			res = this.brr[ res ].arrayIndex ;
    		}
    		else {
    			res = this.crr[ res ].arrayIndex ;
    		}
    	}
    	return res ;
    } ;

    this.solveCase = function() {
        var res , i , j ;
        res = 0 ;
        this.arr = this.arr.sort( function( left , right ) { return left.index - right.index ; } ) ;
        this.brr = [] ;
        for( i = 0 ; i < this.n ; i++ ) {
        	if( i == 0 ) {
        		this.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        	else if( this.arr[ i ].index - this.arr[ i ].height > this.arr[ i - 1 ].index ) {
        		this.brr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        }
        this.crr = [] ;
        for( i = 0 ; i < this.n ; i++ ) {
        	if( i == this.n - 1 ) {
        		this.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        	else if( this.arr[ i ].index + this.arr[ i ].height < this.arr[ i + 1 ].index ) {
        		this.crr.push( { index : this.arr[ i ].index , height : this.arr[ i ].height , arrayIndex : i } ) ;
        	}
        }
        for( i = 0 ; i < this.n ; i++ ) {
        	this.memo[ i ][ 0 ] = 1 ;
        	this.memo[ i ][ 1 ] = 1 ;
        	if( i > 0 ) {
        		j = this.find( this.arr[ i ].index - this.arr[ i ].height , false ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 0 ] + 1 ) ;
        		}
        		j = this.find( this.arr[ i ].index - this.arr[ i ].height , true ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ j ][ 1 ] + 1 ) ;
        		}
        		j = this.find( this.arr[ i ].index , false ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 0 ] + 1 ) ;
        		}
        		j = this.find( this.arr[ i ].index , true ) ;
        		if( j != -1 ) {
        			this.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ j ][ 1 ] + 1 ) ;
        		}
	        	this.memo[ i ][ 0 ] = Math.max( this.memo[ i ][ 0 ] , this.memo[ i - 1 ][ 0 ] ) ;
	        	this.memo[ i ][ 1 ] = Math.max( this.memo[ i ][ 1 ] , this.memo[ i - 1 ][ 1 ] ) ;
	        	res = Math.max( res , this.memo[ i ][ 0 ] ) ;
	        	res = Math.max( res , this.memo[ i ][ 1 ] ) ;
        	}
        }
        print( res );
    };

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

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

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

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

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

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

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

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

function toi(x){return parseInt(x);}
var n=+readline();
var treex=[];
var treeh=[];
for(var i=0;i<n;i++){
    var tmp=readline().split(" ").map(toi);
    treex.push(tmp[0]);
    treeh.push(tmp[1]);
}
var res=1;
var pH=0;
for(var i=1;i<n-1;i++){
    if(pH+treeh[i]<treex[i]-treex[i-1]){//left
	pH=0;
	res++;
    }else if(treeh[i]<treex[i+1]-treex[i]){//right
	pH=treeh[i];
	res++;
    }else{
	pH=0;
    }
}
res++;
print(res);

var n = +readline();

const FALL = {
  yes: {},
  maybe: {},
  no: {}
}

var fallType = function(fallTree, blockTree) {
  var distance = Math.abs(fallTree.x - blockTree.x);

  if (fallTree.h + blockTree.h < distance) {
      return FALL.yes;
  }

  if (fallTree.h < distance) {
      if (blockTree.h >= distance) {
          return FALL.yes;
      }
      else {
          return FALL.maybe;
      }
  }

  return FALL.no;
}

var Tree = function(data) {
  this.x = +data[0];
  this.h = +data[1];
};

Tree.prototype.calculate = function(leftTree, rightTree) {
  this.left = fallType(this, leftTree);
  this.right = fallType(this, rightTree);
};

Tree.prototype.canFall = function() {
  return this.left === FALL.yes || this.right === FALL.yes;
};

Tree.prototype.cantFall = function() {
  return this.left === FALL.no && this.right === FALL.no;
};

Tree.prototype.maybeFall = function() {
  return this.left === FALL.maybe || this.right === FALL.maybe;
};

var trees = [new Tree([-Infinity, 0])];
for (var i = 0; i < n; ++i) {
  trees.push(new Tree(readline().split(' ')));
}
trees.push(new Tree([+Infinity, 0]));

for (var i = 1; i <= n; ++i) {
  trees[i].calculate(trees[i-1], trees[i+1]);
}

var result = 0;
var state = 0;

for (var i = 1; i <= n; ++i) {
  switch (state) {
      case 0:
        if (trees[i].canFall()) {
            ++result;
        } else {
            if (trees[i].cantFall()) {
                // nothing to do here
            } else {
                if (trees[i].left = FALL.maybe) {
                    ++result;
                } else {
                    ++result;
                    state = 1;
                }
            }
        }
        break;
      case 1:
        if (trees[i].canFall()) {
            ++result;
            state = 0;
        } else {
            if (trees[i].cantFall()) {
                state = 0;
            } else {
                if (trees[i].right = FALL.no) {
                    state = 0;
                } else {
                    ++result;
                }
            }
        }
        break;
  }
}

write(result);

var n = +readline();

const FALL = {
  yes: {},
  maybe: {},
  no: {}
}

var fallType = function(fallTree, blockTree) {
  var distance = Math.abs(fallTree.x - blockTree.x);

  if (fallTree.h + blockTree.h < distance) {
      return FALL.yes;
  }

  if (fallTree.h < distance) {
      if (blockTree.h >= distance) {
          return FALL.yes;
      }
      else {
          return FALL.maybe;
      }
  }

  return FALL.no;
}

var Tree = function(data) {
  this.x = +data[0];
  this.h = +data[1];
};

Tree.prototype.calculate = function(leftTree, rightTree) {
  this.left = fallType(this, leftTree);
  this.right = fallType(this, rightTree);
};

Tree.prototype.canFall = function() {
  return this.left === FALL.yes || this.right === FALL.yes;
};

Tree.prototype.cantFall = function() {
  return this.left === FALL.no && this.right === FALL.no;
};

Tree.prototype.maybeFall = function() {
  return this.left === FALL.maybe || this.right === FALL.maybe;
};

var trees = [new Tree([-Infinity, 0])];
for (var i = 0; i < n; ++i) {
  trees.push(new Tree(readline().split(' ')));
}
trees.push([new Tree([+Infinity, 0])]);

for (var i = 1; i <= n; ++i) {
  trees[i].calculate(trees[i-1], trees[i+1]);
}

var result = 0;
var state = 0;

for (var i = 1; i <= n; ++i) {
  switch (state) {
      case 0:
        if (trees[i].canFall()) {
            ++result;
        } else {
            if (trees[i].cantFall()) {
                // nothing to do here
            } else {
                if (trees[i].left = FALL.maybe) {
                    ++result;
                } else {
                    ++result;
                    state = 1;
                }
            }
        }
        break;
      case 1:
        if (trees[i].canFall()) {
            ++result;
            state = 0;
        } else {
            if (trees[i].cantFall()) {
                state = 0;
            } else {
                if (trees[i].right = FALL.no) {
                    state = 0;
                } else {
                    ++result;
                }
            }
        }
        break;
  }
}

write(result);

var n = +readline(),
    x = [],
    h = [],
    spc = [],
    count = 2;

for (var i = 0; i < n; i ++)
{
  var line = readline().split(' ');
  x[i] = +line[0],
  h[i] = +line[1];
}

for (var i = 1; i < n - 1; i ++)
{
  if (x[i - 1] < x[i] - h[i])
  {
    count ++;
  }
  else if (x[i + 1] > x[i] + h[i])
  {
    x[i] += h[i];
    count ++;
  }
}

print(count);