A. Sea Battle

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w1w1 and a height of h1h1, while the second rectangle has a width of w2w2 and a height of h2h2, where w1≥w2w1≥w2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field.

The rectangles are placed on field in the following way:

  • the second rectangle is on top the first rectangle;
  • they are aligned to the left, i.e. their left sides are on the same line;
  • the rectangles are adjacent to each other without a gap.

See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue.

Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1,1)(1,1), the rightmost top cell of the first rectangle has coordinates (w1,h1)(w1,h1), the leftmost bottom cell of the second rectangle has coordinates (1,h1+1)(1,h1+1) and the rightmost top cell of the second rectangle has coordinates (w2,h1+h2)(w2,h1+h2).

After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green.

Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction.

Input

Four lines contain integers w1,h1,w2w1,h1,w2 and h2h2 (1≤w1,h1,w2,h2≤1081≤w1,h1,w2,h2≤108, w1≥w2w1≥w2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles.

Output

Print exactly one integer — the number of cells, which should be marked after the ship is destroyed.

Examples

input

2 1 2 1

output

12

input

2 2 1 2

output

16

Note

In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares):

In the second example the field looks as:

题意:输入4个数,前两个数表示第一个矩阵的长和宽,后两个数表示第二个矩阵的长和宽。然后找出这两个矩阵旁边的相邻单位的数量。就像上图一样,红色代表第一个矩阵,蓝色代表第二个,首先这两个矩阵必须时相邻的,然后找出旁边绿色方块的数量。我的思路就是先算出第一个矩阵的所以相邻个数,再算出第二个矩阵的相邻个数,然后再减去它们两个共同所占据的个数。

#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std; int main()
{
int w1,w2,h1,h2;
cin>>w1>>h1>>w2>>h2;
int sum1=w1*+h1*+; //第一个矩阵相邻单位的数量,加4的意思是4个角
int sum2=w2*+h2*+; //第二个矩阵相邻单位的数量
int sum=sum1+sum2; //两个矩阵的和
sum-=min(w1,w2)*+; //减去他们共同所占据的相邻单位,找两个矩阵相邻的最小边,那里才是它们的共同占据的数量单位,这里加4的意思是减去两个矩阵分别多出的两个角
cout<<sum<<endl;
return ;
}

A. Sea Battle的更多相关文章

  1. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  2. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  3. Codeforces #380 div2 D(729D) Sea Battle

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. Sea Battle

    Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  6. Codeforces Round #380 (Div. 2)D. Sea Battle

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Sea Battle<海战>(思路题)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

  9. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. linux 阿里云 新机器 安装jdk1.8

    2019年7月17日15:58:34 按着顺序来: wget https://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4f ...

  2. element-ui 表格可编辑添加删除

    <template> <div id="Cold_all"> <div class="Cold_Left"> <el- ...

  3. Mac EI 10.11.3 MySQL5.7.11 .dmg 安装(便捷设置,密码重置,卸载)

    MySQL 5.7+ 安装成功以后会弹出一个临时密码 后面需要通过临时密码设置新的密码 重置root密码:安装成功后,使用临时密码登陆:敲入命令,mysqladmin -u root -p passw ...

  4. mysql数据库:分表、多表关联、外键约束、级联操作

    一.分表.外键.级联.多对一 二.多对多 三.一对一 一.分表.外键.级联.多对一 将部门数据与员工数据放到同一张表中会造成 数据重复 结构混乱 扩展维护性差 需要分表 create table de ...

  5. C++中虚函数的作用和虚函数的工作原理

    1 C++中虚函数的作用和多态 虚函数: 实现类的多态性 关键字:虚函数:虚函数的作用:多态性:多态公有继承:动态联编 C++中的虚函数的作用主要是实现了多态的机制.基类定义虚函数,子类可以重写该函数 ...

  6. RHEL6使用系统自带多路径软件配置多路径

    1.多路径的主要功能 多路径一般配合存储设备实现如下功能: 故障的切换和恢复  IO流量的负载均衡  磁盘的虚拟化     2.查看系统自带的多路径软件是否安装 [root@cluster01 ~]# ...

  7. Centos7 更改网卡名称

    cd /etc/sysconfig/network-scripts/ 将要改名的网卡配置文件重命名,例如 mv ifcfg-eth1 ifcfg-eth0 vim ifcfg-eth0 修改devic ...

  8. Linux之checkconfig 服务自启动

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法: chkconfig [--a ...

  9. Python:用filter函数求素数 (再理解generator)

    目的:更熟悉应用generator. 参考:https://www.liaoxuefeng.com/wiki/1016959663602400/1017404530360000 素数定义: 素数:质数 ...

  10. 【踩坑记录】 使用form标签的 reset() 方法报错原因及处理方法

    如果form标签内包含了 id 为 reset 的元素,在调用form的 reset() 方法时,会报xxx.reset is not a function,原因是在调用form的 reset() 方 ...