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. Struts框架的使用初步

    Struts框架的使用初步: A:Apache下载struts.2.1.8.rar包. B:解压空工程,进入apps目录. C:将struts2的基本jar包拷到工程的lib目录中. D:配置web. ...

  2. 作业6:Java虚拟机类加载机制

    一.概述 1.定义 虚拟机类加载机制:把类的数据从Class文件加载进内存,并对数据作校验.转换解析和初始化,最终形成可被JVM直接使用的Java类型. 2.与C/C++的不同 Java不在编译时进行 ...

  3. Winfrom 定时锁屏

    #region 锁屏 public struct LASTINPUTINFO { [MarshalAs(UnmanagedType.U4)] public int cbSize; [MarshalAs ...

  4. 异常-throws的方式处理异常

    定义功能方法时,需要把出现的问题暴露出来让调用者去处理.那么就通过throws在方法上标识. package cn.itcast_05; import java.text.ParseException ...

  5. (๑•̀ㅂ•́)و✧QQ用户信息管理系统

    这是第二篇文章,就直接切主题 这次剖析的也是自己的作业之一:QQ信息管理系统 一:(此处省略了建Proarams类,其实目的只是想强调把连接语句单独放一个类里更容易调用,命名规范如图) 二:(导入SQ ...

  6. SQLplus命令中删除键和翻页键不能用的问题

    问题现象: 在进入连接数据库后,如何写错命令,删除键不好使,总是出现^H^H [oracle@master2 ~]$ sqlplus / as sysdba SQL*Plus: Release 12. ...

  7. ADO.net 数据库连接new SqlConnection、Open、Close、Dispose

    今天踩了一个坑,用了一个static对象,存储了Connection,导致了并发量大时(35/s)出现单个连接的数据库请求堆积,以及并发Open导致的异常,最终使服务下线. 排查中发现有些概念不清的地 ...

  8. php底层的运行机制和原理

    php设计的理念及特点 PHP 被设计为一种适用于web开发的动态脚本语言,同时具有解释型和弱类型,底层完全由C语言实现. 解释型即程序边运行边解释,一行一行运行. 弱类型即变量类型一开始并不是确定的 ...

  9. ubuntu16.04环境LNMP实现PHP5.6和PHP7.2

    最近因为公司突然间说要升级php7,所以做个记录 PPA 方式安装 php7.2 : sudo apt-get install software-properties-common 添加 php7 的 ...

  10. 3.java并发包

    1.java并发包介绍 JDK5.0 以后的版本都引入了高级并发特性,大多数的特性在java.util.concurrent 包中,是专门用于多线程并发编程的,充分利用了现代多处理器 和多核心系统的功 ...