// inputに入力データ全体が入る
function Main(input) {
	var input = input.split('\n')
	var N = parseInt(input[0])
	var d = input.slice(1)
	d = d.map(function (x) {
	    return parseInt(x, 10);
	});

	//10, 9, 8...
	d.sort(function(a,b){
        if( a < b ) return 1;
        if( a > b ) return -1;
        return 0;
	});

	var lastMochi = d[0],
		c = 1
	for(var i = 1; i < d.length; i++) {
		var mochi = d[i]
		if(mochi < lastMochi) c++
		else break
	}

	console.log("" + c)
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();

  return ~~(48-intShift());
}

// If you are interested in the algorithms I used,
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
7
50
30
50
100
50
80
30
`);

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?

Constraints

1≤M≤23

M is an integer.

Input

Input is given from Standard Input in the following format:

M

Output

If we have x hours until New Year at M o'clock on 30th, December, print x.

Sample Input 1

21

Sample Output 1

27

We have 27 hours until New Year at 21 o'clock on 30th, December.

Sample Input 2

12

Sample Output 2

36

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


function Main (input) {
  input = input.split("\n");
  input[0] = input[0].split(" ");
  var A = input[0][0];
  var B = input[0][1];
  var S = input[1];
  var ans = "No";
  if (S.split("")[A] == "-" && S.split("-")[0].length == A && S.split("-")[1].length == B) {
    ans = "Yes";
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.

You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.

Constraints

1≤A,B≤5

|S|=A+B+1

S consists of - and digits from 0 through 9.

Input

Input is given from Standard Input in the following format:

A B
S

Output

Print Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise.

Sample Input 1

3 4
269-6650

Sample Output 1

Yes

The (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format.

Sample Input 2

1 1
---

Sample Output 2

No

S contains unnecessary -s other than the (A+1)-th character, so it does not follow the format.

Sample Input 3

1 2
7444

Sample Output 3

No


((input) => {
    const lines = input.split("\n");
    const [A, B] = lines[0].split(" ").map(x => x | 0);
    const S = lines[1];

    console.log(S.match(new RegExp("\\d{" + A +"}-\\d{" + B + "}")))
})(require("fs").readFileSync("/dev/stdin", "utf8"));
//})(``);


module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(3).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,e,t){function n(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var o=t(2);r.exports=function(r){for(var e=o(1e5),t=new Array(100001).fill(0),u=3;u<1e5;u++)t[u]=t[u-1],1==e[u]&&1==e[(u+1)/2]&&(t[u]+=1);for(var i=Number(r[0]),f=0;f<i;f++){var l=n(r[f+1].split(" ").map(function(r){return Number(r)}),2),a=l[0],c=t[l[1]]-t[a-1];console.log(c)}}},function(r,e,t){"use strict";r.exports=function(r){var e=new Array(r+1).fill(1);e[0]=0,e[1]=0;for(var t=Math.ceil(Math.sqrt(r)),n=2;n<t;n++)if(0!=e[n])for(var o=n;o<=r;)e[o+=n]=0;return e}},function(r,e){r.exports=require("fs")}]);

Score : 400 points

Problem Statement

We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.

You are given Q queries.

In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

Constraints

1≤Q≤10^5

1≤l_i≤r_i≤10^5

l_i and r_i are odd.

All input values are integers.

Input

Input is given from Standard Input in the following format:

Q
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.

Sample Input 1

1
3 7

Sample Output 1

2

3 is similar to 2017, since both 3 and (3+1)/2=2 are prime.

5 is similar to 2017, since both 5 and (5+1)/2=3 are prime.

7 is not similar to 2017, since (7+1)/2=4 is not prime, although 7 is prime.

Thus, the response to the first query should be 2.

Sample Input 2

4
13 13
7 11
7 11
2017 2017

Sample Output 2

1
0
0
1

Note that 2017 is also similar to 2017.

Sample Input 3

6
1 53
13 91
37 55
19 51
73 91
13 49

Sample Output 3

4
4
1
1
1
2


(function(){
'use strict';
function Main(input) {
  input = input.split("\n");
  var a = parseInt(input[0] + [1]);
  var b = parseInt(input[2] + [3]);
  if (a > b) {
    result = 'Left';
  } else if (b > a) {
    result = 'Right';
  } else if (b = a) {
    result = 'Balanced';
  }
  console.log(result);
}
})();

Score : 100 points

Problem Statement

A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.

Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

Constraints

1\leq A,B,C,D \leq 10

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

Sample Input 1

3 8 7 1

Sample Output 1

Left

The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left.

Sample Input 2

3 4 5 2

Sample Output 2

Balanced

The total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.

Sample Input 3

1 7 6 4

Sample Output 3

Right

The total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.


function main(input) {
  let args = input.split(/\n|\s/);
  console.log(Math.ceil((args[0] * 1 + args[1] * 1) / 2));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

You are given two positive integers a and b.
Let x be the average of a and b.
Print x rounded up to the nearest integer.

Constraints

a and b are integers.

1 \leq a, b \leq 100

Input

Input is given from Standard Input in the following format:

a b

Output

Print x rounded up to the nearest integer.

Sample Input 1

1 3

Sample Output 1

2

The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.

Sample Input 2

7 4

Sample Output 2

6

The average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.

Sample Input 3

5 5

Sample Output 3

5


function Main(input) {
	input = input.split("\n");

	var s = input[0];
	var t = input[1];

	var alphabetSort = (function(a, b){
		a = a.toString().toLowerCase();
		b = b.toString().toLowerCase();
		if(a < b){
			return -1;
		}else if(a > b){
			return 1;
		}
		return 0;
	});

	var ss = s.split("").sort(alphabetSort).join();
	var rst = t.split(").sort(alphabetSort).reverse().join();

	var result = [ss, rst].sort(alphabetSort);
	//s'<t'ならばresult[0] = s'

    console.log(result[0] == ss ? "Yes" : "No");
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


(function(){
 'use strict';
function Main(input) {
  num = input.split(" ");
  var a = parseInt(num[0]);
  var b = parseInt(num[1]);
  var c = (a + b) / 2;
  var d = Math.ceil(c);
  console.log(d);
 }
})();


( i => {
  i = i.split('\n').map((val, index) => index ? val.split('').sort().join('') : val.split('').sort().reverse().join(''));
  console.log(i[0] > i[1] ? 'Yes' : 'No')
})(require("fs").readFileSync("/dev/stdin", "utf8"))

Score : 200 points

Problem Statement

You are given strings s and t, consisting of lowercase English letters.
You will create a string s' by freely rearranging the characters in s.
You will also create a string t' by freely rearranging the characters in t.
Determine whether it is possible to satisfy s' < t' for the lexicographic order.

Notes

For a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:

N < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.

There exists i (1 \leq i \leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.

For example, xy < xya and atcoder < atlas.

Constraints

The lengths of s and t are between 1 and 100 (inclusive).

s and t consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

If it is possible to satisfy s' < t', print Yes; if it is not, print No.

Sample Input 1

yx
axy

Sample Output 1

Yes

We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.

Sample Input 2

ratcode
atlas

Sample Output 2

Yes

We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.

Sample Input 3

cd
abc

Sample Output 3

No

No matter how we rearrange cd and abc, we cannot achieve our objective.

Sample Input 4

w
ww

Sample Output 4

Yes

Sample Input 5

zzz
zzz

Sample Output 5

No


function Main(input) {
  var inputs = input.split("\n");
  var s = inputs[0].split("").sort().join();
  var t = inputs[1].split("").sort().reverse().join();

  console.log(s < t ? "Yes":"No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0])
    const A = input[1].split(' ').map(v => parseInt(v))
    let obj = {}
    A.forEach(v => {
        if(typeof obj[v] === 'undefined'){
            obj[v] = 0
        }
        obj[v]++
    })
    let count = 0
    for(let key in obj){
        let k = parseInt(key)
        let c = obj[key]
        if(k < c){
            count += c - k
        }
        if(k > c){
            count += c
        }
    }
    console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Score : 300 points

Problem Statement

You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.

Here, an sequence b is a good sequence when the following condition holds true:

For each element x in b, the value x occurs exactly x times in b.

For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.

Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Constraints

1 \leq N \leq 10^5

a_i is an integer.

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of elements that needs to be removed so that a will be a good sequence.

Sample Input 1

4
3 3 3 3

Sample Output 1

1

We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.

Sample Input 2

5
2 4 1 4 2

Sample Output 2

2

We can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence.

Sample Input 3

6
1 2 2 3 3 3

Sample Output 3

0

Sample Input 4

1
1000000000

Sample Output 4

1

Remove one occurrence of 10^9. Then, () is a good sequence.

Sample Input 5

8
2 7 1 8 2 8 1 8

Sample Output 5

5


var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var s = o.a(1);
  var x = [o.a(),o.a()];
  var h = [[],[]], l = s.length;
  var T = "T";
  for(var i = 0; i < l; i++){
    if(s[i] === T)break;
    x[0]--;
  }
  var f = 1, u = 0;
  for(i++; i < l; i++){
    if(s[i] === T){if(u)h[f].push(u); f ^= 1; u = 0;}
    else u++;
  }
  if(u)h[f].push(u);
  for(i = 0; i < 2; i++){
    var set = new Set();
    set.add(x[i]);
    while(h[i].length){
      var t = h[i].pop();
      var set2 = new Set();
      for(var j of set){
        set2.add(j-t);
        set2.add(j+t);
      }
      set = set2;
    }
    if(!set.has(0))return "No";
  }
  return "Yes";
}

Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No


'use strict'

const main = input => {
	const args = input.trim().split('\n')
	const n = parseInt(args[0], 10)
	const a = args[1].split(' ').map(Number)
	let cnt = 0

	while (true) {
		let isOdd = false

		for (let i = 0; i < n; i++) {
			if (a[i] % 2 === 1) isOdd = true
		}

		if (isOdd) break

		for (let i = 0; i < n; i++) {
			a[i] = Math.floor(a[i] / 2)
		}

		cnt++
	}

	console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Score : 200 points

Problem Statement

There are N positive integers written on a blackboard: A_1, ..., A_N.

Snuke can perform the following operation when all integers on the blackboard are even:

Replace each integer X on the blackboard by X divided by 2.

Find the maximum possible number of operations that Snuke can perform.

Constraints

1 \leq N \leq 200

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible number of operations that Snuke can perform.

Sample Input 1

3
8 12 40

Sample Output 1

2

Initially, [8, 12, 40] are written on the blackboard.
Since all those integers are even, Snuke can perform the operation.

After the operation is performed once, [4, 6, 20] are written on the blackboard.
Since all those integers are again even, he can perform the operation.

After the operation is performed twice, [2, 3, 10] are written on the blackboard.
Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.

Thus, Snuke can perform the operation at most twice.

Sample Input 2

4
5 6 8 10

Sample Output 2

0

Since there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.

Sample Input 3

6
382253568 723152896 37802240 379425024 404894720 471526144

Sample Output 3

8


function main(input) {
  input = input.split('\n');
  const NK = input[0].split(' ').map(n => parseInt(n, 10));
  const N = NK[0],
        K = NK[1];
  const A = input[1].split(' ').map(n => parseInt(n, 10));

  const targets = Array.from(new Set(A))
    .map(i => A.filter(j => j === i).length)
    .sort((a, b) => {
      if (a > b) return -1;
      if (a < b) return 1;
      return 0;
    })
    .slice(K);

  const answer = (targets.length > 0) ? targets.reduce((a, b) => a + b) : 0;
  console.log(answer);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 300 points

Problem Statement

Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.

Sample Input 3

10 3
5 1 3 2 4 1 1 2 3 4

Sample Output 3

3


"use strict"

function main(input) {
  input = input.split(/\n|\s/).map(v => ~~v)
  const k = input[1]
  const nums = input.slice(2, -1).sort((a, b) => a - b)
  let ans = 0

  let items = []
  let pointer = null
  for (let i = 0; i < nums.length; i++) {
    if (
      i == 0 ||
      items[pointer].key == undefined ||
      items[pointer].key != nums[i]
    ) {
      pointer = pointer === null ? 0 : pointer + 1
      items[pointer] = {
        key: nums[i],
        count: 1
      }
    } else {
      items[pointer].count += 1
    }
  }

  // sort by count
  items.sort((a, b) => {
    return a.count - b.count
  })

  const diff = items.length - k
  const tar = items.slice(0, diff)
  for (let i in tar) {
    ans += tar[i].count
  }

  console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


'use strict'

function main(s) {

  s = s.split('\n');
  const K = Number(s[0].split(' ')[1]);
  const balls = s[1].split(' ').map(el => Number(el));
  const countList = [];

  balls.forEach((x, i, self) => {
    if(self.indexOf(x) === i) {
      countList.push({key: x, count: 1});
    } else {
      countList.forEach((y, j, self) => {
        if (x === y.key) y.count += 1;
      })
    }
  });

  countList.sort((a, b) => b.count - a.count);

  const changeList = countList.slice(K);
  let answer = 0;
  if (changeList) {
    changeList.forEach((el) => {
      answer += el.count;
    })
  }

  console.log(answer);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const [n, a, b] = input.trim().split(" ").map(Number);
  return n * a < b ? n * a : b;
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));

Score : 100 points

Problem Statement

You are parking at a parking lot. You can choose from the following two fee plans:

Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.

Plan 2: The fee will be B yen, regardless of the duration.

Find the minimum fee when you park for N hours.

Constraints

1≤N≤20

1≤A≤100

1≤B≤2000

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

When the minimum fee is x yen, print the value of x.

Sample Input 1

7 17 120

Sample Output 1

119

If you choose Plan 1, the fee will be 7×17=119 yen.

If you choose Plan 2, the fee will be 120 yen.

Thus, the minimum fee is 119 yen.

Sample Input 2

5 20 100

Sample Output 2

100

The fee might be the same in the two plans.

Sample Input 3

6 18 100

Sample Output 3

100


var lines = []; var result = 0;

var readline = require("readline");

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {

    var N = Number(lines[0].split(" ")[0]);
    var A = Number(lines[0].split(" ")[1]);
    var B = Number(lines[0].split(" ")[2]);

    A * T < B ? console.log(A * T) : console.log(B);
});


process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!
function main(input) {
    var x = input.split(' ');
    var n = parseInt(x[0]);
    var a = parseInt(x[1]);
    var b = parseInt(x[2]);
    if(a * n > b){
        console.log(b);
    }
    else{
        console.log(a * n);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var n = parseInt(input[0], 10);
    var f = new Array(n);
    for (var i = 0; i < n; i++) {
        f[i] = new Array(10);
        var args = input[1 + i].split(' ');
        for (var j = 0; j < 10; j++) {
            f[i][j] = parseInt(args[j], 10);
        }
    }
    var p = new Array(n);
    for (var i = 0; i < n; i++) {
        p[i] = new Array(10);
        var args = input[1 + n + i].split(' ');
        for (var j = 0; j < 10; j++) {
            p[i][j] = parseInt(args[j], 10);
        }
    }

    var ret = Number.MIN_SAFE_INTEGER;
    for (var i = 1; i < 1024; i++) {
        var cc = 0;
        for (var j = 0; j < n; j++) {
            var c = 0;
            for (var k = 0; k < 10; k++) {
                if ((i >> k & 1) == 1 && f[j][k] > 0) {
                    c++;
                }
            }
            cc += p[j][c];
        }
        if (ret < cc) {
            ret = cc;
        }
    }

    console.log(ret);

    return 0;
}

Score : 300 points

Problem Statement

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already N stores in the street, numbered 1 through N.

You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.

Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

1≤N≤100

0≤F_{i,j,k}≤1

For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.

-10^7≤P_{i,j}≤10^7

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

Output

Print the maximum possible profit of Joisino's shop.

Sample Input 1

1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

Sample Output 1

8

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.

Sample Input 2

2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

Sample Output 2

-2

Note that a shop must be open during at least one period, and the profit may be negative.

Sample Input 3

3
1 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7

Sample Output 3

23


//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var C = one[1];
  var len = 100;
  var list = new Array(len);
  for(var i = 0; i < len; i++){
    list[i] = {
      add : [],
      remove : []
    };
  }
  for(var i = 0; i < N; i++){
    var tmp = nextIntArray();
    list[tmp[0] - 1].add.push(tmp[2]);
    list[tmp[1]].remove.push(tmp[2]);
  }
  var used = new Set();
  for(var i = 0; i < list[0].add.length; i++){
    used.add(list[0].add[i]);
  }
  var output = used.size;
  for(var i = 1; i < len; i++){
    for(var j = 0; j < list[i].remove.length; j++){
      used.delete(list[i].remove[j]);
    }
    for(var j = 0; j < list[i].add.length; j++){
      used.add(list[i].add[j]);
    }
    output = Math.max(output, used.size);
  }
  myout(output);
}

Score : 400 points

Problem Statement

Joisino is planning to record N TV programs with recorders.

The TV can receive C channels numbered 1 through C.

The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.

Here, there will never be more than one program that are broadcast on the same channel at the same time.

When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).

Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.

Constraints

1≤N≤10^5

1≤C≤30

1≤s_i<t_i≤10^5

1≤c_i≤C

If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N C
s_1 t_1 c_1
:
s_N t_N c_N

Output

When the minimum required number of recorders is x, print the value of x.

Sample Input 1

3 2
1 7 2
7 8 1
8 12 1

Sample Output 1

2

Two recorders can record all the programs, for example, as follows:

With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.

With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.

Sample Input 2

3 4
1 3 2
3 4 4
1 4 3

Sample Output 2

3

There may be a channel where there is no program to record.

Sample Input 3

9 4
56 60 4
33 37 2
89 90 3
32 43 1
67 68 3
49 51 3
31 32 3
70 71 1
11 12 3

Sample Output 3

2


var s = require('fs').readFileSync('/dev/stdin', 'utf8');

function toHalfWidth(strVal) {
    // 半角変換
    var halfVal = strVal.replace(/[！-～]/g,
        function (tmpStr) {
            // 文字コードをシフト
            return String.fromCharCode(tmpStr.charCodeAt(0) - 0xFEE0);
        }
    );

    return halfVal;
}

var r = (halfVal(s)).match(/^A?KIHA?BA?RA?$/);

if (r === null) console.log("NO");
else console.log("YES");

Score : 300 points

Problem Statement

You are given a string S.

Takahashi can insert the character A at any position in this string any number of times.

Can he change S into AKIHABARA?

Constraints

1 \leq |S| \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If it is possible to change S into AKIHABARA, print YES; otherwise, print NO.

Sample Input 1

KIHBR

Sample Output 1

YES

Insert one A at each of the four positions: the beginning, immediately after H, immediately after B and the end.

Sample Input 2

AKIBAHARA

Sample Output 2

NO

The correct spell is AKIHABARA.

Sample Input 3

AAKIAHBAARA

Sample Output 3

NO


function main(input) {
  const s = input.trim()

  const array = s.split('').reduce((a, c) => {
    a[c.charCodeAt() - 'a'.charCodeAt()]++
    return a
  }, [0, 0, 0])

  if (Math.max(...array) - Math.min(...array) >= 2) {
    console.log('NO')
  } else {
    console.log('YES')
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Score : 400 points

Problem Statement

Snuke has a string S consisting of three kinds of letters: a, b and c.

He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.

Constraints

1 \leq |S| \leq 10^5

S consists of a, b and c.

Input

Input is given from Standard Input in the following format:

S

Output

If the objective is achievable, print YES; if it is unachievable, print NO.

Sample Input 1

abac

Sample Output 1

YES

As it stands now, S contains a palindrome aba, but we can permute the characters to get acba, for example, that does not contain a palindrome of length 2 or more.

Sample Input 2

aba

Sample Output 2

NO

Sample Input 3

babacccabab

Sample Output 3

YES


'use strict'

function main(s) {

  const n = s.split('\n')[0].split('');

  const pattern1 = n[0] === n[1] && n[1] === n[2]
  const pattern2 = n[1] === n[2] && n[2] === n[3];

  const ans = patter1 || pattern2;
  console.log(ans ? 'Yes' : 'No');
}

// main(require("fs").readFileSync("/dev/stdin", "utf8"));
main();

Score : 100 points

Problem Statement

We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.

You are given a 4-digit integer N. Answer the question: Is N good?

Constraints

1000 ≤ N ≤ 9999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is good, print Yes; otherwise, print No.

Sample Input 1

1118

Sample Output 1

Yes

N is good, since it contains three consecutive 1.

Sample Input 2

7777

Sample Output 2

Yes

An integer is also good when all the digits are the same.

Sample Input 3

1234

Sample Output 3

No


console.log((args=>{
  const S = args.trim().split('');
  const stack = [[S.slice(0,3),S[3]]];
  while ( stack.length ) {
    const [a,s] = stack.pop();
    if ( a.length === 0 ) {
      if ( eval(s) === 7 ) return s+'=7';
      else continue;
    }
    const v = a.pop();
    stack.push([[...a],v+'+'+s]);
    stack.push([[...a],v+'-'+s]);
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8')));

Score : 300 points

Problem Statement

Sitting in a station waiting room, Joisino is gazing at her train ticket.

The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).

In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.

The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

Print the formula you made, including the part =7.

Use the signs + and -.

Do not print a space between a digit and a sign.

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

0 - 2 + 9 - 0 = 7 is also a valid solution.

Sample Input 3

3242

Sample Output 3

3+2+4-2=7


function Main(input){
  var inputs = input.split("");
  var a = [];
  function Func(n,sum){
    if(n == 0){
      if(sum == 0){
        return true;}
    }else{
      if(Func(n-1,sum+new Number(inputs[n-1])) == true){
        a[n-1] = "-";
        return true;
      }else if(Func(n-1,sum-new Number(inputs[n-1])) == true){
        a[n-1] = "+";
        return true;
      }else{
        return false;
      }
    }
  }
  if(Func(4,7) == true){
    console.log(inputs[0] + a[1] + inputs[1] + a[2] + inputs[2] + a[3] + inputs[3] + "=7" );
  }else{
    console.log("program error");
  }
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));


"use strict";

var main = function main(input) {
  var args = input.split('');
  var A = parseInt(args[0], 10);
  var B = parseInt(args[1], 10);
  var C = parseInt(args[2], 10);
  var D = parseInt(args[3], 10);

  if (A + B + C + D == 7) {
    console.log("".concat(A, "+").concat(B, "+").concat(C, "+").concat(D, "=7"));
  } else if (A - B + C + D == 7) {
    console.log("".concat(A, "-").concat(B, "+").concat(C, "+").concat(D, "=7"));
  } else if (A + B - C + D == 7) {
    console.log("".concat(A, "+").concat(B, "-").concat(C, "+").concat(D, "=7"));
  } else if (A + B + C - D == 7) {
    console.log("".concat(A, "+").concat(B, "+").concat(C, "-").concat(D, "=7"));
  } else if (A - B - C + D == 7) {
    console.log("".concat(A, "-").concat(B, "-").concat(C, "+").concat(D, "=7"));
  } else if (A - B + C - D == 7) {
    console.log("".concat(A, "-").concat(B, "+").concat(C, "-").concat(D, "=7"));
  } else if (A - B - C - D == 7) {
    console.log("".concat(A, "-").concat(B, "-").concat(C, "-").concat(D, "=7"));
  } else if (A + B - C - D == 7) {
    console.log("".concat(A, "+").concat(B, "-").concat(C, "-").concat(D, "=7"));
  }
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));


console.log((args=>{
  const [[H,W],...tmp] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  const c = tmp.slice(0,10), A = tmp.slice(10);
  const dp = Array(10).fill(0);
  for ( let i = 0; i < 10; i++ ) dp[i] = c[i][1];
  for ( let i = 0; i < 10; i++ ) {
    if ( i === 1 ) continue;
    for ( let j = 0; j < 10; j++ ) {
      if ( j === 1 ) continue;
      dp[i] = Math.min( dp[i], dp[j] + c[i][j] );
    }
  }
  let cost = 0;
  for ( let i = 0; i < H; i++ ) {
    for ( let j = 0; j < W; j++ ) {
      if ( A[i][j] === -1 || A[i][j] === 1 ) continue;
      cost += dp[A[i][j]];
    }
  }
  return cost;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));

Score : 400 points

Problem Statement

Joisino the magical girl has decided to turn every single digit that exists on this world into 1.

Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).

She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).

You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:

If A_{i,j}≠-1, the square contains a digit A_{i,j}.

If A_{i,j}=-1, the square does not contain a digit.

Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.

Constraints

1≤H,W≤200

1≤c_{i,j}≤10^3 (i≠j)

c_{i,j}=0 (i=j)

-1≤A_{i,j}≤9

All input values are integers.

There is at least one digit on the wall.

Input

Input is given from Standard Input in the following format:

H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}

Output

Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.

Sample Input 1

2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8

Sample Output 1

12

To turn a single 8 into 1, it is optimal to first turn 8 into 4, then turn 4 into 9, and finally turn 9 into 1, costing 6 MP.

The wall contains two 8s, so the minimum total MP required is 6×2=12.

Sample Input 2

5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

Sample Output 2

0

Note that she may not need to change any digit.

Sample Input 3

3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6

Sample Output 3

47


var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0])
    var M = Number(lines[0].split(" ")[1])

    console.log(Math.pow(2, M) * (1900 * M + 100 * (N - M)))
});

Score : 300 points

Problem Statement

Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.

When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.

Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds.

Now, he goes through the following process:

Submit the code.

Wait until the code finishes execution on all the cases.

If the code fails to correctly solve some of the M cases, submit it again.

Repeat until the code correctly solve all the cases in one submission.

Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).

Constraints

All input values are integers.

1 \leq N \leq 100

1 \leq M \leq {\rm min}(N, 5)

Input

Input is given from Standard Input in the following format:

N M

Output

Print X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 10^9.

Sample Input 1

1 1

Sample Output 1

3800

In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1/2 probability in 1900 milliseconds.

The code will succeed in one attempt with 1/2 probability, in two attempts with 1/4 probability, and in three attempts with 1/8 probability, and so on.

Thus, the answer is 1900 \times 1/2 + (2 \times 1900) \times 1/4 + (3 \times 1900) \times 1/8 + ... = 3800.

Sample Input 2

10 2

Sample Output 2

18400

The code will take 1900 milliseconds in each of the 2 cases, and 100 milliseconds in each of the 10-2=8 cases. The probability of the code correctly solving all the cases is 1/2 \times 1/2 = 1/4.

Sample Input 3

100 5

Sample Output 3

608000


function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var z = parseInt(input[0].split(" ")[1]);
  var w = parseInt(input[0].split(" ")[2]);
  tmp = input[1].split(" ");
  ans = 0;
  a = new Array(n).fill(0);
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
  }
  if(n==1){
    ans=a[0]-w;
  }else{
  ans=Math.max(Math.abs(a[n-2]-a[n-1]),Math.abs(a[n-1]-w));
  }

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 500 points

Problem Statement

We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.

Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:

Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.

The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.

X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

Constraints

All input values are integers.

1 \leq N \leq 2000

1 \leq Z, W, a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N Z W
a_1 a_2 ... a_N

Output

Print the score.

Sample Input 1

3 100 100
10 1000 100

Sample Output 1

900

If X draws two cards first, Y will draw the last card, and the score will be |1000 - 100| = 900.

Sample Input 2

3 100 1000
10 100 100

Sample Output 2

900

If X draws all the cards first, the score will be |1000 - 100| = 900.

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

0

Sample Input 4

1 1 1
1000000000

Sample Output 4

999999999


function Main(input) {
    var input = input.split('\n');
    var ue = input[0].split('');
    var sita = input[1].split('');
    if(ue[0]==sita[2] && ue[1]==sita[1] && ue[2]==sita[0]) {
        console.log('Yes');
    } else {
        console.log('No');
    }

    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

You are given a grid with 2 rows and 3 columns of squares.
The color of the square at the i-th row and j-th column is represented by the character C_{ij}.

Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.

Constraints

C_{i,j}(1 \leq i \leq 2, 1 \leq j \leq 3) is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

C_{11}C_{12}C_{13}
C_{21}C_{22}C_{23}

Output

Print YES if this grid remains the same when rotated 180 degrees; print NO otherwise.

Sample Input 1

pot
top

Sample Output 1

YES

This grid remains the same when rotated 180 degrees.

Sample Input 2

tab
bet

Sample Output 2

NO

This grid does not remain the same when rotated 180 degrees.

Sample Input 3

eye
eel

Sample Output 3

NO


(function() {
    'use strict';

    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;

    // ToDo start
      var N = parseInt(lines[0])
      var ans = 0

      for (var i=0;i<=N;i++){
        var test = i*i
        if(test <= N){
            ans = test
        }
      }

    console.log(ans)

//      console.log( Math.pow(parseInt(lines[0]),2) - parseInt(lines[1])  )
    // ToDo end

    });

})();


'use strict'

function main(s) {

  const n = Number(s);

  let max = 0;
  let i = 0;

  while (max < n) {
    i += 1;
    max = Math.pow(i, 2);
  }

  const ans = Math.pow(i - 1, 2);

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

Constraints

1 \leq N \leq 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the largest square number not exceeding N.

Sample Input 1

10

Sample Output 1

9

10 is not square, but 9 = 3 × 3 is. Thus, we print 9.

Sample Input 2

81

Sample Output 2

81

Sample Input 3

271828182

Sample Output 3

271821169


(function() {
    'use strict';

    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;

    // ToDo start
      var N = parseInt(lines[0])
      var A =lines[1].split(" ")
      var B =lines[2].split(" ")
      var C =lines[3].split(" ")
      var ans = 0

        //sort
        for(var ai=0;ai<N;ai++){
            A[ai] = ("000000000" + (""+A[ai]) ).slice(-9)
        }
        A = A.sort()
        for(var bi=0;bi<N;bi++){
            B[bi] = ("000000000" + (""+B[bi]) ).slice(-9)
        }
        B = B.sort()
        for(var bi=0;bi<N;bi++){
//            console.log(B[bi])
        }

        for(var ci=0;ci<N;ci++){
            C[ci] = ("000000000" + (""+C[ci]) ).slice(-9)
        }
        C = C.sort()

      for (var ai=0;ai<N;ai++){
          bloop:for (var bi=N-1;bi>=0;bi--){
              if( A[ai] < B[bi] ) {
                  //console.log("A:"+A[ai] + " B:"+B[bi])
                cloop:for (var ci=0;ci<N;ci++){
                    if( B[bi] < C[ci] ){
//                        console.log("ai:"+A[ai] + " bi:"+B[bi] + " ci:"+C[ci])
                        ans = ans + N-ci
//                        console.log("ans:"+ans)
                        break cloop;
                    }
                 }
               }else{
                   break bloop;
               }
          }
       }

    console.log(ans)

//      console.log( Math.pow(parseInt(lines[0]),2) - parseInt(lines[1])  )
    // ToDo end

    });

})();

Score : 300 points

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

1 \leq B_i \leq 10^9(1\leq i\leq N)

1 \leq C_i \leq 10^9(1\leq i\leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87


const input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");

const N = input[0].split(' ').map(item => parseInt(item))[0]
const K = input[1].split(' ').map(item => parseInt(item))[0]

const greedy = (value, n, k) => {
    if (n == 0) {
        return value
    }
    if (n > 0) {
        a = value * 2
        b = value + k
        a < b ? value = a : value = b
        return greedy(value, n - 1, k)
    }
}

console.log(greedy(1, N, K))

Score : 200 points

Problem Statement

Square1001 has seen an electric bulletin board displaying the integer 1.
He can perform the following operations A and B to change this value:

Operation A: The displayed value is doubled.

Operation B: The displayed value increases by K.

Square1001 needs to perform these operations N times in total.
Find the minimum possible value displayed in the board after N operations.

Constraints

1 \leq N, K \leq 10

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the minimum possible value displayed in the board after N operations.

Sample Input 1

4
3

Sample Output 1

10

The value will be minimized when the operations are performed in the following order: A, A, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.

Sample Input 2

10
10

Sample Output 2

76

The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.

By the way, this contest is AtCoder Beginner Contest 076.


'use strict'
const inputs = require('fs').readFileSync(0, 'utf8').split('\n')
const N = parseInt(inputs[0], 10)
const K = parseInt(inputs[1], 10)
let ans = 1
for (let i = 0;i < N;i++) {
  ans = Math.min(ans + K, ans * 2)
}
console.log(ans)


'use strict'

function main(s) {

  s = s.split('\n').slice(0, -1).map(n => Number(n));

  const n = s[0];
  const k = s[1];

  let num = 1;

  for (let i = 0; i < n; i++) {
    if (num <= k) {
      num *= 2;
    } else {
      num += k;
    }
  }

  console.log(num);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const S = args[0][0]
	const N = S.length
	let ans = false

	for (let i = 0; i < N - 1; i++) {
		if (S.slice(i, i + 2) === 'AC') ans = true
	}

	console.log(ans ? 'Yes' : 'No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Score : 100 points

Problem Statement

Snuke built an online judge to hold a programming contest.

When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring.
(The judge can return any two-character substring of S.)

Determine whether the judge can return the string AC as the verdict to a program.

Constraints

2 \leq |S| \leq 5

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If the judge can return the string AC as a verdict to a program, print Yes; if it cannot, print No.

Sample Input 1

BACD

Sample Output 1

Yes

The string AC appears in BACD as a contiguous substring (the second and third characters).

Sample Input 2

ABCD

Sample Output 2

No

Although the string ABCD contains both A and C (the first and third characters), the string AC does not appear in ABCD as a contiguous substring.

Sample Input 3

CABD

Sample Output 3

No

Sample Input 4

ACACA

Sample Output 4

Yes

Sample Input 5

XX

Sample Output 5

No


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));

    let k = 1;

    for(let i in A) {
        if(A[i] % 2 === 0) {
            k *= 2;
        }
    }

    console.log(Math.pow(3, N) - k);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 200 points

Problem Statement

We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are similar when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N).

In particular, any integer sequence is similar to itself.

You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N.

How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?

Constraints

1 \leq N \leq 10

1 \leq A_i \leq 100

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of integer sequences that satisfy the condition.

Sample Input 1

2
2 3

Sample Output 1

7

There are seven integer sequences that satisfy the condition:

1, 2

1, 4

2, 2

2, 3

2, 4

3, 2

3, 4

Sample Input 2

3
3 3 3

Sample Output 2

26

Sample Input 3

1
100

Sample Output 3

1

Sample Input 4

10
90 52 56 71 44 8 13 30 57 84

Sample Output 4

58921


function Main(input) {
  const numbers = input.split(' ').map(n => Number(n));
  const a = numbers[0];
  const b = numbers[1];
  const c = numbers[2];

  if (a === b) {
    console.log(c);
  } else if (b === c) {
    console.log(a);
  } else {
    console.log(b);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

You are given three integers, A, B and C.

Among them, two are the same, but the remaining one is different from the rest.

For example, when A=5,B=7,C=5, A and C are the same, but B is different.

Find the one that is different from the rest among the given three integers.

Constraints

-100 \leq A,B,C \leq 100

A, B and C are integers.

The input satisfies the condition in the statement.

Input

Input is given from Standard Input in the following format:

A B C

Output

Among A, B and C, print the integer that is different from the rest.

Sample Input 1

5 7 5

Sample Output 1

7

This is the same case as the one in the statement.

Sample Input 2

1 1 7

Sample Output 2

7

In this case, C is the one we seek.

Sample Input 3

-100 100 100

Sample Output 3

-100


function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let N = parseInt(input[0][0], 10);
	let M = parseInt(input[0][1], 10);
	let line;
	let ans = 0;
	for (skip = 0; skip < M; skip++){
		let uf = new UnionFind(N);
		for (let i = 0; i < M; i++){
			if (i === skip) continue;
			line = input[i + 1].map(e => parseInt(e, 10));
			uf.union(line[0] - 1, line[1] - 1);
		}
		if (uf.size(0) !== N) ans ++;
	}
	console.log(ans);
}

function UnionFind (n) {
	this.parents = [];
	for (let i = 0; i < n; i++) {
		this.parents.push(-1);
	}
}

UnionFind.prototype.find = function (x) {
	if (this.parents[x] < 0) return x;
	return this.parents[x] = this.find(this.parents[x]);
}

UnionFind.prototype.union = function (x, y) {
	x = this.find(x);
	y = this.find(y);
	if (x === y) return;
	if (this.parents[x] > this.parents[y]) [x, y] = [y, x];

	this.parents[x] += this.parents[y];
	this.parents[y] = x;
}

UnionFind.prototype.size = function (x) {
	x = this.find(x);
	while (x >= 0) {
		x = this.parents[x];
	}
	return x * -1;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.

The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.

An edge whose removal disconnects the graph is called a bridge.

Find the number of the edges that are bridges among the M edges.

Notes

A self-loop is an edge i such that a_i=b_i (1 \leq i \leq M).

Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \leq i<j \leq M).

An undirected graph is said to be connected when there exists a path between every pair of vertices.

Constraints

2 \leq N \leq 50

N-1 \leq M \leq min(N(N−1)⁄2,50)

1 \leq a_i<b_i \leq N

The given graph does not contain self-loops and double edges.

The given graph is connected.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print the number of the edges that are bridges among the M edges.

Sample Input 1

7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

Sample Output 1

4

The figure below shows the given graph:

The edges shown in red are bridges. There are four of them.

Sample Input 2

3 3
1 2
1 3
2 3

Sample Output 2

0

It is possible that there is no bridge.

Sample Input 3

6 5
1 2
2 3
3 4
4 5
5 6

Sample Output 3

5

It is possible that every edge is a bridge.


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");

    S.splice(S.length - 8, 8, "");

    console.log(S.join(""));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

Rng is going to a festival.

The name of the festival is given to you as a string S, which ends with FESTIVAL, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.

Here, assume that the name of "a festival of s" is a string obtained by appending FESTIVAL to the end of s.
For example, CODEFESTIVAL is a festival of CODE.

Constraints

9 \leq |S| \leq 50

S consists of uppercase English letters.

S ends with FESTIVAL.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer to the question: "Rng is going to a festival of what?"

Sample Input 1

CODEFESTIVAL

Sample Output 1

CODE

This is the same as the example in the statement.

Sample Input 2

CODEFESTIVALFESTIVAL

Sample Output 2

CODEFESTIVAL

This string is obtained by appending FESTIVAL to the end of CODEFESTIVAL, so it is a festival of CODEFESTIVAL.

Sample Input 3

YAKINIKUFESTIVAL

Sample Output 3

YAKINIKU


function getLineByParam( param ){
  var ret;
  for ( var i=0; i<param[0].length; i++ ) {
    if ( "\n" == param[0].charAt( i ) ) {
      ret = param[0].slice( 0, i );
      param[0] = param[0].slice( ret.length+1 );
      return ret;
    }
  }
  ret = param[0];
  param[0]="";
  return ret;
}
function Main(input) {
  input = [input];
  var N = getLineByParam(input);
  N = parseInt( N );

  var N=4/N;
  var chi;
  var mot;
  var tmp;
  for ( var h=1; h<=3500; h++ ) {
    if ( N <= 1/h ) continue;
    for ( var n=1; n<=3500; n++ ) {
      var chi = h+n;
      var mot = (h*n);
      var tmp = chi/mot;
      if ( N <= tmp ) continue;

      tmp = search2way( N-tmp, 3500, 1750 );
      if ( -1 == tmp ) continue;
      if ( isCorrect( N, h, n, tmp ) ) return;
    }
  }
  console.log( "NG" );

  function search2way( ans, val, diff ){
    var tmp;
    var fix=0;
    while ( 0 != diff ) {
      tmp = 1/val;
      if ( ans == tmp ) {
        return val;
      }
      else if ( ans < tmp ) {
        val += diff;
        if ( 1 == diff && 0 == fix ) fix = 1;
        if ( -1 == fix ) return -1;
        if ( val > 3500 ) return -1;
      }
      else {
        val -= diff;
        if ( 1 == diff && 0 == fix ) fix = -1;
        if ( 1 == fix ) return -1;
        if ( val < 1 ) return -1;
      }

      diff = Math.floor( diff / 2 );
      if ( 0 == diff ) diff = 1;
    }
    return -1;
  }
  function isCorrect( N, h, n, w ){
//    if ( N == ( 1/h + 1/n + 1/w ) ) {
    var chi = (n*w)+(h*w)+(h*n);
    var mot = (h*n*w);
    var tmp = chi/mot;
    if ( N == tmp ) {
      console.log( [ h, n, w ].join(" ") );
      return true;
    }
    return false;
  }
  function isInclude( ary, idx ){
    for ( var i=0; i<ary.length; i++ ) {
      if ( ary[i] === idx ) return true;
    }
    return false;
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

You are given an integer N.

Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w.

If there are multiple solutions, any of them will be accepted.

Constraints

It is guaranteed that, for the given integer N, there exists a solution such that h,n,w \leq 3500.

Inputs

Input is given from Standard Input in the following format:

N

Outputs

Print a triple of positive integers h, n and w that satisfies the condition, in the following format:

h n w

Sample Input 1

2

Sample Output 1

1 2 2

4/2 = 1/1 + 1/2 + 1/2.

Sample Input 2

3485

Sample Output 2

872 1012974 1539173474040

It is allowed to use an integer exceeding 3500 in a solution.

Sample Input 3

4664

Sample Output 3

3498 3498 3498


function Main(input){
	var max = 0;
	var ans = 0;
	input = input.split("\n");
	for(var i=1;i<input.length;i++){
		var mem = input[i].split(" ").map(Number);
		if(max<mem[0]){
			max = mem[0];
			ans = mem[0]+mem[1];
		}
	}
	console.log(max[0]-0+(max[1]-0))
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Score : 200 points

Problem Statement

A group of people played a game. All players had distinct scores, which are positive integers.

Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i.

Find the maximum possible number of players in the game.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

0 \leq B_i \leq 10^9(1\leq i\leq N)

If i ≠ j, A_i ≠ A_j.

There exists a possible outcome of the game that are consistent with the facts.

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Outputs

Print the maximum possible number of players in the game.

Sample Input 1

3
4 7
2 9
6 2

Sample Output 1

8

The maximum possible number of players is achieved when, for example, the players have the following scores: 12,9,8,7,5,2,1,0.

Sample Input 2

5
1 10
3 6
5 2
4 4
2 8

Sample Output 2

7

Sample Input 3

2
1 1000000000
1000000000 1

Sample Output 3

1000000001


'use strict';

function Main(input){
  var line = input.split("\n");
  line.pop();
  line.shift();
  line.sort((a,b)=>{
    if ( a > b ) return -1;
    if ( a < b ) return 1;
    return 0;
  });
  console.log(parseInt(line[0].split(" ")[0],10) + parseInt(line[0].split(" ")[1],10));
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


'use strict'

function Main(input) {
    var params = input.split('\n');
    const n = params[0];

    let minScore = 0;
    let lowest = 0;
    for (let i = 1; i < params.length; i++) {
        const arg = params[i].split(' ');
        if (arg[0] > lowest) {
            lowest = parseInt(arg[0], 10);
            minScore = parseInt(arg[1], 10);
        }
    }
    console.log(lowest + minScore);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
     input = input.split('\n')
     input.pop()
  input = input[0].split(' ')
    var N = input[0],
        M = input[1],
        K = input[2]
    if ((K % N == 0 && K / N <= M) || (K % M == 0 && K / M <= N)) {
        console.log('Yes')
        return
    }
    if (K < M && K < N) {
        console.log('No')
        return
    }
    for (var i = 1; i <= M; i++) {
        for (var j = 1; j <= N; j++) {
            if (K == (i * M + (N - 2 * j))) {
                console.log('Yes')
                return
            }
        }
    }
    for (var i = 1; i <= N; i++) {
        for (var j = 1; j <= M; j++) {
            if (K == (i * N + (M - 2 * j))) {
                console.log('Yes')
                return
            }
        }
    }
    console.log('No')
    return

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

We have a grid with N rows and M columns of squares. Initially, all the squares are white.

There is a button attached to each row and each column.
When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.
When a button attached to a column is pressed, the colors of all the squares in that column are inverted.

Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

Constraints

1 \leq N,M \leq 1000

0 \leq K \leq NM

Input

Input is given from Standard Input in the following format:

N M K

Output

If Takahashi can have exactly K black squares in the grid, print Yes; otherwise, print No.

Sample Input 1

2 2 2

Sample Output 1

Yes

Press the buttons in the order of the first row, the first column.

Sample Input 2

2 2 1

Sample Output 2

No

Sample Input 3

3 5 8

Sample Output 3

Yes

Press the buttons in the order of the first column, third column, second row, fifth column.

Sample Input 4

7 9 20

Sample Output 4

No


"use strict";

const main = arg => {
    const A = arg.split("\n")[0];
    const B = arg.split("\n")[1];
    console.log((A * A) - B);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

We have an N \times N square grid.

We will paint each square in the grid either black or white.

If we paint exactly A squares white, how many squares will be painted black?

Constraints

1 \leq N \leq 100

0 \leq A \leq N^2

Inputs

Input is given from Standard Input in the following format:

N
A

Outputs

Print the number of squares that will be painted black.

Sample Input 1

3
4

Sample Output 1

5

There are nine squares in a 3 \times 3 square grid.
Four of them will be painted white, so the remaining five squares will be painted black.

Sample Input 2

19
100

Sample Output 2

261

Sample Input 3

10
0

Sample Output 3

100

As zero squares will be painted white, all the squares will be painted black.


'use strict';

const main = arg => {

    const input = arg.split("\n");
    const n = parseInt(input[0]);

    let freq = new Map();
    for (let i = 0; i < n; i++) {
        const a = parseInt(input[i + 1].trim());
        if (freq.has(a)) {
            freq.set(a, freq.get(a) + 1);
        } else {
            freq.set(a, 1);
        }
    }

    let count = 0;
    for (const [key, value] of freq.entries()) {
        if (value % 2 == 1) {
            count++;
        }
    }
    console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 300 points

Problem Statement

You are playing the following game with Joisino.

Initially, you have a blank sheet of paper.

Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.

Then, you are asked a question: How many numbers are written on the sheet now?

The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?

Constraints

1≤N≤100000

1≤A_i≤1000000000(=10^9)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print how many numbers will be written on the sheet at the end of the game.

Sample Input 1

3
6
2
6

Sample Output 1

1

The game proceeds as follows:

6 is not written on the sheet, so write 6.

2 is not written on the sheet, so write 2.

6 is written on the sheet, so erase 6.

Thus, the sheet contains only 2 in the end. The answer is 1.

Sample Input 2

4
2
5
5
2

Sample Output 2

0

It is possible that no number is written on the sheet in the end.

Sample Input 3

6
12
22
16
22
18
12

Sample Output 3

2


function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,5);
  input.shift();
  var umu = [];
  var count = {};
  var output = 0;
  for(var i = 0; i < input.length; i++){
    if(count[input[i]] == null){
       umu.push(input[i]);
      count[input[i]] = 1;
    }else{
      count[input[i]]++;
    }
  }

  for(var i = 0; i < umu.length; i++){
    if(count[umu[i]] % 2 == 1){
       output++;
    }
  }
  myout(output);
}

Main(myin());


"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function main(input) {
  const a = input.split("\n").map(Number).slice(1);

  const map = new Map();

  a.forEach(e => {
    if(map.has(e)) {
      map.delete(e);
    } else {
      map.set(e, true);
    }
  });

  const ans = map.size;
  console.log(ans);
}


"use strict"

const X = parseInt(process.argv[2]);
const t = parseInt(process.argv[3]);

const ans = X > t ? X - t : 0

console.log(ans);

Score : 100 points

Problem Statement

We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.

How many grams of sand will the upper bulb contains after t seconds?

Constraints

1≤X≤10^9

1≤t≤10^9

X and t are integers.

Input

The input is given from Standard Input in the following format:

X t

Output

Print the number of sand in the upper bulb after t second.

Sample Input 1

100 17

Sample Output 1

83

17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.

Sample Input 2

48 58

Sample Output 2

0

All 48 grams of sand will be gone, resulting in 0 grams.

Sample Input 3

1000000000 1000000000

Sample Output 3

0


function Main(input) {
	input = input.trim().split(" ").map((a)=>Number(a));
  var a = Math.abs(input[0] - input[1]);
  var b = Math.abs(input[0] - input[2]);
  if(a > b){
     console.log("B");
     }else{
     console.log("A");
     }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

Snuke lives at position x on a number line.
On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.

Snuke decided to get food delivery from the closer of stores A and B.
Find out which store is closer to Snuke's residence.

Here, the distance between two points s and t on a number line is represented by |s-t|.

Constraints

1 \leq x \leq 1000

1 \leq a \leq 1000

1 \leq b \leq 1000

x, a and b are pairwise distinct.

The distances between Snuke's residence and stores A and B are different.

Input

Input is given from Standard Input in the following format:

x a b

Output

If store A is closer, print A; if store B is closer, print B.

Sample Input 1

5 2 7

Sample Output 1

B

The distances between Snuke's residence and stores A and B are 3 and 2, respectively.
Since store B is closer, print B.

Sample Input 2

1 999 1000

Sample Output 2

A


"use strict"

const main = arg => {
  arg = arg.trim().split("\n");
  const N = parseInt(arg[0]);
  const A = arg[1].split(" ").map(n=>parseInt(n)).sort((a,b)=>a-b);

  let pairNums = [];

  for(let i in A) {
      if(A[i] === A[parseInt(i) + 1]) {
        pairNums.push(A[i]);
      }
  }

  pairNums.sort((a,b)=>b-a);
  const set = new Set(pairNums);

  if([...set].length === 1) {
      console.log([...set][0] * [...set][0]);
      return;
  }

  console.log(pairNums.length ? [...set][0] * [...set][1] : 0);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

We have N sticks with negligible thickness.
The length of the i-th stick is A_i.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0.

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20


Score : 400 points

Problem Statement

We have a board with a 2 \times N grid.
Snuke covered the board with N dominoes without overlaps.
Here, a domino can cover a 1 \times 2 or 2 \times 1 square.

Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoes that are adjacent by side should be painted by different colors.
Here, it is not always necessary to use all three colors.

Find the number of such ways to paint the dominoes, modulo 1000000007.

The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner:

Each domino is represented by a different English letter (lowercase or uppercase).

The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

Constraints

1 \leq N \leq 52

|S_1| = |S_2| = N

S_1 and S_2 consist of lowercase and uppercase English letters.

S_1 and S_2 represent a valid arrangement of dominoes.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2

Output

Print the number of such ways to paint the dominoes, modulo 1000000007.

Sample Input 1

3
aab
ccb

Sample Output 1

6

There are six ways as shown below:

Sample Input 2

1
Z
Z

Sample Output 2

3

Note that it is not always necessary to use all the colors.

Sample Input 3

52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

Sample Output 3

958681902


let n = require("fs").readFileSync("/dev/stdin", "utf8");
console.log(n[0] == n[2] ? "Yes" : "No");

Score : 100 points

Problem Statement

You are given a three-digit positive integer N.

Determine whether N is a palindromic number.

Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.

Constraints

100≤N≤999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is a palindromic number, print Yes; otherwise, print No.

Sample Input 1

575

Sample Output 1

Yes

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

Sample Input 2

123

Sample Output 2

No

N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.

Sample Input 3

812

Sample Output 3

No


function calc(startA, endA, startB, endB) {
    if (startA <= startB) {
        if (endA <= startB) {
            return 0;
        }
        if (endB <= endA) {
            return endB - startB;
        }
        return endA - startB;
    }
    return calc(startB, endB, startA, endA);
}

function Main(inp) {
    var input = inp.split('\n')[0].split(' ').map(function(n) {
        return Number(n);
    });
    console.log(calc(input[0], input[1], input[2], input[3]));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

function main(s) {

  const str = s.split('\n')[0];
  const rev = str.split('').reverse().join('');

  const ans = (str === rev) ? 'Yes' : 'No';

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    var input = input.split('');
    if(input[0] === input[2]) {
        console.log('Yes');
    } else {
        console.log('No');
    }

    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
	var input = input.split(" ");
  	var n=0;
	for(i=input[0];i<=input[1];i++){
      if(i>=input[2]&&i<=input[3]){
        n++;
      }
    }
  //if(){}

  console.log(n-1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

Alice and Bob are controlling a robot. They each have one switch that controls the robot.

Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.

Bob started holding down his button C second after the start-up, and released his button D second after the start-up.

For how many seconds both Alice and Bob were holding down their buttons?

Constraints

0≤A<B≤100

0≤C<D≤100

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.

Sample Input 1

0 75 25 100

Sample Output 1

50

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.

Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.

Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

Sample Input 2

0 33 66 99

Sample Output 2

0

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.

Sample Input 3

10 90 20 80

Sample Output 3

60


log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = lines[0].split(" ").map(Number)[0];
var T = lines
  .slice(1)
  .filter(v => v !== "")
  .map(Number);

function gcd(a,b){
  if(b === 0) return a
  return gcd(b,a % b)
}

function lcm(a,b){
  return a * b / gcd(a,b)
}

for(var i=1; i<N;i++){
  T[i] = lcm(T[i],T[i-1])
}

log(T[N-1].toFixed())

Score : 300 points

Problem Statement

We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds.

Initially, the hand of every clock stands still, pointing directly upward.

Now, Dolphin starts all the clocks simultaneously.

In how many seconds will the hand of every clock point directly upward again?

Constraints

1≤N≤100

1≤T_i≤10^{18}

All input values are integers.

The correct answer is at most 10^{18} seconds.

Input

Input is given from Standard Input in the following format:

N
T_1
:
T_N

Output

Print the number of seconds after which the hand of every clock point directly upward again.

Sample Input 1

2
2
3

Sample Output 1

6

We have two clocks. The time when the hand of each clock points upward is as follows:

Clock 1: 2, 4, 6, ... seconds after the beginning

Clock 2: 3, 6, 9, ... seconds after the beginning

Therefore, it takes 6 seconds until the hands of both clocks point directly upward.

Sample Input 2

5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

1000000000000000000


function gcd( m, n ) {
  //  m > n
  var tmp;
  while( n != 0 ) {
     if( n == 0 )  {
       return m;
     } else {
         tmp = m % n;
         m = n;
         n = tmp;
     }
  }
}

function Main(input) {
  var N = parseInt(input[0],10);
  var a,b,c;
  var mul = 1;
  a = parseInt(input[1],10);
  mul *= a;
  c = a;
  if( N >= 2 ) {
    b = parseInt(input[2],10);
    mul *= b;
    if( a > b ) {
        c = gcd( a, b);
    } else {
        c = gcd( b, a);
    }
  }
  for( var i = 3; i < N ; i++){
     b = parseInt(input[i], 10);
     mul *= b;
     if( c != 1 ) {
         c = gcd( b , c );
     }
  }
  console.log("%d", mul / c );
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var m = parseInt(line[0]);
    var n = parseInt(line[1]);

    var ans = (m-1)*(n-1);
    console.log(ans);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?

Constraints

2 ≤ n, m ≤ 100

Input

Input is given from Standard Input in the following format:

n m

Output

Print the number of blocks in K-city.

Sample Input 1

3 4

Sample Output 1

6

There are six blocks, as shown below:

Sample Input 2

2 2

Sample Output 2

1

There are one block, as shown below:


( input => {
  console.log(input[0] + (input.length - 2) + input[input.length - 1])
})(require("fs").readFileSync("/dev/stdin", "utf8"))

Score : 200 points

Problem Statement

The word internationalization is sometimes abbreviated to i18n.
This comes from the fact that there are 18 letters between the first i and the last n.

You are given a string s of length at least 3 consisting of lowercase English letters.
Abbreviate s in the same way.

Constraints

3 ≤ |s| ≤ 100 (|s| denotes the length of s.)

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the abbreviation of s.

Sample Input 1

internationalization

Sample Output 1

i18n

Sample Input 2

smiles

Sample Output 2

s4s

Sample Input 3

xyz

Sample Output 3

x1z


const fs = require("fs");

const word = fs.readFileSync(0).toString().trim();
const length = word.length;
process.stdout.write(`${word[0]}${length - 2}${word[length - 1]}\n`);


function Main(input){
  var a = input.substr(0,1);
  var b = input.substr(-2);
  console.log(a+(input.length-2)+b);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0]);
  tmp = input[1].split(" ");
  a=new Array(n).fill(0);
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
  }
  var odd=0;
  var four=0;
  for(i=0;i<n;i++){
    if(a[i]%2==1){
      odd++;
    }else if(a[i]%4==0){
      four++;
    }
  }
  var ans="No";
  if(odd==0){
    ans="Yes";
  }else if(odd-four<=0){
    ans="Yes";
  }else if(n==3&&odd-four<=1&&four>0){
    ans="Yes";
  }else if(n%2==1&&odd-four<=1){
    ans="Yes";
  }
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 400 points

Problem Statement

We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


function Main(input) {
  var n = Number(input)
  var ans = 1;
  while(ans <= n) {
    ans *= 2;
  }
  ans /= 2;
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

Takahashi loves numbers divisible by 2.

You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.

Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.

For example,

6 can be divided by 2 once: 6 -> 3.

8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.

3 can be divided by 2 zero times.

Constraints

1 ≤ N ≤ 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

7

Sample Output 1

4

4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.

Sample Input 2

32

Sample Output 2

32

Sample Input 3

1

Sample Output 3

1

Sample Input 4

100

Sample Output 4

64


function Main(input) {
  var x = input;
  if(x == 2){
  	x = 2;
  } else if(x >= 2 && x < 4) {
 	x = 2
  } else if(x >= 4 && x < 8) {
 	x = 4
  } else if(x >= 8 && x < 16) {
 	x = 8
  } else if(x >= 16 && x < 32) {
 	x = 16
  } else if(x >= 32 && x < 64) {
 	x = 32
  } else if(x >= 64  && x < 128) {
 	x = 64
  }

  console.log(x);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
	var n = input.split("\n");
	//comparing
	var two = 1;
	while(!(two <= n && n < two * 2)){
		two *= 2;
	}
	//出力
	console.log(two);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  	input = input.trim();
	var N = input.split("\n")[0].split(" ")[0];
  	var M = input.split("\n")[0].split(" ")[1];
  	var oneList = new Set();//1から行けるところのリスト
  	var NList = new Set();//Nから行けるところのリスト
  for(var i = 1; i <= M; i++){
    var tmp = input.split("\n")[i].split(" ").map((tmp)=>Number(tmp));
    if(tmp[0] == "1"){
       oneList.add(tmp[1]);
    }
    if(tmp[1] == N){
       NList.add(tmp[0]);
    }
  }
  if(oneList.length == 0 || NList.length == 0){
     console.log("IMPOSSIBLE");
  }else{
    for(i = 2; i < N; i++){
      if(oneList.has(i) != -1 && NList.has(i) != -1){
         	console.log("POSSIBLE");
        return;
      }
    }
    console.log("IMPOSSIBLE");
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.
For convenience, we will call them Island 1, Island 2, ..., Island N.

There are M kinds of regular boat services between these islands.
Each service connects two islands. The i-th service connects Island a_i and Island b_i.

Cat Snuke is on Island 1 now, and wants to go to Island N.
However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.

Help him.

Constraints

3 ≤ N ≤ 200 000

1 ≤ M ≤ 200 000

1 ≤ a_i < b_i ≤ N

(a_i, b_i) \neq (1, N)

If i \neq j, (a_i, b_i) \neq (a_j, b_j).

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

POSSIBLE

Sample Input 2

4 3
1 2
2 3
3 4

Sample Output 2

IMPOSSIBLE

You have to use three boat services to get to Island 4.

Sample Input 3

100000 1
1 99999

Sample Output 3

IMPOSSIBLE

Sample Input 4

5 5
1 3
4 5
2 3
2 4
1 4

Sample Output 4

POSSIBLE

You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.


function Main(input) {
  	input = input.trim();
	var N = input.split("\n")[0].split(" ")[0];
  	var M = input.split("\n")[0].split(" ")[1];
  	var oneList = [];//1から行けるところのリスト
  	var NList = [];//Nから行けるところのリスト
  for(var i = 1; i <= M; i++){
    var tmp = input.split("\n")[i].split(" ");
    if(tmp[0] == "1"){
       oneList.push(tmp[1]);
    }
    if(tmp[1] == N){
       NList.push(tmp[0]);
    }
  }
  if(oneList.length == 0 || NList.length == 0){
     console.log("IMPOSSIBLE");
  }else{
    var check = oneList.concat(NList);
    check = check.filter(function (x, i, self) {
            return self.indexOf(x) === i && i !== self.lastIndexOf(x);
        });
    console.log((check.length != 0) ? "POSSIBLE" : "IMPOSSIBLE");
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);

    const ab = arg.slice(1, M + 1);

    let map = [...Array(N)].fill(0);
    let answer = "IMPOSSIBLE";

    for(let i=0; i<M; i++) {
        let temp = ab[i].split(" ").map(n=>parseInt(n));
        let from = temp[0];
        let to   = temp[1];

        if(from === 1) {
            if(map[to] === N) {
                answer = "POSSIBLE";
                break;
            } else {
                map[to]++;
            }
        }

        if(to === N) {
            if(map[from] === 1) {
                answer = "POSSIBLE";
                break;
            } else {
                map[from]++;
            }
        }
    }

    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
  input = input.split("\n");
  var k = parseInt(input[0]);
  ans=k+"\n"
  for(i=0;i<k;i++){
    var x =k-i;
    if(i!=k-1){
    ans+=x+" ";
    }else{
      ans+=x;
    }
  }
  if(k==0){
    ans="2\n1 1";
  }else if(k==1){
    ans="2\n1 2";
  }

  console.log('%s', ans);
}

// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller.

Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.

You are given an integer K. Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.

Constraints

0 ≤ K ≤ 50 \times 10^{16}

Input

Input is given from Standard Input in the following format:

K

Output

Print a solution in the following format:

N
a_1 a_2 ... a_N

Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.

Sample Input 1

0

Sample Output 1

4
3 3 3 3

Sample Input 2

1

Sample Output 2

3
1 0 3

Sample Input 3

2

Sample Output 3

2
2 2

The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].

Sample Input 4

3

Sample Output 4

7
27 0 0 0 0 0 0

Sample Input 5

1234567894848

Sample Output 5

10
1000 193 256 777 0 1 1192 1234567891011 48 425


"use strict";

const main = arg => {
    const prices = arg.split("\n")[0].split(" ").map(n=>parseInt(n));

    console.log(prices.sort((a,b)=>a-b).slice(0,2).reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.

He has very high awareness of safety, and decides to buy two bells, one for each hand.

The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.
Find the minimum total price of two different bells.

Constraints

1 \leq a,b,c \leq 10000

a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print the minimum total price of two different bells.

Sample Input 1

700 600 780

Sample Output 1

1300

Buying a 700-yen bell and a 600-yen bell costs 1300 yen.

Buying a 700-yen bell and a 780-yen bell costs 1480 yen.

Buying a 600-yen bell and a 780-yen bell costs 1380 yen.

The minimum among these is 1300 yen.

Sample Input 2

10000 10000 10000

Sample Output 2

20000

Buying any two bells costs 20000 yen.


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
(function Main(input) {
  var money = input.split(/\s+/);
  for(var i = 0; i < money.length; i++) {
  money[i] = parseInt(money[i], 10);
  }
  var max = Math.max(money[0], money[1], money[2]);
  console.log('%d', money[1]+money[2]+money[3] - max);
})(input);


process.stdin.setEncoding( 'utf8' );

process.stdin.on( 'readable', function() {
    var chunk = process.stdin.read();
    var inputLineArr;

    if ( chunk !== null ) {
        inputLineArr = chunk.split('\n');

        if( inputLineArr[inputLineArr.length-1] == '' )
            inputLineArr.pop();

        var num = inputLineArr[0].split(' ').map( function( elem ) {
            return parseInt( elem );
        } );

        var a = num[0] + num[1],
            b = num[1] + num[2],
            c = num[2] + num[0];

        console.log( Math.min( a, b, c ) );
    }
} );


function Main(input){
	input = input.split("");
	input.pop();
	if(input.length%2==1) input.pop();
	var ans = 2;
	while(input.length!=0){
	  //  console.log(input.join(""))
	   // console.log(input.join("").substr(input.length/2),input.join("").substr(-1*(input.length/2)))
		if(input.join("").substr(0,input.length/2)==input.join("").substr(input.length/2)){
			ans = input.length;
			break;
		}else{
			input.pop();
			input.pop();
		}
	}
	console.log(ans)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Score : 200 points

Problem Statement

We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.

You are given an even string S consisting of lowercase English letters.
Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S.
It is guaranteed that such a non-empty string exists for a given input.

Constraints

2 \leq |S| \leq 200

S is an even string consisting of lowercase English letters.

There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.

Input

Input is given from Standard Input in the following format:

S

Output

Print the length of the longest even string that can be obtained.

Sample Input 1

abaababaab

Sample Output 1

6

abaababaab itself is even, but we need to delete at least one character.

abaababaa is not even.

abaababa is not even.

abaabab is not even.

abaaba is even. Thus, we should print its length, 6.

Sample Input 2

xxxx

Sample Output 2

2

xxx is not even.

xx is even.

Sample Input 3

abcabcabcabc

Sample Output 3

6

The longest even string that can be obtained is abcabc, whose length is 6.

Sample Input 4

akasakaakasakasakaakas

Sample Output 4

14

The longest even string that can be obtained is akasakaakasaka, whose length is 14.


var s = require("fs").readFileSync("/dev/stdin", "utf8")

	while(s.length) {

		s = s.slice(0, -1)
		l = s.length

		if(l%2 == 0) {
			if(s.slice(0, l/2) == s.slice(l/2)) {
				console.log(l)
				return;
			}
		}

	}