CCC '13 J1 - Next in line

View as PDF

Submit solution

Points: 3
Time limit: 3.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
Canadian Computing Competition: 2013 Stage 1, Junior #1

You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.

Given the ages of the youngest and middle children, what is the age of the oldest child?

Input Specification

The input consists of two integers, each on a separate line. The first line is the age Y of the youngest child (0 \le Y \le 50). The second line is the age M of the middle child (Y \le M \le 50).

Output Specification

The output will be the age of the oldest child.

Sample Input 1

12
15

Output for Sample Input 1

18

Sample Input 2

10
10

Output for Sample Input 2

10

Comments


  • 2
    pinky_puffin  commented on Aug. 5, 2020, 6:07 p.m. edited

    banan bonjouer manoselle


  • -2
    young_boyMav1433223  commented on June 21, 2020, 1:51 p.m.

    sure


  • -2
    Henry_Z  commented on June 7, 2020, 8:46 p.m.

    For the people who just started coding like me finds this very confusing.


    • 3
      hjanday  commented on June 8, 2020, 3:21 p.m.

      It's not really a coding problem, Henry. I would say its a math puzzle and coding it should be done last. First try to see what the problem is saying, and see how those test cases relate to the problem. For example, how are 12 and 15 related and why does the test case give you an answer of 18? Think about how the answer is formed.


  • -2
    owen_  commented on June 7, 2020, 3:37 p.m.

    cool kids are like GG


    • -7
      Plasmatic  commented on June 7, 2020, 3:40 p.m.

      This comment is hidden due to too much negative feedback. Click here to view it.


  • 25
    HeidenCake  commented on Oct. 25, 2019, 12:53 p.m.

    I love coding~