Problem:
Score : 100 points

Problem Statement

There are two buttons, one of size A and one of size B.

When you press a button of size X, you get X coins and the size of that button decreases by 1.

You will press a button twice. Here, you can press the same button twice, or press both buttons once.

At most how many coins can you get?

Constraints

All values in input are integers.

3 \leq A, B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of coins you can get.

Sample Input 1

5 3

Sample Output 1

9

You can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this is the maximum result.

Sample Input 2

3 4

Sample Output 2

7

Sample Input 3

6 6

Sample Output 3

12

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
	class Program4
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ');
			var s = Console.ReadLine();

			List<KeyValuePair<int, int>> numlist = new List<KeyValuePair<int, int>>();

			int k = int.Parse(nk[1]);
			int addk = 0;
			int max = 0;
			int ans = 0;
			int num = 0;
			for (int i = 0; i < s.Length; i++)
			{
				num++;
				bool b = true;
				if (s[i].Equals('1'))
				{
					b = true;
				}
				else
				{
					b = false;
				}

				if (i + 1 < s.Length && s[i].Equals(s[i + 1]))
				{
					continue;
				}

				// これは1が続いた
				if (b)
				{
					numlist.Add(new KeyValuePair<int, int>(1, num));
					ans += num;
					if (ans > max)
					{
						max = ans;
					}
				}
				// ここは0が続いた
				else
				{
					// 0が続いた場合はkを使って裏返す
					if (addk < k)
					{
						addk++;
						numlist.Add(new KeyValuePair<int, int>(0, num));
						ans += num;
						if (ans > max)
						{
							max = ans;
						}
					}
					else
					{
						numlist.Add(new KeyValuePair<int, int>(0, num));
						ans += num;

						// 既にk回裏返している場合はnumlistから0を削除する必要がある
						if (numlist[0].Key == 0)
						{
							ans -= numlist[0].Value;
							numlist.RemoveAt(0);
						}
						else
						{
							ans -= numlist[0].Value;
							ans -= numlist[1].Value;
							numlist.RemoveAt(0);
							numlist.RemoveAt(0);
						}
						if (ans > max)
						{
							max = ans;
						}
					}
				}

				num = 0;
			}

			Console.Write(max.ToString() + "\n");
			//Console.ReadLine();
		}
	}
}