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

public class Solution {
    static class Cottage implements Comparable<Cottage> {
        public int x;
        public double a;

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

        public int compareTo(Cottage c) {
            return x - c.x;
        }
    }

    static final double e = 1e-9;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int t = in.nextInt();
        Cottage[] cottages = new Cottage[n];

        for (int i = 0; i < n; i++)
            cottages[i] = new Cottage(in.nextInt(), in.nextInt());

        Arrays.sort(cottages);

        int ans = 2;

        for (int i = 1; i < cottages.length; i++) {
            double diff = cottages[i].x - cottages[i - 1].x - cottages[i - 1].a / 2 - cottages[i].a / 2;
            ans = Math.abs(diff - t) < e ? ans + 1 : diff - t < -e ? ans : ans + 2;
        }

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

/**
 * Created by HREN_VAM.
 */

public class A implements Runnable{

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;
    public static final String filename = "a";

    class I implements Comparable<I>{

        int x;
        int a;

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

        public int compareTo(I o){
            return Double.compare(x, o.x);
        }
    }

    public void solve() throws IOException{
        int n = nextInt();
        int t = nextInt();

        I[] a = new I[n];

        for(int i = 0;i < n;i ++){
            a[i] = new I(nextInt(), nextInt());
        }

        int res = 2;

        Arrays.sort(a);
        for(int i = 1;i < n;i ++){
            if((a[i].x - a[i - 1].x - 1.0 * (a[i].a + a[i - 1].a) / 2) >= t)res ++;
            if((a[i].x - a[i - 1].x - 1.0 * (a[i].a + a[i - 1].a) / 2) > t)res ++;
        }
        out.println(res);
    }

    public void run(){
        try{
            Locale.setDefault(Locale.US);
            in = new BufferedReader(new InputStreamReader(System.in));
            //in = new BufferedReader(new FileReader(filename + ".in"));
            out = new PrintWriter(System.out);
            //out = new PrintWriter(new FileWriter(filename + ".out"));
            st = new StringTokenizer("");
            solve();
            out.close();
        } catch(IOException e){
            throw new RuntimeException(e);
        }
    }

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

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

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

    public double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class Main implements Runnable {
    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer st;
    
    private void eat(String line)
    {
        st = new StringTokenizer(line);
    }
    
    private String next() throws IOException
    {
        while(!st.hasMoreTokens()) {
            String line = in.readLine();
            if(line == null)
                return null;
            eat(line);
        }
        return st.nextToken();
    }
    
    private int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }
    
    public void run()
    {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            eat("");
            
            go();
            
            out.close();
        } catch(Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
    
    public static void main(String[] args)
    {
        new Thread(new Main()).start();
    }
    
    public void go() throws IOException
    {
        int n = nextInt(), t = nextInt();
        int[] x = new int[n], a = new int[n];
        for(int i = 0; i < n; ++i) {
            x[i] = nextInt();
            a[i] = nextInt();
        }
        out.println(new Algo().solve(n, t, x, a));
    }
}

final class Algo {
    public int solve(int n, int t, final int[] x, final int[] a)
    {
        Integer[] order = new Integer[n];
        for(int i = 0; i < n; ++i)
            order[i] = i;
        Arrays.sort(order, new Comparator<Integer>() {
            public int compare(Integer a, Integer b)
            {
                return x[a] - x[b];
            }
        });
        int result = 2;
        for(int i = 0; i + 1 < n; ++i) {
            int u = order[i], v = order[i + 1];
            int dist = 2 * (x[v] - x[u]) - (a[v] + a[u]);
            if(dist > 2 * t)
                result += 2;
            else if(dist == 2 * t)
                ++result;
        }
        return result;
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;

public class Village{
	static class House implements Comparable<House>{
		public double center, length;

		public House(double center, double  length){
			this.center = center;
			this.length = length;
		}
		public double getRight(){
			return center + length/2;
		}
		public double getLeft(){
			return center - length/2;
		}
		public int compareTo(House h){
			return this.center < h.center ? -1 : this.center == h.center ? 0 : 1;
		}

	}
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String[] fline = in.nextLine().split("\\s+");
		int N = Integer.parseInt(fline[0]);
		int T = Integer.parseInt(fline[1]);

		House[] houses = new House[N];
		for (int i = 0; i < N; i++){
			String[] house = in.nextLine().split("\\s+");
			houses[i] = new House(Double.parseDouble(house[0]), Double.parseDouble(house[1]));
		}
		Arrays.sort(houses);
		int count = 2;
		for (int i = 0; i < houses.length - 1; i++){
			//how many positions between house i and house i + 1 can we fit in?
			double diff = houses[i+1].getLeft() - houses[i].getRight();
			if (diff < T) continue;
			if (Math.abs(diff - T) < 1E-12) count++;
			else count+=2;
		}
		System.out.println(count);
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	
	public Main() {
		super();
	}
	
	public static void main(String... args) {
		Main main = new Main();
		main.start();
	}
	
	
	public void start() {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int t = in.nextInt();
		House list[] = new House[n];
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			int a = in.nextInt();
			list[i] = new House(x, a);
		}
		Arrays.sort(list);
		int c = 2;
		for (int i = 1; i < n; i++) {
			float d = list[i].left - list[i - 1].right;
			if (d == t) c++;
			else if (d > t) c += 2;
		}
		System.out.println(c);
	}
}


class House implements Comparable<House> {
	public int x;
	public float left, right;
	public House(int x, int a) {
		this.x = x;
		float h = a / 2f;
		this.left = x - h;
		this.right = x + h;
	}
	
	public int compareTo(House h) {
		return this.x == h.x ? 0 : this.x < h.x ? -1 : 1;
	}
	
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.*;
import java.awt.*;

public class A
{
	static Comparator<Point> cmp = new Comparator<Point>()
	{
		public int compare(Point a, Point b)
		{
			if(a.x < b.x)
				return -1;
			else if(a.x > b.x)
				return 1;

			return 0;
		}
	};

	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);

		while(scan.hasNextInt())
		{

		int n = scan.nextInt();
		int k = scan.nextInt();

		Point[] a = new Point[n];

		for(int i=0;i < n;i++)
		{
			a[i] = new Point();
			a[i].x = scan.nextInt();
			a[i].y = scan.nextInt();
		}

		Arrays.sort(a, cmp);

		int rtn = 0;

		ArrayList<Double> ans = new ArrayList<Double>();

		for(int i=0;i < n;i++)
		{
			//Left
			double lb = a[i].x - (a[i].y / 2.0) - k;
			double pos = lb + (k/2.0);
			boolean good = true;

			for(int j=0;j < ans.size();j++)
				if(Math.abs(ans.get(j) - pos) < 0.0000001)
					good = false;


			if(good && (i == 0 || a[i-1].x + (a[i-1].y / 2.0) <= lb))
			{
				rtn++;
				ans.add(pos);
			}

			double rb = a[i].x + (a[i].y / 2.0) + k;
			pos = rb - (k/2.0);
			good = true;

			for(int j=0;j < ans.size();j++)
				if(Math.abs(ans.get(j) - pos) < 0.0000001)
					good = false;

			if(good && (i == n-1 || a[i+1].x - (a[i+1].y / 2.0) >= rb))
			{
				rtn++;
				ans.add(pos);
			}
		}

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

public class Main implements Runnable {
	
	class Segment {
		int l, r;
		Segment(int l, int r) {
			this.l = l;
			this.r = r;
		}
		@Override
		public boolean equals(Object obj) {
			Segment o = (Segment)obj;
			return l == o.l && r == o.r;
		}
		@Override
		public int hashCode() {
			return 1000 * l + r;
		}
	}

	public void _main() throws IOException {
		int n = nextInt();
		int t = nextInt();
		int[] x = new int[n];
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = nextInt();
			a[i] = nextInt();
		}		
		Set<Segment> set = new HashSet<Segment>();
		for (int i = 0; i < n; i++) {
			int l = 2 * x[i] + a[i];
			int r = 2 * x[i] + a[i] + 2 * t;
			boolean ok = true;
			for (int j = 0; j < n; j++) {
				if (i == j) continue;
				int L = Math.max(l, 2 * x[j] - a[j]);
				int R = Math.min(r, 2 * x[j] + a[j]);				
				if (L < R) {
					ok = false;
					break;
				}
			}
			if (ok)
				set.add(new Segment(l, r));
			
			l = 2 * x[i] - a[i] - 2 * t;
			r = 2 * x[i] - a[i];			
			ok = true;
			for (int j = 0; j < n; j++) {
				if (i == j) continue;
				int L = Math.max(l, 2 * x[j] - a[j]);
				int R = Math.min(r, 2 * x[j] + a[j]);
				if (L < R) {
					ok = false;
					break;
				}
			}
			if (ok)
				set.add(new Segment(l, r));
		}
		out.print(set.size());
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

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

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

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

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

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

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

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

public class test 
{  
    public static void main(String[] args) 
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int t=in.nextInt();
        
        House[] houses=new House[n];
        
        for(int i=0;i<n;i++)
        {
            houses[i]=new House(in.nextInt(),in.nextInt());
        }
        
        Arrays.sort(houses);
        
        int count=2;
        
        for(int i=0;i<n-1;i++)
        {
            double start=houses[i].x+(double)houses[i].a/2;
            double end=houses[i+1].x-(double)houses[i+1].a/2;
            
            if(end-start==t)
        	count++;
            if(end-start>t)
        	count+=2;
        }
        
        System.out.println(count);
 
    }
}

class House implements Comparable<House>
{
    int x;
    int a;
    
    public House(int _x, int _a)
    {
	x=_x;
	a=_a;
    }

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

/**
 * @author Alexander Grigoryev
 *         Created on 28.07.2011
 */
public
class Main {
    static Scanner in = new Scanner(System.in);

    public static
    void main(String[] args) {
        int n = in.nextInt();
        int t = in.nextInt();

        List<Integer> v = new ArrayList<Integer>(n);
        for(int i = 0; i < n; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            v.add(2 * a - b);
            v.add(2 * a + b);
        }
        Collections.sort(v);
        int ans = 2;
        for(int i = 2; i < v.size(); i += 2) {
            if(v.get(i) - v.get(i - 1) > 2 * t) ans += 2;
            if(v.get(i) - v.get(i - 1) == 2 * t) ans++;
        }
        System.out.println(ans);
    }
}
// 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;
			else 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.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author burdakovd
 * 
 */
public class A {

	static class House {
		int x, a;
	}

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

		try {
			final int n = in.nextInt();
			final int t = in.nextInt();

			final House[] h = new House[n];
			for (int i = 0; i < h.length; ++i) {
				h[i] = new House();
				h[i].x = in.nextInt();
				h[i].a = in.nextInt();
			}

			Arrays.sort(h, new Comparator<House>() {

				@Override
				public int compare(final House o1, final House o2) {
					return Integer.valueOf(o1.x).compareTo(o2.x);
				}
			});

			int ans = 2;
			for (int i = 1; i < n; ++i) {
				final int dspace = 2 * h[i].x - h[i].a
						- (2 * h[i - 1].x + h[i - 1].a);
				if (dspace == 2 * t) {
					++ans;
				} else if (dspace > 2 * t) {
					ans += 2;
				}
			}

			out.println(ans);

		} finally {
			in.close();
			out.close();
		}
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Comparator;


public class Main {
	private static StreamTokenizer in;
	private static PrintWriter out;
	
	private static int nextInt() throws Exception {
		in.nextToken();
		return (int)in.nval;
	}
	
	private static String nextString() throws Exception {
		in.nextToken();
		return in.sval;
	}
	
	public static void main(String[] args) throws Exception {
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		out = new PrintWriter(System.out);
		
		int n = nextInt(), t = nextInt() * 2;
		int[][] a = new int[n][2];
		for (int i=0; i<n; i++) {
			a[i][0] = nextInt() * 2;
			a[i][1] = nextInt() * 2;
		}
		
		Arrays.sort(a, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0]>b[0]?1:a[1]<b[1]?-1:0;
			}
		});
		
		int s = 2;
		
		for (int i=0; i<n-1; i++) {
			int g = (a[i+1][0]-a[i][0])-(a[i+1][1]+a[i][1])/2;
			if (g > t) s += 2;
			if (g == t) s+= 1;
		}
		out.println(s);
		
		
		out.flush();
	}
}
// 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.Collections;

public class A {
	
	public static void main(String[] args) {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			
			String[] s = in.readLine().split(" ");
			int n = Integer.parseInt(s[0]);
			int t = Integer.parseInt(s[1]) * 2;
			
			int[] walls = new int[n*2]; 
			
			for (int i=0; i<n; i++)
			{
				s = in.readLine().split(" ");
				int x = Integer.parseInt(s[0]) * 2;
				int a = Integer.parseInt(s[1]);
				walls[i*2] = x-a;
				walls[i*2+1] = x+a;
			}
			
			Arrays.sort(walls);
			
			int count = 2;
			
			for (int i=1; i<n*2-2; i+=2) {
				int space = walls[i+1] - walls[i]; 
				if ( space == t)
					count += 1;
				else if ( space > t)
					count += 2;
			}
			
			System.out.println (count);

		} catch (NumberFormatException e) {
			throw new RuntimeException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}

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

public class village {
    static int[] X, A;
    public void solve()
    {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), T = in.nextInt();
        X = new int[N];
        A = new int[N];

        for(int i = 0; i < N; i++) {
            X[i] = in.nextInt(); A[i] = in.nextInt();
        }

        if(N == 1) {
            System.out.println("2");
            return; 
        }

        List<Integer> x = new ArrayList<Integer>();
        for(int i = 0; i < N; i++) {
            x.add(i);
        }

        Collections.sort(x, new Comp());

        int places = 0;
        for(int i = 0; i < N-1; i++) {
            double space = (X[x.get(i+1)]-X[x.get(i)]-A[x.get(i+1)]/2.0-A[x.get(i)]/2.0);
            if(space < T) {
                continue;
            } if(space - T < 1e-9) {
                places++;
            } else if(space > T) {
                places+=2;
            }
        }
        System.out.println(places+2);
    }

    public class Comp implements Comparator<Integer> {
            public int compare(Integer i1, Integer i2) {
                return X[i1]-X[i2];
            }
    }

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

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

public class A implements Runnable
{
	public static void main(String [] args) throws IOException
	{
		new Thread(null, new A(), "", 1 << 20).start();
	}
	
	String file = "input";
	BufferedReader input;
	PrintWriter out;
	
	public void run() 
	{
		try
		{
			//input = new BufferedReader(new FileReader(file + ".in"));
			input = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new BufferedOutputStream(System.out));
			solve();
			input.close();
			out.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
	int N, T;
	void solve() throws IOException
	{
		StringTokenizer st = tokens();
		N = nextInt(st); T = nextInt(st);
		T *= 2;
		ArrayList<Pair> list = new ArrayList<Pair>();
		for(int i = 0; i < N; i++)
		{
			st = tokens();
			int c = nextInt(st), L = nextInt(st);
			c *= 2; L *= 2;
			list.add(new Pair(c - L / 2, c + L / 2));
		}
		Collections.sort(list);
		HashSet<Integer> set = new HashSet<Integer>();
		for(int i = 0; i < list.size(); i++)
		{
			if(i == 0 || list.get(i).x - list.get(i - 1).y >= T)
			{
				set.add(list.get(i).x - T / 2);
			}
			if(i == list.size() - 1 || list.get(i + 1).x - list.get(i).y >= T)
			{
				set.add(list.get(i).y + T / 2);
			}
		}
		System.out.println(set.size());
	}
	class Pair implements Comparable<Pair>
	{
		int x, y;
		public Pair(int x, int y)
		{
			this.x = x;
			this.y = y;
		}
		public int compareTo(Pair p)
		{
			if(x != p.x) return x - p.x;
			return y - p.y;
		}
	}

	StringTokenizer tokens() throws IOException
	{
		return new StringTokenizer(input.readLine());
	}
	
	String next(StringTokenizer st)
	{
		return st.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(input.readLine());
	}
	
	int nextInt(StringTokenizer st)
	{
		return Integer.parseInt(st.nextToken());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(input.readLine());
	}
	
	double nextDouble(StringTokenizer st)
	{
		return Double.parseDouble(st.nextToken());
	}
	
	void print(Object... o)
	{
		out.println(deepToString(o));
	}
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Scanner;


public class A {
    static class Sort implements Comparable<Sort> {
        int x,a;
        public int compareTo(Sort o) {
            if (this.x==o.x)
                return this.a-o.a;
            return this.x-o.x;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        Sort[]a = new Sort[n];
        for (int i = 0; i < n; i++) {
            a[i] = new Sort();
            a[i].x = sc.nextInt();
            a[i].a = sc.nextInt();
        }
        Arrays.sort(a);
        int ans = 2;
        for (int i = 1; i < n; i++) {
            double d = a[i].x-a[i].a / 2.0-a[i-1].x-a[i-1].a / 2.0;
            if (d==t)
                ans++;
            else if (d > t)
                ans += 2;
        }
        System.out.println(ans);
    }
}
// Problem: 15_A. Cottage Village
// Time complexity: nlogn
import java.security.KeyException;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeMap;

public class P15A
{
    public static void main (String [] args)
    {

        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt(), t = scan.nextInt();

        TreeMap<Integer,Integer> hm = new TreeMap<Integer, Integer>();

        for (int i = 0; i < n; i++) hm.put(scan.nextInt(),scan.nextInt());

        int _x = 0, _a = 0, res = 2;

        boolean started = false;

        for (Integer key : hm.keySet())
        {

            if (!started)
            {
                _x = key;
                _a = hm.get(_x);
                started = true;
                continue;
            }

            if (key - _x - ((Integer)hm.get(key) + _a)/2.0 > t) res +=2;
            else if (key - _x - ((Integer)hm.get(key) + _a)/2.0 == t) res++;

            _x = key;
            _a = hm.get(_x);

        }

        System.out.println(res);


    }

}