Under construction

Still being built. Things may change

Tomatoes

Time limit1sMemory limit1024 MB

Summary
Given a row of n tomatoes with three initially ripe, count how many are ripe after d days of spreading to adjacent tomatoes.
Level

Easy2 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

There are nn tomatoes in a long row, numbered from 11 to nn. Three of them, numbers t1t_1, t2t_2, and t3t_3, are already ripe when the simulation starts on day 00. Every day, each unripe tomato that is directly next to a ripe tomato ripens. After day 11, the neighbors of the first three ripe tomatoes have ripened. After day 22, the neighbors of the tomatoes that ripened on day 11 have also ripened, and so on.

Write a program that, given nn, dd, and the numbers t1t_1, t2t_2, and t3t_3, computes how many tomatoes are ripe after dd days.

Input

The first line contains two integers nn (3≤n≤1003 \le n \le 100) and dd (1≤d≤1001 \le d \le 100).

The second line contains t1t_1, t2t_2, and t3t_3. They are all different and lie in the range 1…n1 \dots n.

Output

Print a single integer: the number of ripe tomatoes after dd days.

Examples1

  1. Example 1

    Input
    12 2
    4 8 5
    
    Expected output
    9