codeparrot/codecomplex huggingface dataset:
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Scanner;

public class P015A {

    public static void main(String[] args) {
        Scanner inScanner = new Scanner(System.in);
        int n = inScanner.nextInt();
        int t = inScanner.nextInt();
        House[] houses = new House[n];
        for (int i = 0; i < n; i++)
            houses[i] = new House(inScanner.nextInt(), inScanner.nextInt());
        Arrays.sort(houses);
        int sum = 2;
        for (int i = 1; i < n; i++) {
            double space = houses[i].leftX - houses[i - 1].rightX;
            if (space >= t)
                sum++;
            if (space > t)
                sum++;
        }
        System.out.println(sum);
    }

    private static class House implements Comparable<House> {

        int x;
        double leftX;
        double rightX;

        public House(int x, int size) {
            super();
            this.x = x;
            leftX = x - (double) size / 2;
            rightX = x + (double) size / 2;
        }

        @Override
        public int compareTo(House o) {
            return x - o.x;
        }
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.Scanner;

public class A015 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), t = in.nextInt();
		int[] centers = new int[n], sides = new int[n];
		for (int x = 0; x < n; x++) {
			centers[x] = in.nextInt();
			sides[x] = in.nextInt();
		}
		int count = 0;

		big: for (int x = -4000; x <= 4000; x++) {
			boolean touch = false;
			for (int i = 0; i < n; i++) {
				int d = 2*centers[i] - x;
				d = d > 0 ? d : -d;
				int s = t + sides[i];
				if (s == d) {
					touch = true;
				} else if (s > d) {
					continue big;
				}
			}
			if (touch)
				count++;
		}
		System.out.println(count);
	}
}
// 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 n = sc.nextInt();
        int t = sc.nextInt();
        double [] left = new double[n];
        double [] right = new double[n];
        for (int i = 0; i<n; i++){
            int x = sc.nextInt();
            int a = sc.nextInt();
            double l = x - (double)a/2;
            double r = x + (double)a/2;
            left[i] = l;
            right[i] = r;
        }
        int answer = 2;
        quickSort(left, right, 0, n-1);
        for (int i = 0; i<n-1; i++){
            if (left[i+1] - right[i] == t){
                answer++;   
            }
            if (left[i+1] - right[i] > t){
                answer += 2;
            }
        }
        System.out.println(answer);
    }
    
////////////////////////////////////////////////////////////////    
    int partition(double arr[], int left, int right)
    {
          int i = left, j = right;
          double tmp;
          double pivot = arr[(left + right) / 2];
          while (i <= j) {
                while (arr[i] < pivot)
                      i++;
                while (arr[j] > pivot)
                      j--;
                if (i <= j) {
                      tmp = arr[i];
                      arr[i] = arr[j];
                      arr[j] = tmp;
                      i++;
                      j--;
                }
          };
          return i;
    }
    void quickSort(double arr[], int left, int right) {
          int index = partition(arr, left, right);
          if (left < index - 1)
                quickSort(arr, left, index - 1);
          if (index < right)
                quickSort(arr,index, right);
    }
/////////////////////////////////////////////////////////////////////
    static int partition(double arr[], double arr2[], int left, int right)
    {
          int i = left, j = right;
          double tmp; double tmp2;
          double pivot = arr[(left + right) / 2];

          while (i <= j) {
                while (arr[i] < pivot)
                      i++;
                while (arr[j] > pivot)
                      j--;
                if (i <= j) {
                      tmp = arr[i];
                      arr[i] = arr[j];
                      arr[j] = tmp;
                      tmp2 = arr2[i];
                      arr2[i] = arr2[j];
                      arr2[j] = tmp2;
                      i++;
                      j--;
                }
          };
          return i;
    }
    static void quickSort(double arr[], double[]arr2, int left, int right) {
          int index = partition(arr, arr2, left, right);
          if (left < index - 1)
                quickSort(arr, arr2, left, index - 1);
          if (index < right)
                quickSort(arr, arr2, index, right);
    }
    ////////////////////////////////////////////////////////////////////////
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Scanner;


public class CottageVillage {
	
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int counter = 0;
			int numbCottages = scan.nextInt();
			int t = scan.nextInt();
			House[] cottages = new House[numbCottages];
			for(int i =0; i<numbCottages; i++){
				int centre = scan.nextInt();
				int length = scan.nextInt();
				double beginning = centre - ((double)length)/2;
				double end = centre + ((double)length)/2;
				cottages[i]= new House(beginning, end);
				
			}
			
			Arrays.sort(cottages);
			
			//check righthand side of first cottage
			
			/*
			if(cottages[0].end + t < cottages[1].beginning)
				counter++;
			//check lefthand side of last cottage
			
			if(cottages[numbCottages-1].beginning -t > cottages[numbCottages-2].end)
				counter++;
				
				*/
			
			for(int i =0; i<numbCottages-1; i++){
				
				if(cottages[i].end + t <= cottages[i+1].beginning){
					counter++;
//					System.out.println(counter + "left hand");
				}
				
				if (cottages[i+1].beginning - t >= cottages[i].end){
					counter++;
//					System.out.println(counter + "right hand");
				}
				
				if (Math.abs((cottages[i].end + t - cottages[i+1].beginning)) < 1e-8){
					counter--;
					
					
				}
				
	
			}
			
			System.out.println(counter+2);
			
		}
	}
	
	static class House implements Comparable<House>{
		double beginning;
		double end;
		House(double _beginning, double _end){
			beginning = _beginning;
			end = _end;
		}
		@Override
		public int compareTo(House house) {
//			if(this.beginning<house.beginning){
//				return -1;
//			}
//			else if(this.beginning==house.beginning){
//				return 0;
//			}
//			else{
//				return 1;
//			}
			return Double.valueOf(beginning).compareTo(house.beginning);
		}
		
		
	}

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


import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author epiZend
 */
public class Cottage {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        List<Point> houses = new ArrayList<Point>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int a = sc.nextInt();
            houses.add(new Point(x, a));
        }
        Collections.sort(houses, new Comparator<Point>() {
            
            @Override
            public int compare(Point o1, Point o2) {
                return ((Integer) o1.x).compareTo(o2.x);
            }
        });
        int pos = 2;
        for (int i = 0; i < n - 1; i++) {
            double end = houses.get(i).x + (houses.get(i).y+0.0)/2;
            double start = houses.get(i+1).x - (houses.get(i+1).y+0.0)/2;
            //System.out.println("end "+end+" start "+start);
            double diff = start-end;
            //System.out.println("diff");
            if (Math.abs(diff-t) < 0.0000001) {
                pos++;
            }
            if (diff > t) {
                pos += 2;
            }
        }
        System.out.println(pos);
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Solution {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    static class Pair implements Comparable<Pair> {
        int x, a;

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

        @Override
        public int compareTo(Pair o) {
            // TODO Auto-generated method stub
            return 0;
        }
    }

    boolean isCross(double l1, double r1, double l2, double r2) {
        double r = min(r1, r2);
        double l = max(l1, l2);
        return r > l;
    }

    boolean check(double xl, double xr, double[] l, double[] r, int n) {
        boolean ok = false;
        for (int j = 0; j < n; ++j)
            ok |= isCross(xl, xr, l[j], r[j]);
        return ok;
    }

    void solve() throws IOException {
        int n = ni();
        double t = ni();
        double[] l = new double[n];
        double[] r = new double[n];
        for (int i = 0; i < l.length; i++) {
            double x = ni();
            double len = ni();
            l[i] = x - len / 2.0;
            r[i] = x + len / 2.0;
        }
        HashSet<Double> set = new HashSet<Double>();
        for (int i = 0; i < n; ++i) {
            double xl = l[i] - t;
            double xr = l[i];
            boolean ok = check(xl, xr, l, r, n);
            if (!ok)
                set.add(xl);
            xl = r[i];
            xr = r[i] + t;
            ok = check(xl, xr, l, r, n);
            if (!ok)
                set.add(xl);

        }
        out.println(set.size());
    }

    public Solution() throws IOException {
        Locale.setDefault(Locale.US);
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

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

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

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

public class a {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		double w = in.nextDouble();
		int tot = 2;
		Interval[] houses = new Interval[n];
		for(int i=0; i<n; i++) {
			double center = in.nextDouble();
			double wid = in.nextDouble();
			houses[i] = new Interval(center-wid/2,center+wid/2);
		}
		Arrays.sort(houses);
		for(int i=1; i<n; i++) {
			double dist = houses[i].s - houses[i-1].e;
			if(dist+1e-6 >= w) {
				tot+=2;
				if(Math.abs(w-dist) < 1e-6)
					tot--;
			}
		}
		System.out.println(tot);
	}
}
class Interval implements Comparable<Interval> {
	double s, e;
	Interval(double a, double b) {
		s=a;
		e=b;
	}
	public int compareTo(Interval i) {
		return (int)Math.signum(s-i.s);
	}
}
// 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<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.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;
import java.util.StringTokenizer;

public class A {
    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    static class House implements Comparable<House> {
        final int x, a;

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

        public int compareTo(House h) {
            return x - h.x;
        }
    }

    void solve() throws IOException {
        int n = nextInt();
        int t = nextInt();
        House[] h = new House[n];
        for (int i = 0; i < n; ++i) {
            h[i] = new House(2 * nextInt(), nextInt());
        }
        Arrays.sort(h);
        int ans = 2;
        for (int i = 1; i < n; ++i) {
            House prev = h[i - 1];
            House curr = h[i];
            int diff = 2 * t + curr.a + prev.a;
            if (curr.x - prev.x == diff) {
                ++ans;
            } else if (curr.x - prev.x > diff) {
                ans += 2;
            }
        }
        out.println(ans);
    }

    public void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        eat("");
        solve();
        out.close();
        in.close();
    }

    void eat(String s) {
        st = new StringTokenizer(s);
    }

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            eat(line);
        }
        return st.nextToken();
    }

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

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

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

    public static void main(String[] args) throws IOException {
        new A().run();
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;


public class R015A {
    final double EPS = 1e-9;    
    boolean isEqual(double x, double y) {
        return Math.abs(x-y) <= EPS * Math.max(Math.abs(x), Math.abs(y));
    }
    class Pair implements Comparable<Pair>{
        double left;
        double right;
        Pair(double left, double right) {
            this.left = left;
            this.right = right;
        }
        public String toString() {
            return "(" + left + "," + right + ")";
        }
        public int hashCode() {
            return (int)(left * 17 + right * 31);
        }
        public boolean equals(Object o) {
            if(!(o instanceof Pair)) return false;
            Pair that = (Pair)o;
            return isEqual(this.left, that.left) && isEqual(this.right, that.right);
        }
        public int compareTo(Pair that) {
            if(this.left != that.left)
                return (int)(this.left - that.left);
            return (int)(this.right - that.right);
        }
    }
    public R015A() {
    }
    
    private void process() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int t = scanner.nextInt();
        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();
        }
        List<Pair> pairs = new ArrayList<Pair>();
        for(int i=0; i<n; i++) {
            double left = x[i] - a[i] / 2.0;
            double right= x[i] + a[i] / 2.0;
            pairs.add(new Pair(left, right));
        }
        Collections.sort(pairs);
        Set<Pair> newPairs = new HashSet<Pair>();
        newPairs.add(new Pair(pairs.get(0).left - t, pairs.get(0).left));
        for(int i=0; i<pairs.size()-1; i++) {
            if(pairs.get(i+1).left - pairs.get(i).right >= t) {
                newPairs.add(new Pair(pairs.get(i).right, pairs.get(i).right + t));
                newPairs.add(new Pair(pairs.get(i+1).left - t, pairs.get(i+1).left));
            }
        }
        newPairs.add(new Pair(pairs.get(pairs.size()-1).right, pairs.get(pairs.size()-1).right + t));
        System.out.println(newPairs.size());
    }
    
    public static void main(String[] args) {
        new R015A().process();
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class ProblemA {

    static ArrayList<Point2> houses = new ArrayList<Point2>();
    
    public static void main(String[] args) {
        ProblemA a = new ProblemA();
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt();
            double t = in.nextDouble();
            for (int k=0;k<n;k++){
                houses.add(a.new Point2(in.nextDouble(),in.nextDouble()));
            }
            Collections.sort(houses);
            int ans = 2;
            for (int k=0;k<n-1;k++){
                Point2 cur = houses.get(k);
                Point2 next = houses.get(k+1);
                double dist = (next.x - next.y/2) - (cur.x + cur.y/2);
                if (dist == t) ans ++;
                if (dist > t ) ans+=2;
            }
            System.out.println(ans);
        }
    }
    
    public class Point2 implements Comparable<Point2>{
        public double x;
        public double y;
        public Point2(double one, double two){
            x = one;
            y = two;
        }
        
        public int compareTo(Point2 other){
            if (x - other.x > 0) return 1;
            if (x - other.x < 0) return -1;
            return 0;
        }
        
        public String toString(){
            return "x:" + x + " y:" + y;
        }
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;

public class House {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		ArrayList<HS> list = new ArrayList<HS>();

		for (int i = 0; i < n; i++) {
			list.add(new HS(sc.nextInt(),sc.nextInt()));
		}
		
		Collections.sort(list);
		
		int count = 0;
		
		if(n >= 1)
			count = 2;
		
		for(int i = 0; i < list.size() - 1; i++){
			double d = Math.abs(list.get(i + 1).x - list.get(i).x);
			d -= ((1.0*list.get(i).a/2.0) + (1.0*list.get(i + 1).a/2.0));
			if ((d >= t)&& ((d-t) <= 0.00000001)){
				count++;
			}
			else if(d > t){
				count+= 2;
			} 
		}
		System.out.println(count);
	}
}

class HS implements Comparable<HS> {
	public int x;
	public int a;

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

	public int compareTo(HS o) {
		return x - o.x;
	}

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

public class Main  {
    
    Scanner in;
    PrintWriter out;
    
    static class House implements Comparable <House>{
        int len;
        int pos;
        
        House(Scanner in){
            pos = in.nextInt() * 2;
            len = in.nextInt() * 2;         
        }
        
        public int compareTo(House arg0) {
            return this.pos-arg0.pos;
        }
        
    }
            
    void solve(){
        int n = in.nextInt();
        int size = in.nextInt();
        House []h = new House[n];
        for (int i = 0; i < h.length; i++){
            h[i] = new House(in);
        }
        Arrays.sort(h);
        int ans = 2;
        for (int i = 0; i < h.length - 1; i++){
            int next = i + 1;
            int sz = h[next].pos - h[i].pos - (h[next].len + h[i].len) / 2;
            if (sz == size * 2) {
                ans ++;
            } else if (sz > size * 2) {
                ans += 2;
            }
        }
        out.println(ans);
    }
    
    public void run(){
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);
        
        try {
            solve();
        } finally {
            out.close();
        }
    }
    
    void asserT(boolean e){
        if (!e){
            throw new Error();
        }
    }

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

public class CottageVillage {
    
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();
        while (n-->0) {
            tm.put(sc.nextInt(), sc.nextInt());
        }
        
        int cnt=2, x=0, a=0; 
        double diff=0;
        for(Map.Entry<Integer, Integer> e : tm.entrySet()) {
            if (x!=0 || a!=0) {
                diff = Math.abs(e.getKey()-x-e.getValue()*0.5-a*0.5); 
                if (diff-k>0) cnt+=2;
                else if (diff-k==0) cnt++;
            }
            x=e.getKey();
            a=e.getValue();
        }
        System.out.println(cnt);
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
    StreamTokenizer in;
    PrintWriter out;
    static public void main(String[] args) throws IOException {
        new Main().run();
    }
    int ni() throws IOException {
        in.nextToken(); return (int) in.nval;
    }
    void run() throws IOException {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = ni(), t = ni();
        if(n == 0) {
            out.println(0); out.flush(); return;
        }
        House[] h = new House[n];
        for(int i = 0; i < n; i++) {
            h[i] = new House();
            h[i].x = ni(); h[i].a = ni();
        }
        Arrays.sort(h);
        int ret = 2;
        for(int i = 0; i < n - 1; i++) {
            if(2*(h[i + 1].x - h[i].x) - h[i].a - h[i + 1].a > 2*t) ret+=2;
            else if(2*(h[i + 1].x - h[i].x) - h[i].a - h[i + 1].a == 2*t) ret++;
        }
        out.println(ret);

        out.flush();
    }
    void run1() throws IOException {
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            out = new PrintWriter(new OutputStreamWriter(System.out));

            int t = ni();
            long n = ni(), m = ni();
            long x1 = ni(), y1 = ni(), x2 = ni(), y2 = ni();
        long tx1 = Math.min(x1, x2), tx2 = x1 + x2 - tx1;
        long ty1 = Math.min(y1, y2), ty2 = y1 + y2 - ty1;
        long dx = tx2 - tx1;
        long dy = ty2 - ty1;
        
    }

    class House implements Comparable<House> {
        int x, a;
        public int compareTo(House h) {
            return x < h.x ? -1 : 1;
        }
    }
}