codeparrot/codecomplex huggingface dataset:
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class A {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        // int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(bf.readLine());
        int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        int ans = 2;
        for(int i=0; i<n-1; i++) {
          int diff = a[i+1]-a[i];
          if(diff == 2*d) ans++;
          else if(diff > 2*d) ans += 2;

        }
        System.out.println(ans);
        // int n = scan.nextInt();

        // out.close(); System.exit(0);
    }
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.math.BigDecimal;

public class Main {

    static class Task {

        void solve(int test, FastScanner in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int d = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            Arrays.sort(a);

            int ans = 2;
            for (int i = 0; i < n - 1; i++) {
                if (a[i + 1] - d > a[i] + d) {
                    ans += 2;
                } else if (a[i + 1] - d >= a[i] + d) {
                    ans++;
                }
            }

            out.println(ans);
        }
    }

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        FastScanner in = new FastScanner("input.txt");
//        PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
        new Task().solve(1, in, out);
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer token;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return token.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class A {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		int d = nextInt();
		int[]x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = nextInt();
		}
		int ans = 2;
		for (int i = 1; i < n; i++) {
			if (x[i]-x[i-1]==2*d)
				ans++;
			else if (x[i]-x[i-1] > 2*d)
				ans += 2;
		}
		System.out.println(ans);
		pw.close();
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int d = in.nextInt();
      Set<Integer> pts = new HashSet<>();
      int[] x = in.nextIntArray(n);
      for (int i = 0; i < n; i++) {
        pts.add(x[i] - d);
        pts.add(x[i] + d);
      }
      Set<Integer> ans = new HashSet<>();
      for (int pt : pts) {
        int min = (int) (1e9 + 10);
        for (int i = 0; i < n; i++) {
          min = Math.min(Math.abs(x[i] - pt), min);
        }
        if (min >= d) {
          ans.add(pt);
        }
      }
      out.println(ans.size());
    }

  }

  static class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 13];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (this.numChars == -1) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return -1;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {
      }

      byte sgn = 1;
      if (c == 45) {
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) {
        res *= 10;
        res += c - 48;
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    public static boolean isSpaceChar(int c) {
      return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
    }

    public int[] nextIntArray(int n) {
      int[] arr = new int[n];
      for (int i = 0; i < n; i++) {
        arr[i] = nextInt();
      }
      return arr;
    }

  }
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
//package CodeforcesJava;

import java.io.*;
import java.util.*;

public class Main {

    public void solve(InputProvider input, PrintWriter output) throws IOException {
        int n = input.nextInt();
        int d = input.nextInt();
        int count = 1;
        int current = input.nextInt();
        for (int i = 1; i < n; i++) {
            int x = input.nextInt();
            if (x - current == d * 2) {
                count++;
            } else if (x - current > d * 2) {
                count += 2;
            }
            current = x;
        }
        count++;
        output.print(count);
    }

    public static void main(String[] args) throws Exception {
        try (InputProvider input = new InputProvider(System.in);
             PrintWriter output = new PrintWriter(System.out)) {
            new Main().solve(input, output);
        }
    }

    public static class InputProvider implements AutoCloseable {

        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputProvider(Reader reader) {
            this.reader = new BufferedReader(reader);
        }

        public InputProvider(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input));
        }

        public String next() throws IOException {
            if (Objects.isNull(tokenizer) || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }

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

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

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

        public String nextLine() throws IOException {
            return reader.readLine();
        }

        @Override
        public void close() throws Exception {
            reader.close();
        }

    }

}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.*;
import java.util.*;


public class A {
	public static boolean ok(int []x,int d,int X)
	{
		for(int i=0;i<x.length;i++)
			if(Math.abs(x[i]-X)<d)
				return false;
		return true;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int ans=0;
		int n=sc.nextInt(),d=sc.nextInt();
		TreeSet<Integer> set=new TreeSet();
		int []x=new int [n];
		for(int i=0;i<n;i++)
			x[i]=sc.nextInt();
		for(int i=0;i<n;i++)
		{
			int x1=x[i]+d;
			if (ok(x,d,x1))
				set.add(x1);
			x1=x[i]-d;
			if (ok(x,d,x1))
				set.add(x1);
			
			
		}
		pw.println(set.size());
			
		
		pw.close();
		
	}
	
	
	static class Scanner
	{
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}
	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	public Scanner(String s) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(s));
	}
	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

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

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public boolean ready() throws IOException {
		return br.ready();
	}
}
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class AA {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int d =sc.nextInt();
		int[] hotels = new int[n];
		for (int i = 0; i < hotels.length; i++) {
			hotels[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < hotels.length-1; i++) {
			int one = hotels[i];
			int two = hotels[i+1];
			double mid = (two-one)*1.0/2.0;
			if(mid==d) {
				count++;
//				System.out.println("hello"+" "+i+" "+(i+1));
			}
			else if(mid>d) {
//				System.out.println("hello2"+" "+i+" "+(i+1));
				count+=2;
				
			}
			
		}
		count+=2;
		System.out.println(count);
		
		
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}//19 91 991 919 199

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

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */
public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ASonyaAndHotels solver = new ASonyaAndHotels();
        solver.solve(1, in, out);
        out.close();
    }

    static class ASonyaAndHotels {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int d = in.scanInt();
            int[] ar = new int[n];
            int ans = 2;
            for (int i = 0; i < n; i++) ar[i] = in.scanInt();
            for (int i = 0; i < n - 1; i++) {
                if (ar[i + 1] - ar[i] == 2 * d) ans++;
                else if (ar[i + 1] - ar[i] > 2 * d) ans += 2;
            }
            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.util.Scanner;

public class R495A {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(), k=scan.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++) a[i]=scan.nextInt();
		int res=2;
		for(int i=0;i<n-1;i++) {
			if(a[i+1]-a[i]>2*k) res+=2;
			else if(a[i+1]-a[i]==2*k) res++;
		}
		System.out.println(res);
	}
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.*;
import java.util.*;

public class A implements Runnable{
	public static void main (String[] args) {new Thread(null, new A(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int n = fs.nextInt();
		int d = fs.nextInt();
		int[] a = fs.nextIntArray(n);
		sort(a);
		long res = 0;
		if(n == 1) {
			System.out.println(2);
			return;
		}

		HashSet<Integer> set = new HashSet<>();
		for(int i = 0; i < n; i++) {
			int one = a[i] - d;
			int min = Integer.MAX_VALUE;
			for(int j = 0; j < n; j++) {
				int dist = Math.abs(a[j] - one);
				min = Math.min(min, dist);
			}
			if(min == d) set.add(one);
			one = a[i] + d;
			min = Integer.MAX_VALUE;
			for(int j = 0; j < n; j++) {
				int dist = Math.abs(a[j] - one);
				min = Math.min(min, dist);
			}
			if(min == d) set.add(one);
		}
		System.out.println(set.size());
		out.close();
	}

	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 50; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.util.Arrays;
import java.util.Scanner;

public class SonyaAndHotels {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[] locs = new int[n];
        for (int i = 0; i < n; i++) {
            locs[i] = sc.nextInt();
        }
        Arrays.sort(locs);
        int count = 2;
        for (int i = 0; i < locs.length-1; i++) {
            if(locs[i+1]-locs[i]==2*d){
                count++;
            }else if(locs[i+1]-locs[i]>2*d){
                count+=2;
            }
        }
        System.out.println(count);
    }
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.util.Arrays;
import java.util.Scanner;

public class CF495A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long d = s.nextLong();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        Arrays.sort(arr);
        long ans  = 2;
        for (int i = 0; i < n - 1; i++) {
            if(arr[i + 1] - arr[i] > 2 * d){
                ans += 2;
            }else if(arr[i + 1] - arr[i] == 2 * d){
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}
// Problem: 1004_A. Sonya and Hotels
// Time complexity: linear
import java.io.*;
import java.util.*;
public class A {
    public static void main(String[] args)throws Throwable {
        MyScanner sc=new MyScanner();
        PrintWriter pw=new PrintWriter(System.out);

        int n=sc.nextInt();
        int d=sc.nextInt();
        int [] a=new int [n];
        for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
        int ans=2;
        for(int i=0;i<n-1;i++){
            if(a[i+1]-a[i]<2*d)
                continue;
            if(a[i+1]-a[i]==2*d)
                ans++;
            else
                ans+=2;
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {while (st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch (IOException e) {e.printStackTrace();}}
            return st.nextToken();}
        int nextInt() {return Integer.parseInt(next());}
        long nextLong() {return Long.parseLong(next());}
        double nextDouble() {return Double.parseDouble(next());}
        String nextLine(){String str = "";
            try {str = br.readLine();}
            catch (IOException e) {e.printStackTrace();}
            return str;}
    }
}