Grandma's Footsteps

AtCoder
IDabc428_a
Time2000ms
Memory256MB
Difficulty
Takahashi is enjoying a game at school. The game starts at the moment the bell rings. Immediately after the bell rings, he repeats the following actions: * Run at a speed of $S$ meters per second for $A$ seconds. Then, remain stationary for $B$ seconds. How many meters in total does he run by the time $X$ seconds have elapsed since the bell rang? ## Constraints * $1 \leq S \leq 15$ * $1 \leq A \leq 1000$ * $1 \leq B \leq 1000$ * $1 \leq X \leq 1000$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $S$ $A$ $B$ $X$ [samples]
Samples
Input #1
7 3 2 11
Output #1
49

During the $11$ seconds after the bell rings, Takahashi moves as follows:

*   From $0$ seconds to $3$ seconds, he runs at a speed of $7$ meters per second. The distance traveled during this time is $21$ meters.
*   From $3$ seconds to $5$ seconds, he remains stationary.
*   From $5$ seconds to $8$ seconds, he runs at a speed of $7$ meters per second. The distance traveled during this time is $21$ meters.
*   From $8$ seconds to $10$ seconds, he remains stationary.
*   From $10$ seconds to $11$ seconds, he runs at a speed of $7$ meters per second. The distance traveled during this time is $7$ meters.

The total distance traveled is $49$ meters, so output $49$.
Input #2
6 3 2 9
Output #2
36

During the $9$ seconds after the bell rings, Takahashi moves as follows:

*   From $0$ seconds to $3$ seconds, he runs at a speed of $6$ meters per second. The distance traveled during this time is $18$ meters.
*   From $3$ seconds to $5$ seconds, he remains stationary.
*   From $5$ seconds to $8$ seconds, he runs at a speed of $6$ meters per second. The distance traveled during this time is $18$ meters.
*   From $8$ seconds to $9$ seconds, he remains stationary.

The total distance traveled is $36$ meters, so output $36$.
Input #3
1 1 666 428
Output #3
1

During the $428$ seconds after the bell rings, Takahashi moves as follows:

*   From $0$ seconds to $1$ second, he runs at a speed of $1$ meter per second. The distance traveled during this time is $1$ meter.
*   From $1$ second to $428$ seconds, he remains stationary.

The total distance traveled is $1$ meter, so output $1$.
API Response (JSON)
{
  "problem": {
    "name": "Grandma's Footsteps",
    "description": {
      "content": "Takahashi is enjoying a game at school. The game starts at the moment the bell rings. Immediately after the bell rings, he repeats the following actions: *   Run at a speed of $S$ meters per second f",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc428_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Takahashi is enjoying a game at school. The game starts at the moment the bell rings.\nImmediately after the bell rings, he repeats the following actions:\n\n*   Run at a speed of $S$ meters per second f...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments