codeparrot/codecomplex huggingface dataset:
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;
import static java.lang.Math.*;

public class Main{
  public static void main(String[] args){
    new Main().run();
  }
  
  void run(){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt() * 2;
    H[] tbl = new H[n];
    for(int i = 0; i < n; i++)tbl[i] = new H(sc.nextInt()*2, sc.nextInt()*2);
    Arrays.sort(tbl);
    TreeSet<Integer> cand = new TreeSet<Integer>();
    //cand.add(tbl[0].x - tbl[0].len / 2);
    for(int i = 0; i < n; i++){
      int left = tbl[i].x - tbl[i].len / 2 - t / 2;
      if(!cand.contains(left)){
        if(i > 0 && tbl[i-1].x + tbl[i-1].len/2 > left - t/2){
          
        }else{
          cand.add(left);
        }
      }
      int right = tbl[i].x + tbl[i].len / 2 + t/2;
      if(!cand.contains(right)){
        if(i < n-1 && tbl[i+1].x - tbl[i+1].len/2 < right + t/2){
          
        }else{
          cand.add(right);
        }
      }
    }
    System.out.println(cand.size());
  }
  
  class H implements Comparable<H>{
    int x, len;
    H(int a, int b){
      x = a;
      len = b;
    }
    public int compareTo(H h){
      return this.x - h.x;
    }
  }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;
public class j
{
public static void main(String a[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int k=0,i=0,j=0,n=0,p=0,t=0;
String s;
s=b.readLine();
StringTokenizer c=new StringTokenizer(s);
n=Integer.parseInt(c.nextToken());
k=Integer.parseInt(c.nextToken());
int d[]=new int[n];
int e[]=new int[n];
for(i=0;i<n;i++)
{
s=b.readLine();
StringTokenizer z=new StringTokenizer(s);
d[i]=Integer.parseInt(z.nextToken());
e[i]=Integer.parseInt(z.nextToken());
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(d[j]<d[i])
{
t=d[j];
d[j]=d[i];
d[i]=t;
t=e[j];
e[j]=e[i];
e[i]=t;
}
}
}
for(i=0;i<n-1;i++)
{
if(((d[i+1]-e[i+1]/2.0)-(d[i]+e[i]/2.0))>k)
p+=2;
if(((d[i+1]-e[i+1]/2.0)-(d[i]+e[i]/2.0))==k)
p++;
}
System.out.print(p+2);
}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.text.*;
import java.util.*;

public class CottageVillage {

	static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;

	static String LINE() throws Exception { return stdin.readLine(); }
	static String TOKEN() throws Exception {
		while (st == null || !st.hasMoreTokens())st = new StringTokenizer(LINE());
		return st.nextToken();
	}
	static int INT() throws Exception {return Integer.parseInt(TOKEN());}
	static long LONG() throws Exception {return Long.parseLong(TOKEN());}
	static double DOUBLE() throws Exception {return Double.parseDouble(TOKEN());}

	static DecimalFormat DF = new DecimalFormat("0.000",new DecimalFormatSymbols(Locale.ENGLISH));
	
	public static final double EPSILON = 1E-9;
	
	public static void main(String[] args) throws Exception {
		int N = INT(), T = INT();
		House[] list = new House[N];
		for(int i = 0;i<N;i++) {
			list[i] = new House(INT(),INT());
		}
		Arrays.sort(list);
		int cnt = 2;
		for(int i = 1;i<N;i++) {
			int room = list[i].center-list[i-1].center;
			if(2*T<2*room-list[i].side-list[i-1].side)cnt += 2;
			else if(2*T==2*room-list[i].side-list[i-1].side)cnt++;
		}
		System.out.println(cnt);
		
	}
	
	private static class House implements Comparable<House> {
		int center, side;
		House(int c, int s) {
			this.center = c;
			this.side = s;
		}
		public int compareTo(House h) {
			return this.center-h.center;
		}
	}

}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class A {

    static class Entity implements Comparable {

        public Entity(int x, int a) {
            this.x = x;
            this.a = a;
        }
        public int x, a;

        public int compareTo(Object t) {
            Entity o = (Entity) t;
            return x == o.x ? 0 : x < o.x ? -1 : 1;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), t = 2 * scanner.nextInt();
        if (1 == n) {
            System.out.println(2);
        } else {
            int rez = 2;
            ArrayList<Entity> list = new ArrayList<Entity>();
            for (int i = 0; i < n; i++) {
                list.add(new Entity(scanner.nextInt(), scanner.nextInt()));
            }
            Collections.sort(list);
            for (int i = 1; i < n; i++) {
                int num = 2 * (list.get(i).x - list.get(i - 1).x)
                        - list.get(i).a - list.get(i - 1).a;
                if (t < num) {
                    rez += 2;
                } else if (t == num) {
                    rez++;
                }
            }
            System.out.println(rez);
        }
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class AA {

	static class Pair implements Comparable<Pair> {
		public int x, y;
		public Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
		public int compareTo(Pair p) {
			if (p.x != x)
				return x - p.x;
			return y - p.y;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int t = in.nextInt() * 2;
		List<Pair> l = new ArrayList<Pair>();
		for (int i = 0; i < n; i++) {
			int c = in.nextInt() * 2;
			int a = in.nextInt();
			l.add(new Pair(c - a, c + a));
		}
		Collections.sort(l);
		int ret = 2;
		for (int i = 1; i < n; i++) {
			if (l.get(i).x - l.get(i-1).y > t)
				ret += 2;
			else if (l.get(i).x - l.get(i-1).y == t)
				ret += 1;
		}
		System.out.println(ret);
	}

}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists()) {
				System.setIn(new FileInputStream("input.txt"));
			}
		} catch (SecurityException e) {
		}
		
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		int N = nextInt();
		int T = nextInt();

		Pair[] p = new Pair [N];
		for (int i = 0; i < N; i++)
			p[i] = new Pair(nextInt(), nextInt());
		sort(p);
		int ans = 2;
		for (int i = 1; i < N; i++) {
			int dif = (2 * p[i].x - p[i].a) - (2 * p[i - 1].x + p[i - 1].a);
			if (dif == 2 * T)
				ans++;
			else if (dif > 2 * T)
				ans += 2;
		}
		out.println(ans);
		out.close();
	}
	
	class Pair implements Comparable<Pair> {
		int x, a;
		
		public Pair(int xx, int aa) {
			x = xx;
			a = aa;
		}
		
		@Override
		public int compareTo(Pair p) {
			return x < p.x ? -1 : 1;
		}
	}
	
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.BufferedReader;
import static java.lang.Math.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class CodeforcesA implements Runnable {
	public static final String taskname = "A";
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(new CodeforcesA()).start();
	}
	
	static class Square implements Comparable<Square>{
		int x, a;
		public Square(int x, int a) {
			this.x = x;
			this.a = a;
		}
		@Override
		public int compareTo(Square o) {
			return x - o.x;
		}
		
		int distance(Square a, int t) {
			double dist = a.x - x - this.a / 2.0 - a.a / 2.0;
			if(dist > t) return 2;
			else if(abs(dist - t) < 1e-9) return 1;
			return 0;
		}
		
		public String toString() {
			return x + " " + a;
		}
	}
	

	void solve() throws IOException {
		int n = nextInt(), t = nextInt();
		Square[] x = new Square[n];
		for(int i = 0; i < n; ++i) {
			x[i] = new Square(nextInt(), nextInt());
		}
		Arrays.sort(x);
		long res = 2;
		for(int i = 0; i < n - 1; ++i) {
			res += x[i].distance(x[i + 1], t);
		}
		out.println(res);
			
	}

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			//in = new BufferedReader(new FileReader(new File("input.txt")));
			 out = new PrintWriter(System.out);
			//out = new PrintWriter(new File("output.txt"));
			solve();
			out.flush();
			out.close();
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	String nextLine() throws IOException {
		tok = null;
		return in.readLine();
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class CottageVillage {
    
    class cl {
        int x=0;
        int a=0;
        
        cl(int x, int a){
            this.x=x; 
            this.a=a;
        }
    }
    
    class cmp implements Comparator<cl> {
        public int compare(cl d1, cl d2) {
            return d1.x<d2.x ? -1 : 1;
        }
    }
    
    public CottageVillage() {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        cl[] w = new cl[n];
        for(int i=0; i<n; i++)
            w[i] = new cl(sc.nextInt(), sc.nextInt());
        Arrays.sort(w, new cmp());
        
        int cnt=2, diff=0; 
        for(int i=1; i<n; i++) {
            diff = Math.abs(2*w[i].x-2*w[i-1].x-w[i].a-w[i-1].a)-2*k; 
            if (diff>0) cnt+=2;
            else if (diff==0) cnt++;
        }
        System.out.println(cnt);
    }
    
    public static void main(String... args) {
        new CottageVillage();
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
public class A {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int t = Integer.parseInt(st.nextToken());
		State[] s = new State[n];
		for(int i = 0; i < n; i++)	{
			st = new StringTokenizer(br.readLine());
			s[i] = new State(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
		}
		Arrays.sort(s);
		int num = 2;
		for(int i = 1; i < s.length; i++)	{
			int dist = s[i].x - s[i-1].x;
			dist *= 2;
			int size = s[i].d + s[i-1].d;
			size += 2 * t;
			if(dist == size)
				num++;
			else if(dist > size)
				num += 2;
		}
		System.out.println(num);
	}
	static class State implements Comparable<State> {
		public int x,d;
		public State(int a, int b)	{
			x=a;
			d=b;
		}
		public int compareTo(State s)	{
			return x - s.x;
		}
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;
import java.math.*;

public class Task15a {

	public static class House implements Comparable<House>{
		int x, s;

		public House(int x, int s) {
			super();
			this.x = x;
			this.s = s;
		}

		public int compareTo(House o) {
			return x - o.x;
		}
		
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt() * 2;
		House[] hs = new House[n];
		for (int i = 0; i < n; i++){
			hs[i] = new House(sc.nextInt()*2, sc.nextInt());
		}
		Arrays.sort(hs);
		int res = 2;
		for (int i = 0; i < n - 1; i++) {
			int curr = hs[i+1].x - hs[i].x - hs[i+1].s - hs[i].s;
			if (curr > t) res += 2;
			if (curr == t) res += 1;
		}
		System.out.println(res);
	}

}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class _P015A{
    Scanner sc=new Scanner(System.in);

    int INF=1<<28;
    double EPS=1e-9;

    int n, t;
    int[][] a;

    void run(){
        n=sc.nextInt();
        t=sc.nextInt();
        a=new int[n][2];
        for(int i=0; i<n; i++){
            a[i][0]=sc.nextInt();
            a[i][1]=sc.nextInt();
        }
        solve();
    }

    void solve(){
        sort(a, new Comparator<int[]>(){
            @Override
            public int compare(int[] a0, int[] a1){
                return a0[0]-a1[0];
            }
        });
        int ans=2;
        for(int i=0; i<n-1; i++){
            int s=(a[i+1][0]*2-a[i+1][1])-(a[i][0]*2+a[i][1]);
            if(s>t*2){
                ans+=2;
            }else if(s==t*2){
                ans++;
            }
        }
        println(ans+"");
    }

    void println(String s){
        System.out.println(s);
    }

    void print(String s){
        System.out.print(s);
    }

    void debug(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args){
        new _P015A().run();
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;

public class ProblemA {
	
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int t = s.nextInt();
		TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
		
//		int x = 0 ;
		while(s.hasNextInt())
		{
			int i = s.nextInt();
			int j = s.nextInt();
			map.put(i,j);
//			x++;
//			if(x == 2)
//				break;
		}
		
		int count = 0;
		double left = -100000;
		double right;
		int size;
		for(Integer i : map.keySet())
		{
			size = map.get(i);
			right = (double)i - (double)size/2.0;
			
			if(right - left > t)
			{
				count+=2;
			}
			if(right - left == t)
			{
				count++;
			}
			
			left = (double)i + (double)size/2.0;
		}
		
		System.out.println(count);
	}

}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;

public class CottageVillage {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int size=sc.nextInt();
		int side=sc.nextInt();
		ArrayList<Pair> lis=new ArrayList<Pair>();
		for(int x=0;x<size;x++)
		{
			lis.add(new Pair(sc.nextInt(), sc.nextInt()));
			
		}
		Collections.sort(lis);
		int count=2;
		for(int x=0;x<lis.size()-1;x++)
		{
			Pair a=lis.get(x);
			Pair b=lis.get(x+1);
			double na=a.x+a.len/2;
			double nb=b.x-b.len/2;
			//System.out.println(na+" "+nb);
			if(na<nb)
			{
				double dif=Math.abs(nb-na);
				if(dif==side)count++;
				else if(dif>side)count+=2;
			}
		}
		System.out.println(count);
	}
}
class Pair implements Comparable<Pair>
{
	int x;
	double len;

	public Pair(int a,int b)
	{
		x=a;
		len=b;
	}
	public int compareTo(Pair o) {
		return x-o.x;
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class Main {
//	static Scanner in;
	static PrintWriter out;
	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}

	public static void main(String[] args) throws Exception {
//		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

		int n = next();
		int t = 2*next();

		int[] x = new int[n];
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = 2* next() + 2000;
			a[i] = next();
		}

		int[] srt = new int[n];
		for (int i = 0; i < n; i++) srt[i] = 10000 * x[i] + a[i];
		Arrays.sort(srt);
		for (int i = 0; i < n; i++) {
			x[i] = srt[i] / 10000;
			a[i] = srt[i] % 10000;
		}

		int answ = 2;
		for (int i = 0; i < n - 1; i++) {
			if (x[i + 1] - x[i] > a[i] + a[i + 1] + t) answ++;
			if (x[i + 1] - x[i] >= a[i] + a[i + 1] + t) answ++;
		}

		out.println(answ);

		out.close();
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;

public class Beta15PA {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Beta15PA temp = new Beta15PA();
		temp.solve();
	}
	
	public void solve() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), t = scan.nextInt();
		House[]	houses = new House[n];
		for(int i=0; i<n; i++) {
			houses[i] = new House(scan.nextInt(), scan.nextInt());
		}
		Arrays.sort(houses);
		int res = 2;
		for(int i=0; i<n-1; i++) {
			double cnt = houses[i+1].coordinate - houses[i].coordinate;
			cnt -= 1.0*(houses[i+1].side+houses[i].side)/2;
			if(cnt>t) res += 2;
			else if(Math.abs(cnt-t)<1e-7) res += 1;
		}
		System.out.println(res);
	}
	
	public class House implements Comparable<House> {
		public int coordinate, side;

		public House(int coordinate, int side) {
			this.coordinate = coordinate;
			this.side = side;
		}

		@Override
		public int compareTo(House arg0) {
			// TODO Auto-generated method stub
			return this.coordinate - arg0.coordinate;
		}
		
	}

}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ProblemA {
	
	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		String[] line = s.readLine().split(" ");
		int n = Integer.valueOf(line[0]);
		int ht = Integer.valueOf(line[1]);
		
		int[][] house = new int[n][2];
		Set<Integer> candidates = new HashSet<Integer>(); 
		for (int i = 0 ; i < n ; i++) {
			String[] data = s.readLine().split(" ");
			house[i][0] = Integer.valueOf(data[0]) * 2;
			house[i][1] = Integer.valueOf(data[1]);
			candidates.add(house[i][0] - house[i][1] - ht);
			candidates.add(house[i][0] + house[i][1] + ht);
		}
		
		int ans = 0;
		for (int p : candidates) {
			int f = p - ht;
			int t = p + ht;
			boolean isok = true;
			for (int i = 0 ; i < n ; i++) {
				if (house[i][0] + house[i][1] <= f) {
				} else if (house[i][0] - house[i][1] >= t) {
				} else {
					isok = false;
					break;
				}
			}
			if (isok) {
				ans++;
			}
		}
		
		
		out.println(ans);
		out.flush();
	}


	public static void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.Scanner;
import java.util.TreeMap;

/**
 *
 * @author camoroh13
 */
public class Solution {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
 //       Scanner sc = new Scanner(new FileInputStream("/home/camoroh13/NetBeansProjects/JavaApplication1/src/input.txt"));
        int n = sc.nextInt();
        int t = sc.nextInt();
//        int[][] h = new int[n][2];
        TreeMap<Integer, Integer> h = new TreeMap<Integer, Integer>();
        for (int i=0; i < n; i++) {
            int key = sc.nextInt();
            h.put(key, sc.nextInt());
        }

        int ans = 2;
        Integer lastKey = h.firstKey();
        Integer last = h.get(lastKey);
        h.remove(lastKey);
        for (int i=1; i < n; i++) {
            int key = h.firstKey();
            int val = h.get(key);
            //System.out.println(Math.abs(key-val*1.0/2 - (lastKey + last*1.0/2)) + "-" + key + "-"+val);
            if (Math.abs(key-val*1.0/2 - (lastKey + last*1.0/2)) == t) {
                ans++;
            } else if (Math.abs(key-val*1.0/2 - (lastKey + last*1.0/2))  > t) {
                ans += 2;
            }
            lastKey = key;
            last = val;
            h.remove(lastKey);
        }

        System.out.println(ans);
        
        sc.close();
    }


}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.Scanner;

/**
 * @author Son-Huy TRAN
 * 
 */
public class P15A_CottageVillage {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int t = scanner.nextInt();
		scanner.nextLine();

		int[] x = new int[n];
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			x[i] = scanner.nextInt();
			a[i] = scanner.nextInt();
			scanner.nextLine();
		}

		scanner.close();

		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (x[i] > x[j]) {
					swap(x, i, j);
					swap(a, i, j);
				}
			}
		}

		int countPositions = 2;

		for (int i = 1; i < n; i++) {
			double left = x[i - 1] + a[i - 1] * 1.0 / 2;
			double right = x[i] - a[i] * 1.0 / 2;
			double length = right - left;

			if (length == (double) t) {
				countPositions++;
			} else if (length > t) {
				countPositions += 2;
			}
		}

		System.out.println(countPositions);
	}

	private static void swap(int[] numbers, int i, int j) {
		int temp = numbers[i];
		numbers[i] = numbers[j];
		numbers[j] = temp;
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.awt.Point;
import java.util.Arrays;
import java.util.Scanner;


public class p15a {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int t = in.nextInt();
        if(n == 1) {
            System.out.println(2);
            return;
        }
        house[] all = new house[n];
        for (int i = 0; i < all.length; i++) {
            all[i] = new house(in.nextInt(),in.nextInt());
        }
        Arrays.sort(all);
        
        int count = 0;
        for (int i = 0; i < all.length; i++) {
            double left = all[i].center - (all[i].side*1.0/2);
            double right = all[i].center + (all[i].side*1.0/2);
            if(i == 0) {
                count++;
                double left2 = all[i+1].center - (all[i+1].side*1.0/2);
                if(right+t<left2) {
                    count++;
                }
                continue;
                
            }
            if(i == all.length-1) {
                count++;
                double right2 = all[i-1].center + (all[i-1].side*1.0/2);
                if(left-t>= right2) {
                    count++;
                }
                continue;
            }
            double left2 = all[i+1].center - (all[i+1].side*1.0/2);
            double right2 = all[i-1].center + (all[i-1].side*1.0/2);
            
            if(right+t<left2) {
                count++;
            }
            if(left-t>=right2)
                count++;
        }
        System.out.println(count);
        
    }
}
class house implements Comparable<house>{
    int center;
    int side;
    public house(int a , int b) {
        center = a;
        side = b;
    }
    public int compareTo(house o) {
        return center-o.center;
    }
}