codeparrot/codecomplex huggingface dataset:
// Problem: 15_A. Cottage Village
// Time complexity: nlogn


import java.awt.Point;
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class ProblemA_15 {
    
    final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok=new StringTokenizer("");
    
    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
            in=new BufferedReader(new InputStreamReader(System.in));
            out =new PrintWriter(System.out);
        }
        else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }
    
    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            tok=new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }
    
    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }
    
    public static void main(String[] args){
        new ProblemA_15().run();
    }
    
    public void run(){
        try{
            long t1=System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2=System.currentTimeMillis();
            System.err.println("Time = "+(t2-t1));
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
    
    void solve() throws IOException{
        int n=readInt();
        int t=readInt();
        Point[] a=new Point[n];
        for (int i=0; i<n; i++){
            a[i]=new Point(readInt(), readInt());
        }
        int count=2;
        Arrays.sort(a, new Comparator<Point>(){

            @Override
            public int compare(Point p1, Point p2) {
                return p1.x-p2.x;
            }
            
        });
        for (int i=1; i<n; i++){
            double li=a[i-1].x+(double)a[i-1].y/2;
            double ri=a[i].x-(double)a[i].y/2;
            if (ri-li>t){
                count+=2;
            }
            if (ri-li==t){
                count++;
            }
        }
        out.print(count);
    }       
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer split = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(split.nextToken());
        double t = Double.parseDouble(split.nextToken());

        House[] xaxis = new House[n];

        for (int i = 0; i < n; i++) {
            split = new StringTokenizer(in.readLine());
            xaxis[i] = new House(Double.parseDouble(split.nextToken()), Double.parseDouble(split.nextToken()));
        }
        Arrays.sort(xaxis);
        int count = 2;
        for (int i = 0; i < xaxis.length - 1; i++) {
            double free = (xaxis[i + 1].getX() - xaxis[i + 1].getSize() / 2.0) - (xaxis[i].getX() + xaxis[i].getSize() / 2.0);
            if (free / t == 1.0) {
                count++;
            } else if (free / t > 1.0) {
                count += 2;
            }
        }

        System.out.println(count);
    }
}

class House implements Comparable<House> {

    private double x;
    private double size;

    public House(double x, double size) {
        this.x = x;
        this.size = size;
    }

    public double getX() {
        return x;
    }

    public double getSize() {
        return size;
    }

    public int compareTo(House o) {
        if (this.x > o.getX()) {
            return 1;
        } else if (this.x == o.getX()) {
            return 0;
        }
        return -1;
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static Node[] node;

    public static void main(String[] args) {
    Scanner cin = new Scanner(System.in);
    int ret = 2, del;
    int n = cin.nextInt();
    int t = cin.nextInt() * 2;
    node = new Node[n];
    for (int i = 0; i < n; i++) {
        int x = cin.nextInt();
        int a = cin.nextInt();
        node[i] = new Node(x * 2 - a, x * 2 + a);
    }
    Arrays.sort(node);
    for (int i = 1; i < n; i++) {
        del = node[i].l - node[i - 1].r;
        if (del > t) {
        ret += 2;
        } else if (del == t) {
        ret++;
        }
    }
    System.out.println(ret);
    }

    private static class Node implements Comparable<Node> {
    public int l;
    public int r;

    public Node(int l, int r) {
        // TODO Auto-generated constructor stub
        this.l = l;
        this.r = r;
    }

    @Override
    public int compareTo(Node arg0) {
        // TODO Auto-generated method stub
        return l - arg0.l;
    }
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String args[]) throws IOException
	{
		Scanner sc = new Scanner(System.in/*new File("input.txt")*/);
		int n = sc.nextInt(), t = sc.nextInt(), x, a, kol = 2;
		ArrayList<Double> al = new ArrayList<Double>();
		for(int i=0;i<n;i++)
		{
			x = sc.nextInt();
			a = sc.nextInt();
			al.add(x - a/2.);
			al.add(x + a/2.);	
		}
		Collections.sort(al);
		double d0 = 0; int k = 0, kn = al.size();
		for(Double d: al)
		{
			if (k == 2)
			{
				if (d-d0>t) kol+=2; else
				if (d-d0==t) kol++;
				d0 = d;
				k = 1;		
			} else 
			{
				k++;
				d0 = d;
			}			
		} 
		System.out.print(kol);
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn

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

public class BetaRound15_A implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws IOException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

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

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	@Override
	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new BetaRound15_A()).start();
	}

	class House implements Comparable<House> {
		int left, right;
		House(int left, int right) {
			this.left = left;
			this.right = right;
		}
		@Override
		public int compareTo(House h) {
			return this.left - h.left;
		}
	}
	
	int getAns(House h1, House h2, int t) {
		int d = h2.left - h1.right;
		if (d < t) return 0;
		if (d == t) return 1;
		return 2;
	}
	
	void solve() throws IOException {
		int n = readInt();
		int t = readInt() * 2;
		House[] h = new House[n];
		for (int i = 0; i < n; i++) {
			int c = readInt() * 2;
			int b = readInt();
			h[i] = new House(c - b, c + b);
		}
		Arrays.sort(h);
		int ans = 2;
		for (int i = 1; i < n; i++) {
			ans += getAns(h[i - 1], h[i], t);
		}
		out.print(ans);
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.text.*;
import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int t = scan.nextInt();
		List<Double> coords = new ArrayList<Double>();
		while (n-- > 0) {
			double x = scan.nextDouble();
			double a = scan.nextDouble() / 2;
			coords.add(x - a);
			coords.add(x + a);
		}
		Collections.sort(coords);
		int count = 2;
		ChoiceFormat f = new ChoiceFormat("-1#0|0#1|0<2");
		for (int i = 1; i < coords.size()-2; i+=2) {
			count += new Integer(f.format(coords.get(i+1)-coords.get(i)-t));
		}
		System.out.println(count);
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn


import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int t = in.nextInt() * 2;
        Point[] A = new Point[n];
        for (int i = 0; i < n; i++) {
            int center = in.nextInt() * 2;
            int side = in.nextInt();
            A[i] = new Point(center - side, center + side);
        }
        Arrays.sort(A, new Comparator<Point>() {
            public int compare(Point x, Point y) {
                return x.x - y.x;
            }
        });
        int ans = 2;
        for (int i = 1; i < n; i++) {
            if (A[i].x - A[i - 1].y > t)
                ans += 2;
            else if (A[i].x - A[i - 1].y == t)
                ans++;
        }
        System.out.println(ans);
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn

import java.util.*;


public class main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int houses = sc.nextInt();
        int size = sc.nextInt();
        hizzy[] array = new hizzy[houses];
        long total =2;
        for(int a=0;a<houses;a++)array[a]=new hizzy(sc.nextInt(),sc.nextInt());
        Arrays.sort(array);
        for(int a=0;a<houses-1;a++){
            double L = array[a].loc+array[a].size/2;
            double R = array[a+1].loc-array[a+1].size/2;
            if(R-L>size)total+=2;
            else if((R-L)==size)total++;
        }
        System.out.println(total);
    }   

}
class hizzy implements Comparable{
    double loc;
    double size;
    hizzy(double l, double s){
        this.loc=l;
        this.size=s;
    }
    
    public int compareTo(Object o) {
        hizzy other = (hizzy) o;
        return (int) (this.loc-other.loc);
    }
    
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;

public class Village {
	
	private class House implements Comparable<House> {
		Double Coordinate;
		Double Sidelength;

		private House(double coordinate, double sidelength) {
			Coordinate = coordinate;
			Sidelength = sidelength;
		}

		public int compareTo(House o) {
			return Coordinate.compareTo(o.Coordinate);
		}
	}

	private void solve() {
		Scanner in = new Scanner(System.in);
		in.next();
		double requireside = in.nextDouble();
		ArrayList<House> coordinate = new ArrayList<House>();
		while (in.hasNext()) {
			double coo = in.nextDouble();
			double side = in.nextDouble();
			coordinate.add(new House(coo, side));
		}
		Collections.sort(coordinate);
		ArrayList<Double> edges = new ArrayList<Double>();
		int count = 2;
		for (int i = 0; i < coordinate.size(); i++) {
			edges.add(coordinate.get(i).Coordinate
					- (double) coordinate.get(i).Sidelength / (double) 2);
			edges.add(coordinate.get(i).Coordinate
					+ (double) coordinate.get(i).Sidelength / (double) 2);
		}
		ArrayList<Double> difference = new ArrayList<Double>();
		for (int i = 1; i < edges.size() - 1; i++) {
			difference.add(Math.abs(edges.get(i) - edges.get(i + 1)));
		}
		for (int i = 0; i < difference.size(); i += 2) {
			if (difference.get(i) == requireside)
				count++;
			else if (difference.get(i) > requireside)
				count += 2;
		}
		System.out.println(count);
	}

	public static void main(String args[]) {
		Village v = new Village();
		v.solve();
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn

import java.util.*;


public class A
{
   public static void main(String[] args)
   {
      new A(new Scanner(System.in));
   }

   public A(Scanner in)
   {
      int n = in.nextInt();
      int t = in.nextInt();
      int tt = 2*t;

      rect[] rs = new rect[n];
      for (int i=0; i<n; i++)
         rs[i] = new rect(in.nextInt(), in.nextInt());
      
      Arrays.sort(rs);

      int res = 2;
      for (int i=1; i<n; i++)
      {
         rect a = rs[i-1];
         rect b = rs[i];
         int d = b.p-a.p;
         int dd = a.t+b.t;
         int tv = 2*d-dd;
         if (tt == tv)
            res++;
         if (tv > tt)
            res+=2;
      }
      System.out.printf("%d%n", res);
   }
}

class rect implements Comparable<rect>
{
   int p;
   int t;

   public rect(int pp, int tt)
   {
      p = pp;
      t = tt;
   }

   public int compareTo(rect rhs)
   {
      return p-rhs.p;
   }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

public class Main implements Runnable {

    class Home implements Comparable<Home> {
        @Override
        public int compareTo(Home arg0) {
            return st - arg0.st;
        }

        int st, end;
        
    }
    
    public void solve() throws IOException {
        int n = nextInt(), t = nextInt() * 2;
        Home[] h = new Home[n];
        for(int i = 0; i < n; ++i) {
            int x = nextInt() * 2, a = nextInt() * 2;
            h[i] = new Home();
            h[i].st = x - a / 2;
            h[i].end = x + a / 2;           
        }             
        Arrays.sort(h);
        int ans = 2;
        for(int i = 0; i + 1 < n; ++i) {
            int delta = h[i + 1].st - h[i].end;
            if (delta == t)
                ans++;
            if (delta > t)
                ans += 2;
        }
        pw.println(ans);
    }
    
    static final String filename = "A";
    static final boolean fromConsole = true;

    public void run() {
        try {
            if (!fromConsole) {
                in = new BufferedReader(new FileReader(filename + ".in"));
                pw = new PrintWriter(filename + ".out");
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                pw = new PrintWriter(System.out);
            }
            st = new StringTokenizer("");
            long st = System.currentTimeMillis();
            solve();            
            //pw.printf("\nWorking time: %d ms\n", System.currentTimeMillis() - st);            
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        } 
    }
    
    private StringTokenizer st;
    private BufferedReader in;
    private PrintWriter pw; 
    
    boolean hasNext() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return false;
            }
            st = new StringTokenizer(line);
        }
        return st.hasMoreTokens();
    }
    
    String next() throws IOException {
        return hasNext() ? st.nextToken() : null;
    }
    
    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    
    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }
    
    long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    
    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    
    public static void main(String[] args) {
        new Thread(new Main()).start();
    }   
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;

public class A {
	Scanner in = new Scanner(System.in);
	
	public class Houses implements Comparable<Houses>{
		double x;
		double a;
		
		public Houses(double xVal, double aVal){
			x = xVal-aVal/2;
			a = aVal;
		}

		@Override
		public int compareTo(Houses o) {
			return (int) (x - o.x);
		}	
	}
	
	public void solve2(ArrayList<Houses> list,int t){
		Collections.sort(list);
		int count = 2; //beginning and end
		
		for(int f = 0; f < list.size()-1; f++){

			if(list.get(f+1).x-list.get(f).x-list.get(f).a > t){
				count+=2;
			}
			else if(list.get(f+1).x-list.get(f).x-list.get(f).a == t){
				count++;
			}
			
		}
		
		System.out.println(count);
	}
	
	public void solve(){
		ArrayList<Houses> list = new ArrayList<Houses>();
		int n = in.nextInt();
		int t = in.nextInt();
		for(int i = 0; i < n; i++){
			list.add(new Houses(in.nextDouble(),in.nextDouble()));
		}
		
		solve2(list,t);
	}
	
	public static void main(String[] args){
		A p = new A();
		p.solve();
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.math.*;
import java.util.*;

public class Village
{
	static Scanner in = new Scanner( new BufferedReader( new InputStreamReader( System.in ) ) );

	public static void main( String[] args )
	{
		int n = in.nextInt(), t = 2*in.nextInt(), h[][] = new int[n][2], ans = 2;
		for( int i = 0; i < n; i++ )
		{
			h[i][0] = 2*in.nextInt();
			h[i][1] = in.nextInt();
		}
		Arrays.sort( h, new Comp() );
		for( int i = 1; i < n; i++ )
		{
			int d = (h[i][0]-h[i][1])-(h[i-1][0]+h[i-1][1]);
			if( d>t ) ans += 2;
			if( d==t ) ans++;
		}
		System.out.println( ans );
	}

	static class Comp implements Comparator<int[]>
	{
		public int compare( int[] a, int[] b ) { return a[0]-b[0]; }
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class A implements Runnable {
	public static void main(String[] args) {
		new A().run();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		boolean eof;
		String buf;

		public FastScanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
			nextToken();
		}

		public FastScanner(InputStream stream) {
			br = new BufferedReader(new InputStreamReader(stream));
			nextToken();
		}

		String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

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

		long nextLong() {
			return Long.parseLong(nextToken());
		}

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

		void close() {
			try {
				br.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	class House {
		int x, t;

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

	}

	void solve() {
		int n = nextInt();
		int t = nextInt();
		House[] h = new House[n];
		for (int i = 0; i < n; i++) {
			h[i] = new House(nextInt(), nextInt());
		}
		Arrays.sort(h, new Comparator<House>() {
			@Override
			public int compare(House o1, House o2) {
				return o1.x < o2.x ? -1 : o1.x > o2.x ? 1 : 0;
			}
		});
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (i == 0
					|| (h[i].x - h[i - 1].x) * 2 - h[i].t - h[i - 1].t >= 2 * t) {
				++ans;
			}
			if (i == n - 1
					|| (h[i + 1].x - h[i].x) * 2 - h[i + 1].t - h[i].t > 2 * t) {
				++ans;
			}
		}
		out.println(ans);
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.text.ChoiceFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int t = scan.nextInt();
		List<List<Double>> coords = new ArrayList<List<Double>>();
		while (n-- > 0) {
			double x = scan.nextDouble();
			double a = scan.nextDouble() / 2;
			coords.add(Arrays.asList(x - a, x + a));
		}
		Collections.sort(coords, new Comparator<List<Double>>() {
			@Override
			public int compare(List<Double> o1, List<Double> o2) {
				return o1.get(0).compareTo(o2.get(0));
			}
		});
		int count = 2;
		ChoiceFormat f = new ChoiceFormat("-1#0|0#1|0<2");
		for (int i = 0; i < coords.size()-1; i++) {
			double l = coords.get(i+1).get(0)-coords.get(i).get(1)-t;
			count += new Integer(f.format(l));
		}
		System.out.println(count);
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.lang.*;
import java.io.*;
import java.util.*;
import java.math.*;

public class Solution  implements Runnable{
    private static BufferedReader br = null;
    private static PrintWriter out = null;
    private static StringTokenizer stk = null;
    
    public static void main(String[] args) {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
       (new Thread(new Solution())).start();
    }
    
    private void loadLine() {
        try {
            stk = new StringTokenizer(br.readLine());
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    private String nextLine() {
        try {
            return br.readLine();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    private Integer nextInt() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Integer.parseInt(stk.nextToken());
    }
    
    private Long nextLong() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Long.parseLong(stk.nextToken());
    }
    
    private String nextWord() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return (stk.nextToken());
    }
    
    private Double nextDouble() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Double.parseDouble(stk.nextToken());
    }
    
    public void run() {
        int n = nextInt();
        int t = nextInt();
        
        double[] d = new double[2*n];
        for (int i = 0; i < n; ++i) {
            double x = nextDouble();
            double a = nextDouble();
            d[2*i] = x-a/2;
            d[2*i+1] = x+a/2;
        }
        
        Arrays.sort(d);
        int res = 2;
        for (int i = 1; i < 2*n-1; i+=2) {
            if (d[i+1] - d[i] >= t) {
                ++res;
            }
            if (d[i+1] - d[i] > t) {
                ++res;
            }
        }
        
        out.println(res);
        out.flush();
    }
}