logo AlgoBeat OnlineJudge
登录 注册

#213738. [NWRRC 2021] Anno Domini 2022

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Soon we will celebrate New Year 2022, but what does this number mean? As you possibly know, this dating system was invented in AD 525 by Dionysius Exiguus. He chose the birth of Jesus Christ as the starting point of the Years of Our Lord (Anno Domini in Latin, AD for short). All the years before that were counted backwards as years Before Christ (BC for short).

An interesting detail of this dating system is that there is no year 0 --- year 1 BC is immediately followed by AD 1. Because of that, sometimes it is quite tricky to find time difference between two dates if these dates belong to two different eras.

To simplify this task, please write a program that computes how many years passed between January 1st of two years given in the input.

输入格式

Two years are specified on two sequential input lines. Each year is specified in one of two forms:

  • as letters , followed by a space and a positive integer without leading zeroes in range ;
  • as a positive integer without leading zeroes in range , followed by a space and letters .

The years may be specified in arbitrary order --- the earlier year is not necessarily given first.

输出格式

The only line of the output must contain one integer: the number of years that passed between January 1st of the earlier year and January 1st of the later year.

样例

样例输入 1

1 BC
AD 1

样例输出 1

1

样例输入 2

AD 1
AD 2001

样例输出 2

2000

样例输入 3

AD 2022
5508 BC

样例输出 3

7529