Problem:
Score: 100 points

Problem Statement

We held two competitions: Coding Contest and Robot Maneuver.

In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen.

DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver.
Find the total amount of money he earned.

Constraints

1 \leq X \leq 205

1 \leq Y \leq 205

X and Y are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the amount of money DISCO-Kun earned, as an integer.

Sample Input 1

1 1

Sample Output 1

1000000

In this case, he earned 300000 yen in Coding Contest and another 300000 yen in Robot Maneuver. Furthermore, as he won both competitions, he got an additional 400000 yen.
In total, he made 300000 + 300000 + 400000 = 1000000 yen.

Sample Input 2

3 101

Sample Output 2

100000

In this case, he earned 100000 yen in Coding Contest.

Sample Input 3

4 4

Sample Output 3

0

In this case, unfortunately, he was the highest-ranked contestant without prize money in both competitions.

Solution in JavaScript (node.js v5.12) (judge verdict: Runtime Error)

'use strict';

const main = input => {
  input = inputS.trim().split('\n');
  const kukan = input[1].split(' ');

  const kukanInt = kukan.map(n => parseInt(n, 10));

  const nagasa = kukanInt.reduce((x, y) => x + y);
  const mokuhyo = nagasa / 2;

  // console.log('nagasa = ' + nagasa);
  // console.log('mokuhyo = ' + mokuhyo);

  let half = 0;
  let i = 0;

  while (half < mokuhyo) {
    half += kukanInt[i];
    i++;
  }

  let ans1 = 0;
  let ans2 = 0;

  for (let j = 0; j < i; j++) {
    ans1 += kukanInt[j];
  }
  for (let j = 0; j <= i; j++) {
    ans2 += kukanInt[j];
  }

  // console.log(ans1);
  // console.log(ans2);

  if (ans1 === half && nagasa - ans1 === half) {
    ans1 = 0;
  } else {
    ans1 = Math.abs(ans1 - nagasa);
  }

  if (ans2 === nagasa) {
    ans2 = Infinity;
  } else {
    ans2 = Math.abs(ans2 - nagasa);
  }

  if (ans1 < ans2) {
    console.log(ans1);
  } else {
    console.log(ans2);
  }
};
main(require('fs').readFileSync('/dev/stdin', 'utf8'));