console.log((args=>{
  const [N,...A] = args.trim().split`\n`.map(v=>v|0);
  const ex = new Map();
  for ( let i = 0; i < N; i++ ) ex.set( A[i], ex.get(A[i])^1 );
  let s = 0;
  for ( const [,v] of ex ) s += v;
  return `${s}`;
})(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


#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return f?x:-x;
}
std::map<int, bool> mp;
int main(int argc, char const *argv[]) {
	int n = read(), ans = 0;
	for (int i = 1; i <= n; i++) {
		int x = read();
		if (mp[x]) ans --, mp[x] = 0;
		else       ans ++, mp[x] = 1;
	}
	printf("%d\n", ans);
	return 0;
}

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

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.


"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const n = nextInt()
    const a = nextIntArray()
    let m = {}
    let maxVal = 0
    for(let val of a){
        if(!m[val]) m[val] = 1
        else m[val]++
        maxVal = Math.max(maxVal, val)
    }
    let cnt = {}

    for(let i = 0; i<= maxVal; i++){
        let curr = m[i] ? m[i] : 0
        let prev = m[i-1]? m[i-1] : 0
        let next = m[i+1]? m[i+1] : 0
        cnt[i] = curr + prev + next
    }
    let ans = 1
    for(let key of Object.keys(cnt)){
        ans = Math.max(ans, cnt[key])
    }
    console.log(ans)
}
Main()

Score : 300 points

Problem Statement

You are given an integer sequence of length N, a_1,a_2,...,a_N.

For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.

After these operations, you select an integer X and count the number of i such that a_i=X.

Maximize this count by making optimal choices.

Constraints

1≤N≤10^5

0≤a_i<10^5 (1≤i≤N)

a_i is an integer.

Input

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

N
a_1 a_2 .. a_N

Output

Print the maximum possible number of i such that a_i=X.

Sample Input 1

7
3 1 4 1 5 9 2

Sample Output 1

4

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.

Sample Input 2

10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

3

Sample Input 3

1
99999

Sample Output 3

1


"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);

    const set = new Set();

    let max = 0;

    for(let i=0; i<N; i++) {
        let cnt = 0;

        if(set.has(a[i])) {
            continue;
        }

        set.add(a[i]);

        for(let j=0; j<N; j++) {
            if(Math.abs(a[j] - a[i]) <= 1) {
                cnt++;
            }
        }

        if(cnt > max) {
            max = cnt;
        }
    }

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


"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);

  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


"use strict";

function main(input) {
  input = input.split(" ");
  input[0] = parseInt(input[0]);
  input[1] = parseInt(input[1]);
  input[2] = parseInt(input[2]);
  input[3] = parseInt(input[3]);
  let a;
  let b;
  if (input[1] > input[3]) {
    a = input[3];
  } else {
    a = input[1];
  }
  if (input[0] > input[2]) {
    b = input[0];
  } else {
    b = input[2];
  }
  if (a > b) {
    console.log(String(Math.abs(b - a)));
  } else {
    console.log("0");
  }
}

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

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


function main(input){
    var num = input.split(" ");
    for(var i=0; i<num.length; i++){
        num[i] = Number(num[i]);
    }
    if(num[0]<=num[2]){
        if(num[2]>=num[1]){
            console.log(0);
        }else if(num[1]<=num[3]){
            console.log(num[1]-num[2]);
        }else{
            console.log(num[3]-num[2]);
        }
    }else{
        if(num[0]>=num[3]){
            console.log(0);
        }else if(num[3]<=num[1]){
            console.log(num[3]-num[0]);
        }else{
            console.log(num[1]-num[0]);
        }
    }
}

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


"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
function gcd(m, n) {
    return n != 0n ? gcd(n, m % n) : m;
}

function lcm(m, n) {return m * n / gcd(m,n)}

const Main = () => {
    const n = nextInt()
    while(hasNext()){
        t.push(BigInt(nextInt()))
    }
    let ans = t[0]
    for(let v of s.values()){
        ans = lcm(ans, v)
    }
    console.log(Number(ans))
}
Main()

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(a,b){
    if(b==0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

function lcm(a,b){
    var g = gcd(a,b);
    return a*b/g;
}

function main(input){
    var num = input.split(/\r\n|\r|\n/);
    for (var i = 0; i<num.length; i++){
        num[i] = Number(num[i]);
    }
    if(num.length==2){
        console.log(num[1]);
    }else{
        var res = lcm(num[1], num[2]);
        for(var i=3; i<num.length; i++){
            res = lcm(res, num[i]);
        }
        console.log(res);
    }

}

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


'use strict'

function main(input) {
  input = `${input.slice(0, 1)}${input.length - 2}${input.slice(-1)}`
  console.log(input)
}
main(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


function Main(input) {
  const number = input.split("");
  const middleNumber = input.substract(1, number.length-2);
  console.log("number[1]" + middleNumber.length + "number[number.length-1]");
}

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


function Main(input) {
        console.log("s"+(input.length-2)+"s");
}

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


function Main(input) {
	var cText = input.length;
	var sText = input.substr(0,1);
	var eText = input.substr(input.length-1,1);
        var n = sText+cText+eText;
	//出力
	console.log('%s\n',n);
}

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


var readline = require('readline');
var a = readline();
console.log("ABC" + a);

Score : 100 points

Problem Statement

This contest, AtCoder Beginner Contest, is abbreviated as ABC.

When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.

What is the abbreviation for the N-th round of ABC? Write a program to output the answer.

Constraints

100 ≤ N ≤ 999

Input

Input is given from Standard Input in the following format:

N

Output

Print the abbreviation for the N-th round of ABC.

Sample Input 1

100

Sample Output 1

ABC100

The 100th round of ABC is ABC100.

Sample Input 2

425

Sample Output 2

ABC425

Sample Input 3

999

Sample Output 3

ABC999


"use strict";

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

const main = input => {
  const N = input[0]
  const ans = `ABC${N}`
  console.log(ans)
};

main(receive);


'use strict'

function main(input) {
  const n = Number(input)
  let ans = 0
  let tmpmax = 0
  if (n == 1) {
    console.log(1)
    return
  }
  for (let i = 1; i <= n; i++) {
    if (i % 2 > 0) {
      continue
    } else {
      //何回割り切れるか
      let j = i
      let cnt = 0
      while (j % 2 == 0) {
        cnt++
        j = j / 2
      }
      if (tmpmax < cnt) {
        tmpmax = cnt
        ans = i
      }
    }
  }

  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


"use strict";

function Main(input) {
  const n = parseInt(input, 10);
  const nums = [64, 32, 16, 8, 4, 2, 1];

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


'use strict'
function Main(input) {
    input = input.split("\n");
    const n = parseInt(input[0], 10)
    const arr = input[1].split(' ').map(v => parseInt(v, 10))
    const sum = arr.reduce((pre, cur) => pre + cur)
    let min = -1
    let tmp = 0
    for (let i = 0; i < n - 1; i ++) {
        tmp += arr[i]
        const abs = Math.abs(sum - 2 * tmp)
        if (min < 0 || min > abs) {
            min = abs
        }
    }
    console.log(min)
}

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

Score : 300 points

Problem Statement

Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.

They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.

Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

Constraints

2 \leq N \leq 2 \times 10^5

-10^{9} \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 answer.

Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

Sample Input 2

2
10 -10

Sample Output 2

20

Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20.


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]);
  var x = 0;

  for (var i = 0; i < money.length; i++) {
    if (money[i] != max) { x += money[i];}
  }
  console.log(x);
})(input);

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.


"use strict"

function main(input) {

    input = input.split('')
    for (let i = input.length - 2; i > 0; i--) {
        if (i % 2 == 0) {
            let a = input.slice(0, i / 2).join('')
            let b = input.slice(i / 2, i).join('')
            // console.log(a, b)
            if (a == b) {
                console.log(i)
                return
            }
        }

    }

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

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.


'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n")[0].split(" ");
    const X = parseInt(input[0], 10);
    if (parseInt(input[1], 10) >= parseInt(input[2], 10)) {
        console.log("delicious");
    } else {
        const day = Math.abs(parseInt(input[1], 10) - parseInt(input[2], 10));
        console.log(X > day ? "safe" : "dangerous");
    }
}

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

Score : 100 points

Problem Statement

Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier.
He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.

Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.

Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.

Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.

Constraints

1 ≤ X,A,B ≤ 10^9

Input

Input is given from Standard Input in the following format:

X A B

Output

Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.

Sample Input 1

4 3 6

Sample Output 1

safe

He ate the food three days after the "best-by" date. It was not delicious or harmful for him.

Sample Input 2

6 5 1

Sample Output 2

delicious

He ate the food by the "best-by" date. It was delicious for him.

Sample Input 3

3 7 12

Sample Output 3

dangerous

He ate the food five days after the "best-by" date. It was harmful for him.


"use strict";

var main = function main(input) {
  var args = input.split('\n');
  var N = parseInt(args[0], 10);
  var a = [];

  for (var i = 1; i <= N; i++) {
    a.push(parseInt(args[i], 10));
  }

  var start = a[0];
  var next = a[a[0] - 1];
  var flag = false;
  var count = 0;

  while (start != next) {
    count++;

    if (next == 2) {
      flag = true;
      break;
    }

    next = a[next - 1];
  }

  if (flag) {
    console.log(count + 1);
  } else {
    console.log(-1);
  }
};

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

Score : 200 points

Problem Statement

Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.

The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.
These buttons are numbered 1 through N.
When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.
When Button i is not lighten up, nothing will happen by pressing it.

Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.

Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

Constraints

2 ≤ N ≤ 10^5

1 ≤ a_i ≤ N

Input

Input is given from Standard Input in the following format:

N
a_1
a_2
:
a_N

Output

Print -1 if it is impossible to lighten up Button 2.
Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.

Sample Input 1

3
3
1
2

Sample Output 1

2

Press Button 1, then Button 3.

Sample Input 2

4
3
4
1
2

Sample Output 2

-1

Pressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.

Sample Input 3

5
3
3
4
2
4

Sample Output 3

3


"use strict";
function Main(input) {
  input = input.split("\n");
  const person = input[1].split(" ");
  let rates = [];

  for(let i=0; i < 9; i++){
    rates[i] = 0;
  }

  for(let personCount=0; personCount < person.length; personCount++){
    let inputValue = parseInt(person[personCount], 10);
    if(1 <= inputValue && inputValue < 400){
      rates[0] = 1;
    }
    else if(400 <= inputValue && inputValue < 800){
      rates[1] = 1;
    }
	else if(800 <= inputValue && inputValue < 1200){
      rates[2] = 1;
	}
	else if(1200 <= inputValue && inputValue < 1600){
      rates[3] = 1;
	}
	else if(1600 <= inputValue && inputValue < 2000){
      rates[4] = 1;
    }
    else if(2000 <= inputValue && inputValue < 2400){
      rates[5] = 1;
    }
    else if(2400 <= inputValue && inputValue < 2800){
      rates[6] = 1;
	}
	else if(2800 <= inputValue && inputValue < 3200){
      rates[7] = 1;
    }
    else if(3200 <= inputValue && inputValue <= 4800){
      rates[8] += 1;
    }
  }

  let  color = 0;
  for(let colorCount=0; colorCount < 8; colorCount++){
    color += rates[colorCount];
  }

  let max = color + rates[8];
  let min = color;

  if(color === 0 && rates[8] > 0){
    min = 1;
  }
  console.log(min,max);
}

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

Score : 100 points

Problem Statement

AtCoDeer has three cards, one red, one green and one blue.

An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.

We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.

Is this integer a multiple of 4?

Constraints

1 ≤ r, g, b ≤ 9

Input

Input is given from Standard Input in the following format:

r g b

Output

If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.

Sample Input 1

4 3 2

Sample Output 1

YES

432 is a multiple of 4, and thus YES should be printed.

Sample Input 2

2 3 4

Sample Output 2

NO

234 is not a multiple of 4, and thus NO should be printed.


function Main(input) {
	input = input.split("\n")[1].split(" ");
  var max, min;
  var count = [0, 0, 0, 0, 0, 0, 0, 0, 0];
  for (val in input) {
    var n = parseInt(input[val], 10);
    var q = Math.floor(n / 400);
    count[q]++;
  }
  var nonZero = 0;
  for (var i=0; i<8; i++) {
    if (count[i] != 0) nonZero++;
  }
  min = math.min(nonZero, 1);
  max = nonZero+count[8];

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

Score : 300 points

Problem Statement

In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:

Rating 1-399 : gray

Rating 400-799 : brown

Rating 800-1199 : green

Rating 1200-1599 : cyan

Rating 1600-1999 : blue

Rating 2000-2399 : yellow

Rating 2400-2799 : orange

Rating 2800-3199 : red

Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.

Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.

Find the minimum and maximum possible numbers of different colors of the users.

Constraints

1 ≤ N ≤ 100

1 ≤ a_i ≤ 4800

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 minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.

Sample Input 1

4
2100 2500 2700 2700

Sample Output 1

2 2

The user with rating 2100 is "yellow", and the others are "orange". There are two different colors.

Sample Input 2

5
1100 1900 2800 3200 3200

Sample Output 2

3 5

The user with rating 1100 is "green", the user with rating 1900 is blue and the user with rating 2800 is "red".

If the fourth user picks "red", and the fifth user picks "blue", there are three different colors. This is one possible scenario for the minimum number of colors.

If the fourth user picks "purple", and the fifth user picks "black", there are five different colors. This is one possible scenario for the maximum number of colors.

Sample Input 3

20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990

Sample Output 3

1 1

All the users are "green", and thus there is one color.


process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.on('data', function(chunk){
    var lines = chunk.toString().split("\n");
    var N = parseInt(lines[0],10);
//レート3200未満の人達の色の数を調べるため配列作成
    var Ary =new Array(8);
    Ary.fill(0);
//  3200以上の選べる人たち
    var rate_ab3200 = 0;
    var  N_color =0; //色の種類

//各色の人数を把握する    >=400 && rate<800
    var rate_all = lines[1].split(" ");

/*
   for(i=0; i<N; i++){
       console.log(rate_all[i]);
   }
*/
   for(i=0; i<N; i++){
       var rate =parseInt(rate_all[i],10);
       if(rate < 400){
           Ary[0]++;
           }else if(rate>=400 && rate<800){
             Ary[1]++;
              }else if(rate>=800 && rate<1200){
                    Ary[2]++;
                    }else if(rate>=1200 && rate<1600){
                        Ary[3]++;
                        }else if(rate>=1600 && rate<2000){
                            Ary[4]++;
                            }else if(rate>=2000 && rate<2400){
                                Ary[5]++;
                                }else if(rate>=2400 && rate<2800){
                                    Ary[6]++;
                                    }else if(rate>=2800 && rate<3200){
                                        Ary[7]++;
                                        }else{
                                            rate_ab3200++;
                                            }
   }

    //        console.log(Ary);
    //        console.log(rate_ab3200);

//色の数(3200未満の人々)
    for(i=0; i<8; i++){
        if(Ary[i] >0){
            N_color++;
        }
    }

    //       console.log(N_color);
 //3200以上の人が8人以上の場合

    if(rate_ab3200>=8){
        console.log(N_color+" "+8);
//200以上の人が8人未満の場合
    }else{
//3200未満の色数が0の時、そうでないとき
        if(N_color === 0){
            console.log(1+" "+rate_ab3200);
        }else{
//3200以上の人数人数とい3200未満の色数が8以上の時、そうでないとき
            if(rate_ab3200+N_color>=8){
                console.log(N_color+" "+8);
            }else{
                console.log(N_color+" "+(rate_ab3200+N_color));
            }
        }
    }

    });


'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const a = s[0];
  const b = s[1];

  const sum = a + b;

  const ans = (sum < 10) ? sum : 'error';

  console.log(ans);
}

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

Score : 100 points

Problem Statement

You are given two integers A and B as the input. Output the value of A + B.

However, if A + B is 10 or greater, output error instead.

Constraints

A and B are integers.

1 ≤ A, B ≤ 9

Input

Input is given from Standard Input in the following format:

A B

Output

If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.

Sample Input 1

6 3

Sample Output 1

9

Sample Input 2

6 4

Sample Output 2

error


console.log((args=>{
  const [N,...s] = args.trim().split`\n`.map(v=>v|0);
  const dp = Array.from({length:N+1},_=>Array(10).fill(-Infinity));
  dp[0][0] = 0;
  for ( let i = 0; i < N; i++ ) {
    for ( let j = 0; j < 10; j++ ) {
      const d = (j+s[i]) % 10;
      dp[i+1][d] = Math.max( dp[i][d], dp[i][j] + s[i] );
    }
  }
  dp[N][0] = 0;
  return `${Math.max(...dp[N])}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));

Score : 300 points

Problem Statement

You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.

However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?

Constraints

All input values are integers.

1 ≤ N ≤ 100

1 ≤ s_i ≤ 100

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the maximum value that can be displayed as your grade.

Sample Input 1

3
5
10
15

Sample Output 1

25

Your grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.

Sample Input 2

3
10
10
15

Sample Output 2

35

Your grade will be 35 if all the questions are answered correctly, and this grade will be displayed correctly.

Sample Input 3

3
10
20
30

Sample Output 3

0

Regardless of whether each question is answered correctly or not, your grade will be a multiple of 10 and displayed as 0.


'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n")[0].split(" ");
    const x = parseInt(input[0], 10);
    const y = parseInt(input[1], 10);
    const a = [1, 3, 5, 7, 8, 10, 12];
    const b = [4, 6, 9, 11];

    if ((x == 2 && x == y) || (a.indexOf(x) >= 0 && a.indexOf(y)) || (b.indexOf(x) >= 0 && b.indexOf(y))) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}

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

Score : 100 points

Problem Statement

Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.
Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.

Constraints

x and y are integers.

1 ≤ x < y ≤ 12

Input

Input is given from Standard Input in the following format:

x y

Output

If x and y belong to the same group, print Yes; otherwise, print No.

Sample Input 1

1 3

Sample Output 1

Yes

Sample Input 2

2 4

Sample Output 2

No


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    const numbers = arg.slice(1, N+1);

    const map = [];

    for(let i in numbers) {
        let temp = numbers[i].split(" ").map(n=>parseInt(n));

        let number = temp[0];
        let amount = temp[1];

        map.push({number: number, amount: amount})
    }

    //map.sort((a,b)=>a.number - b.number);

    let sum = 0;
    let i   = 0;

    while(sum < K) {
        sum += map[i].amount;
        i++;
    }

    console.log(map[i - 1].number);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 300 points

Problem Statement

There is an empty array.
The following N operations will be performed to insert integers into the array.
In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.
Find the K-th smallest integer in the array after the N operations.
For example, the 4-th smallest integer in the array \{1,2,2,3,3,3\} is 3.

Constraints

1≤N≤10^5

1≤a_i,b_i≤10^5

1≤K≤b_1…+…b_n

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
a_1 b_1
:
a_N b_N

Output

Print the K-th smallest integer in the array after the N operations.

Sample Input 1

3 4
1 1
2 2
3 3

Sample Output 1

3

The resulting array is the same as the one in the problem statement.

Sample Input 2

10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000

Sample Output 2

1


'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => ~~v))
  const n = input[0][0]
  const k = input[0][1]

  let xxx = input.slice(1, input.length).sort((a, b) => {
    if (a[0] < b[0]) return -1
    if (a[0] > b[0]) return 1
    if (a[1] < b[1]) return -1
    if (a[1] > b[1]) return 1
    return 0
  })

  let stack = 0
  for (let i = 0; i < n; i++) {
    stack += xxx[i][1]

    if (stack > k) {
      console.log(xxx[i][0])
      return
    }
  }

  // console.log(xxx[0], xxx[1], xxx[2])

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


// inputに入力データ全体が入る
function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var aa = parseInt(line[0]);
    var bb = parseInt(line[1]);
    var cc = parseInt(line[2]);

    var temp = [aa,bb,cc];

    var ans = 0;

    if(aa === bb && bb === cc){
        if(aa%2===1||bb%2===1||cc%2===1){
        } else {
            ans = -1;
        }
    } else {
        while(1){
//            console.log("ans:"+ans+" a:"+aa+" b:"+bb+" c:"+cc);
          if(aa%2===1||bb%2===1||cc%2===1){
                break;
            } else {
                temp[0] = aa;
                temp[1] = bb;
                temp[2] = cc;

                aa = (temp[1]+temp[2])/2;
                bb = (temp[0]+temp[2])/2;
                cc = (temp[1]+temp[0])/2;

                ans++;
            }
        }
    }

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

Score : 300 points

Problem Statement

Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:

Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.

This action will be repeated until there is a person with odd number of cookies in hand.

How many times will they repeat this action?
Note that the answer may not be finite.

Constraints

1 ≤ A,B,C ≤ 10^9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the number of times the action will be performed by the three people, if this number is finite.
If it is infinite, print -1 instead.

Sample Input 1

4 12 20

Sample Output 1

3

Initially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,

After the first action, they have 16, 12 and 8.

After the second action, they have 10, 12 and 14.

After the third action, they have 13, 12 and 11.

Now, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.

Sample Input 2

14 14 14

Sample Output 2

-1

Sample Input 3

454 414 444

Sample Output 3

1


function Main(input) {
  input = input.trim()
  input = input.split(" ");
if(input[1].slice( 0,1 )==input[0].slice( -1 )&&input[2].slice( 0,1 )==input[1].slice( -1 )){
  console.log("YES");
}else{
  console.log("NO");
}}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

You are given three strings A, B and C. Check whether they form a word chain.

More formally, determine whether both of the following are true:

The last character in A and the initial character in B are the same.

The last character in B and the initial character in C are the same.

If both are true, print YES. Otherwise, print NO.

Constraints

A, B and C are all composed of lowercase English letters (a - z).

1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print YES or NO.

Sample Input 1

rng gorilla apple

Sample Output 1

YES

They form a word chain.

Sample Input 2

yakiniku unagi sushi

Sample Output 2

NO

A and B form a word chain, but B and C do not.

Sample Input 3

a a a

Sample Output 3

YES

Sample Input 4

aaaaaaaaab aaaaaaaaaa aaaaaaaaab

Sample Output 4

NO


'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const A = s[0];
  const B = s[1];
  const C = s[2];

  let modSet = new Set();

  for (let i = 0; i <= A * B; i++) {
    modSet.add((A * i) % B);
  }

  const answer = modSet.has(C) ? 'YES' : 'NO';
  console.log(answer);
}

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

Score : 200 points

Problem Statement

We ask you to select some number of positive integers, and calculate the sum of them.

It is allowed to select as many integers as you like, and as large integers as you wish.
You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.

Your objective is to make the sum congruent to C modulo B.
Determine whether this is possible.

If the objective is achievable, print YES. Otherwise, print NO.

Constraints

1 ≤ A ≤ 100

1 ≤ B ≤ 100

0 ≤ C < B

Input

Input is given from Standard Input in the following format:

A B C

Output

Print YES or NO.

Sample Input 1

7 5 1

Sample Output 1

YES

For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.

Sample Input 2

2 2 1

Sample Output 2

NO

The sum of even numbers, no matter how many, is never odd.

Sample Input 3

1 100 97

Sample Output 3

YES

You can select 97, since you may select multiples of 1, that is, all integers.

Sample Input 4

40 98 58

Sample Output 4

YES

Sample Input 5

77 42 36

Sample Output 5

NO


//↓見なくていいよ！ここから--------------------------------------------------
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");
  var start = new Date();
  Main();
  var end = new Date() - start;

  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return 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){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var list = nextIntArray();
	var output = Math.pow(10,15);
	if(K == 1){
		myout(0);
		return;
	}
	for(var i = 0; i < (1 << N); i++){
		var selected = [list[0]];
		for(var j = 1; j < N; j++){
			if((i & (1 << j)) != 0){
				//選ぶ
				selected.push(list[j]);
			}
		}
		if(selected.length >= K){
			var sum = 0;
			//myerr(selected);
			for(var j = 0; j < selected.length - 1; j++){
				if(selected[j] >= selected[j + 1]){
					sum += selected[j] - selected[j + 1] + 1;
					selected[j + 1] += selected[j] - selected[j + 1] + 1;
				}
			}
			output = Math.min(output, sum);
		}
	}
	myout(output);
}

Max Score: 350 Points

Problem Statement

There are N buildings along the line. The i-th building from the left is colored in color i, and its height is currently a_i meters.

Chokudai is a mayor of the city, and he loves colorful thigs. And now he wants to see at least K buildings from the left.

You can increase height of buildings, but it costs 1 yens to increase 1 meters. It means you cannot make building that height is not integer.

You cannot decrease height of buildings.

Calculate the minimum cost of satisfying Chokudai's objective.

Note: "Building i can see from the left" means there are no j exists that (height of building j) ≥ (height of building i) and j < i.

Input Format

N K
a_1 a_2 a_3 ... a_N

Output Format

Print the minimum cost in one line. In the end put a line break.

Constraints

1 ≤ K ≤ N ≤ 15

1 ≤ a_i ≤ 10^9

Scoring

Subtask 1 [120 points]

N = K

Subtask 2 [90 points]

N ≤ 5

a_i ≤ 7

Subtask 3 [140 points]

There are no additional constraints.

Sample Input 1

5 5
3949 3774 3598 3469 3424

Sample Output 1

1541

The optimal solution is (height of buildings from the left) = [3949, 3950, 3951, 3952, 3953].

Sample Input 2

5 3
7 4 2 6 4

Sample Output 2

7

The optimal solution is (height of buildings from the left) = [7, 8, 2, 9, 4].


"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const [a, b, c] = input.trim().split(" ").map(Number);
  if ((a + c) / 2 === b) {
    return "YES";
  } else {
    return "NO";
  }
};

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

Score : 100 points

Problem Statement

Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.
We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.

Determine whether the arrangement of the poles is beautiful.

Constraints

1 \leq a,b,c \leq 100

a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print YES if the arrangement of the poles is beautiful; print NO otherwise.

Sample Input 1

2 4 6

Sample Output 1

YES

Since 4-2 = 6-4, this arrangement of poles is beautiful.

Sample Input 2

2 5 6

Sample Output 2

NO

Since 5-2 \neq 6-5, this arrangement of poles is not beautiful.

Sample Input 3

3 2 1

Sample Output 3

YES

Since 1-2 = 2-3, this arrangement of poles is beautiful.


"use strict";

const fs = require("fs");

const [a, b] = fs.readFileSync(0).toString().trim().split("\n");
const result = [];
for (let i = 0, len = a.length; i < len; i++)
  result[i * 2] = a[i];
for (let i = 0, len = b.length; i < len; i++)
  result[i * 2 + 1] = b[i];
process.stdout.write(result.join("") + "\n");

Score : 200 points

Problem Statement

Snuke signed up for a new website which holds programming competitions.
He worried that he might forget his password, and he took notes of it.
Since directly recording his password would cause him trouble if stolen,
he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.

You are given two strings O and E. O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order.
Restore the original password.

Constraints

O and E consists of lowercase English letters (a - z).

1 \leq |O|,|E| \leq 50

|O| - |E| is either 0 or 1.

Input

Input is given from Standard Input in the following format:

O
E

Output

Print the original password.

Sample Input 1

xyz
abc

Sample Output 1

xaybzc

The original password is xaybzc. Extracting the characters at the odd-numbered positions results in xyz, and extracting the characters at the even-numbered positions results in abc.

Sample Input 2

atcoderbeginnercontest
atcoderregularcontest

Sample Output 2

aattccooddeerrbreeggiunlnaerrccoonntteesstt


'use strict'

const main = (input) => {
    input = input.split('\n')
    const odd = input[0].split('')
    const even = input[1].split('')

    let str = ''
    for(let i = 0; i <= even.length - 1; i++){
        str += odd[i]
        str += even[i]
    }

    if(odd.length > even.length){
        str += odd[odd.length - 1]
    }
    console.log(str)
}

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


"use strict";

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

    const alphabets = "abcdefghijklmnopqrstuvwxyz".split("");

    let map = [...Array(27)].fill(0);
    let answer = [];

    for(let i in alphabets) {
        let contains = Infinity;

        for(let j in S) {
            let cnt = S[j].split("").filter(n=>n===alphabets[i]).length;

            if(cnt > 0) {
                contains = Math.min(cnt, contains);
            } else {
                contains = 0;
                break;
            }
        }

        for(let j=0; j<contains; j++) {
            answer.push(alphabets[i]);
        }
    }

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

Score : 300 points

Problem Statement

Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.

He will receive a headline which contains one of the strings S_1,...,S_n tomorrow.
He is excited and already thinking of what string he will create.
Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.

Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains.
If there are multiple such strings, find the lexicographically smallest one among them.

Constraints

1 \leq n \leq 50

1 \leq |S_i| \leq 50 for every i = 1, ..., n.

S_i consists of lowercase English letters (a - z) for every i = 1, ..., n.

Input

Input is given from Standard Input in the following format:

n
S_1
...
S_n

Output

Print the lexicographically smallest string among the longest strings that satisfy the condition.
If the answer is an empty string, print an empty line.

Sample Input 1

3
cbaa
daacc
acacac

Sample Output 1

aac

The strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth.
Among them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac.

Sample Input 2

3
a
aa
b

Sample Output 2

The answer is an empty string.


function main(input){
  const args = input.trim().split("");
  const a = args[0],
        b = args[1];

  if (a == b)
    console.log("H");
  else
    console.log("D");
}

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

Score : 100 points

Problem Statement

Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.
In this game, an honest player always tells the truth, and an dishonest player always tell lies.
You are given two characters a and b as the input. Each of them is either H or D, and carries the following information:

If a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest.
If b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.

Given this information, determine whether TopCoDeer is honest.

Constraints

a=H or a=D.

b=H or b=D.

Input

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

a b

Output

If TopCoDeer is honest, print H. If he is dishonest, print D.

Sample Input 1

H H

Sample Output 1

H

In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.

Sample Input 2

D H

Sample Output 2

D

In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.

Sample Input 3

D D

Sample Output 3

H


// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
  　input = Number(input)
    var num = 1000000007
    var P = 1;
    for(var i=1;i<=input;i++){
      P *= i
      P %= num
    }
    console.log(P)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

Snuke loves working out. He is now exercising N times.

Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.

Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

Constraints

1 ≤ N ≤ 10^{5}

Input

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

N

Output

Print the answer modulo 10^{9}+7.

Sample Input 1

3

Sample Output 1

6

After Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.

After Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.

After Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.

Sample Input 2

10

Sample Output 2

3628800

Sample Input 3

100000

Sample Output 3

457992974

Print the answer modulo 10^{9}+7.


function main (s) {
    s=s.split(" ");
	for(var i=0;i<2;i++)s[i]=parseInt(s[i]);
	if(s[0]===s[1])console.log("Draw\n");
	else if(s[0]>s[1]||s[0]===1)console.log("Alice\n");
	else console.log("Bob\n");
}

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

Score : 100 points

Problem Statement

Alice and Bob are playing One Card Poker.

One Card Poker is a two-player game using playing cards.

Each card in this game shows an integer between 1 and 13, inclusive.

The strength of a card is determined by the number written on it, as follows:

Weak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong

One Card Poker is played as follows:

Each player picks one card from the deck. The chosen card becomes the player's hand.

The players reveal their hands to each other. The player with the stronger card wins the game.

If their cards are equally strong, the game is drawn.

You are watching Alice and Bob playing the game, and can see their hands.

The number written on Alice's card is A, and the number written on Bob's card is B.

Write a program to determine the outcome of the game.

Constraints

1≦A≦13

1≦B≦13

A and B are integers.

Input

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

A B

Output

Print Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.

Sample Input 1

8 6

Sample Output 1

Alice

8 is written on Alice's card, and 6 is written on Bob's card.
Alice has the stronger card, and thus the output should be Alice.

Sample Input 2

1 1

Sample Output 2

Draw

Since their cards have the same number, the game will be drawn.

Sample Input 3

13 1

Sample Output 3

Bob


var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var MA = one[1];
  var MB = one[2];
  var list = new Array(N);
  for(var i = 0; i < N; i++){
    list[i] = nextIntArray();
  }
  var dp = new Array(N + 1);
  var maxValue = 101;
  for(var i = 0; i < N + 1; i++){
    dp[i] = new Array(maxValue);
    for(var j = 0; j < maxValue; j++){
      dp[i][j] = new Array(maxValue);
    }
  }
  dp[0][0][0] = 0;
  //dp[i][j][k] : i個目を買い、MA合計がj、MB合計がkになる時の最小コスト
  for(var i = 1; i <= N; i++){
	for(var j = 0; j < maxValue; j++){
		for(var k = 0; k < maxValue; k++){
			if(dp[i - 1][j][k] != null){
				dp[i][j][k] = dp[i - 1][j][k];
			}
		}

	}
    var item = list[i - 1];
    for(var j = 0; j < maxValue; j++){
      for(var k = 0; k < maxValue; k++){
        //myerr({i,j,k});
        if(dp[i - 1][j][k] != null){
          if(dp[i][j + item[0]][k + item[1]] == null){
            dp[i][j + item[0]][k + item[1]] = dp[i - 1][j][k] + item[2];
          }else{
            dp[i][j + item[0]][k + item[1]] = Math.min(dp[i - 1][j][k] + item[2], dp[i][j + item[0]][k + item[1]]);
          }
        }
      }
    }
  }
	var count = 1;
	var output = 10000;
	while(true){
		var getMA = MA * count;
		var getMB = MB * count;
		if(getMA < maxValue && getMB < maxValue){
			if(dp[N][getMA][getMB] != null){
				output = Math.min(output,dp[N][getMA][getMB]);
			}
		}else{
			break;
		}
		count++;
	}
	if(output == 10000){
		myout(-1);
	}else{
		myout(output);
	}
}

Score : 400 points

Problem Statement

Dolphin is planning to generate a small amount of a certain chemical substance C.

In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b.

He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy.

The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock.

The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan).

Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C.

Find the minimum amount of money required to generate the substance C.

If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact.

Constraints

1≦N≦40

1≦a_i,b_i≦10

1≦c_i≦100

1≦M_a,M_b≦10

gcd(M_a,M_b)=1

a_i, b_i, c_i, M_a and M_b are integers.

Input

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

N M_a M_b
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N

Output

Print the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C, print -1 instead.

Sample Input 1

3 1 1
1 2 1
2 1 2
3 3 10

Sample Output 1

3

The amount of money spent will be minimized by purchasing the packages of chemicals 1 and 2.

In this case, the mixture of the purchased chemicals will contain 3 grams of the substance A and 3 grams of the substance B, which are in the desired ratio: 3:3=1:1.

The total price of these packages is 3 yen.

Sample Input 2

1 1 10
10 10 10

Sample Output 2

-1

The ratio 1:10 of the two substances A and B cannot be satisfied by purchasing any combination of the packages. Thus, the output should be -1.


function Main(input) {
	input = parseInt(input.trim().split(" "));
  console.log((input < 1200) ? "ABC" : "ARC");
}

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

Score : 100 points

Problem Statement

Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.

You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise.

Constraints

1 ≦ x ≦ 3{,}000

x is an integer.

Input

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

x

Output

Print the answer.

Sample Input 1

1000

Sample Output 1

ABC

Smeke's current rating is less than 1200, thus the output should be ABC.

Sample Input 2

2000

Sample Output 2

ARC

Smeke's current rating is not less than 1200, thus the output should be ARC.


function main(a){
	a = stn(a.split(" "));
	var ss=[];
	ss.push(a[0]*a[1]);
	ss.push(a[2]*a[3]);
	ss.sort(function(a,b){return a-b;});
	console.log(ss[1]);
}
function stn(a){
		return a.map(function(x){return parseInt(x,10);});
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

There are two rectangles.
The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B.
The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.

Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.

Constraints

All input values are integers.

1≤A≤10^4

1≤B≤10^4

1≤C≤10^4

1≤D≤10^4

Input

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

A B C D

Output

Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.

Sample Input 1

3 5 2 7

Sample Output 1

15

The first rectangle has an area of 3×5=15, and the second rectangle has an area of 2×7=14.
Thus, the output should be 15, the larger area.

Sample Input 2

100 600 200 300

Sample Output 2

60000


function main (input) {
  var args = input.split("\n");
  var ar = args[1].split("");
  var x = 0;
  var a = [0];
  for(var i = 0; i < ar.length; i++){
    if arra[i] === "I"
      x++;
      a.push(x);
    else
      x--;
      a.push(x);
  }

  var ans = Math.max.apply(null, a);
  console.log(ans);
}

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

Score : 200 points

Problem Statement

You have an integer variable x.
Initially, x=0.

Some person gave you a string S of length N, and using the string you performed the following operation N times.
In the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the value of x by 1 if S_i=D.

Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

Constraints

1≤N≤100

|S|=N

No characters except I and D occur in S.

Input

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

N
S

Output

Print the maximum value taken by x during the operations.

Sample Input 1

5
IIDID

Sample Output 1

2

After each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively. Thus, the output should be 2, the maximum value.

Sample Input 2

7
DDIDDII

Sample Output 2

0

The initial value x=0 is the maximum value taken by x, thus the output should be 0.


const fs = require("fs");

const input = fs.readFileSync("/dev/stdin", "utf-8").trim();

const lines = input.split(",");
console.log(lines.join(" "));

Score : 100 points

Problem Statement

As a New Year's gift, Dolphin received a string s of length 19.

The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].

Dolphin wants to convert the comma-separated string s into a space-separated string.

Write a program to perform the conversion for him.

Constraints

The length of s is 19.

The sixth and fourteenth characters in s are ,.

The other characters in s are lowercase English letters.

Input

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

s

Output

Print the string after the conversion.

Sample Input 1

happy,newyear,enjoy

Sample Output 1

happy newyear enjoy

Replace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy.

Sample Input 2

haiku,atcoder,tasks

Sample Output 2

haiku atcoder tasks

Sample Input 3

abcde,fghihgf,edcba

Sample Output 3

abcde fghihgf edcba


function Main(input) {
  input = input.split("\n");
  var sx = parseInt(input[0].split(" ")[0]);
  var sy = parseInt(input[0].split(" ")[1]);
  var tx = parseInt(input[0].split(" ")[2]);
  var ty = parseInt(input[0].split(" ")[3]);
  var ans = "";
  for(i=0;i<tx-sx;i++){
    ans+="R";
  }
  for(i=0;i<ty-sy;i++){
    ans+="U";
  }
  for(i=0;i<tx-sx;i++){
    ans+="L";
  }
  for(i=0;i<ty-sy;i++){
    ans+="D";
  }
  ans+="D";
  for(i=0;i<=tx-sx;i++){
    ans+="R";
  }
  for(i=0;i<=ty-sy;i++){
    ans+="U";
  }
  ans+="LU";
  for(i=0;i<=tx-sx;i++){
    ans+="L";
  }
  for(i=0;i<=ty-sy;i++){
    ans+="D";
  }
  ans+="R";
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.

Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.

Here, both the x- and y-coordinates before and after each movement must be integers.

He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).

Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).

Under this condition, find a shortest path for him.

Constraints

-1000 ≤ sx < tx ≤ 1000

-1000 ≤ sy < ty ≤ 1000

sx,sy,tx and ty are integers.

Input

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

sx sy tx ty

Output

Print a string S that represents a shortest path for Dolphin.

The i-th character in S should correspond to his i-th movement.

The directions of the movements should be indicated by the following characters:

U: Up

D: Down

L: Left

R: Right

If there exist multiple shortest paths under the condition, print any of them.

Sample Input 1

0 0 1 2

Sample Output 1

UURDDLLUUURRDRDDDLLU

One possible shortest path is:

Going from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)

Going from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)

Going from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)

Going from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)

Sample Input 2

-2 -2 1 1

Sample Output 2

UURRURRDDDLLDLLULUUURRURRDDDLLDL


function Main(input) {
  input = input.split("\n");
  var sx = parseInt(input[0].split(" ")[0]);
  var sy = parseInt(input[0].split(" ")[0]);
  var tx = parseInt(input[0].split(" ")[0]);
  var ty = parseInt(input[0].split(" ")[0]);
  var ans = "";
  for(i=0;i<tx-sx;i++){
    ans+="R";
  }
  for(i=0;i<ty-sy;i++){
    ans+="U";
  }
  for(i=0;i<tx-sx;i++){
    ans+="L";
  }
  for(i=0;i<ty-sy;i++){
    ans+="D";
  }
  ans+="D";
  for(i=0;i<=tx-sx;i++){
    ans+="R";
  }
  for(i=0;i<=ty-sy;i++){
    ans+="U";
  }
  ans+="LU";
  for(i=0;i<=tx-sx;i++){
    ans+="L";
  }
  for(i=0;i<=ty-sy;i++){
    ans+="D";
  }
  ans+="R";
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


//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 ai = one[0];
  var ao = one[1];
  var at = one[2];
  var aj = one[3];
  var al = one[4];
  var as = one[5];
  var az = one[6];
  var output1 = Math.floor(ai / 2) * 2 + Math.floor(aj / 2) * 2 + Math.floor(al / 2) * 2;
  var output2;
  if(ai > 2 && aj > 2 && al > 2){
    output2 = Math.floor((ai - 1) / 2) * 2 + Math.floor((aj - 1) / 2) * 2 + Math.floor((al - 1) / 2) * 2 + 6;
  }else{
    output2 = 0;
  }
  myout(Math.max(output1, output2) + ao);
}

Score : 600 points

Problem Statement

A tetromino is a figure formed by joining four squares edge to edge.
We will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z, respectively.
Snuke will join K of his tetrominos to form a rectangle that is two squares tall and 2K squares wide.
Here, the following rules must be followed:

When placing each tetromino, rotation is allowed, but reflection is not.

Each square in the rectangle must be covered by exactly one tetromino.

No part of each tetromino may be outside the rectangle.

Snuke wants to form as large a rectangle as possible.
Find the maximum possible value of K.

Constraints

0≤a_I,a_O,a_T,a_J,a_L,a_S,a_Z≤10^9

a_I+a_O+a_T+a_J+a_L+a_S+a_Z≥1

Input

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

a_I a_O a_T a_J a_L a_S a_Z

Output

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

Sample Input 1

2 1 1 0 0 0 0

Sample Output 1

3

One possible way to form the largest rectangle is shown in the following figure:

Sample Input 2

0 0 10 0 0 0 0

Sample Output 2

0

No rectangle can be formed.


function Main(input){

  var c = String(input);

  if( c === 'a' || c === 'i' || c === 'u' || c === 'e' || c === 'o') {
      console.log('vowel');
  } else {
    console.log('consonant');
  }

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

Score : 100 points

Problem Statement

Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: a, e, i, o and u.

Constraints

c is a lowercase English letter.

Input

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

c

Output

If c is a vowel, print vowel. Otherwise, print consonant.

Sample Input 1

a

Sample Output 1

vowel

Since a is a vowel, print vowel.

Sample Input 2

z

Sample Output 2

consonant

Sample Input 3

s

Sample Output 3

consonant


'use strict'

const main = (input) => {
    input = input.split('\n')
    const h = parseInt(input[0].split(' ')[0])
    const arr = input.slice(1, h + 1)

    arr.forEach(v => {
        console.log(v)
        console.log(v)
    })
}

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


//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 K = one[1];
  var L = one[2];
  var ufk = unionFind(N);
  var ufl = unionFind(N);
  var output = new Array(N).fill(1);
  var klist = new Array(K);
  var llist = new Array(L);
  for(var i = 0; i < K; i++){
    var tmp = nextIntArray();
    tmp.sort();
    tmp[0]--;
    tmp[1]--;
    klist[i] = tmp;
    ufk.doUnion(tmp[0], tmp[1]);
  }
  for(var i = 0; i < L; i++){
    var tmp = nextIntArray();
    tmp.sort();
    tmp[0]--;
    tmp[1]--;
    llist[i] = tmp;
    ufl.doUnion(tmp[0], tmp[1]);
  }
  var used = new Set();
  for(var i = 0; i < K; i++){
    var tmp = klist[i];
    if(ufl.isSame(tmp[0], tmp[1])){
      output[tmp[0]]++;
      output[tmp[1]]++;
    }
    used.add(tmp.join(":"));
  }
  for(var i = 0; i < L; i++){
    var tmp = llist[i];
    if(used.has(tmp.join(":"))){
      continue;
    }
    if(ufk.isSame(tmp[0], tmp[1])){
      output[tmp[0]]++;
      output[tmp[1]]++;
    }
  }
  myout(myconv(output, 8));
}

function unionFind(n){
  var uf = {
    //全てのインデックスは「-X(親、絶対値はグループの大きさ)」「自分が属する親(≒根)」のいずれかを持つ。
    //最初はみんなグループの大きさ1の親
    "list" : new Array(n).fill(-1),

    //同じ親を持つか
    "isSame" : function(mae, ato){
      return this.getRootIndex(mae) == this.getRootIndex(ato);
    },
    //自身の親インデックスをたどって根っこに着く
    //親にたどり終えたら子に帰っていくついでに、子たちに「共通の親を持っている」ことを知らせる
    "getRootIndex" : function(index){
      if(this.list[index] < 0){
        return index;
      }else{
        this.list[index] = this.getRootIndex(this.list[index]);
        return this.list[index];
      }
    },
    //異なる親同士のまとまりを一つにする（同じ親ならスルー）
    //小さいグループの親が大きいグループの親の直下に着く
    //グループの大きさも更新する
    "doUnion" : function(mae, ato){
      var maeRoot = this.getRootIndex(mae);
      var atoRoot = this.getRootIndex(ato);
      if(!this.isSame(maeRoot, atoRoot)){
        if(maeRoot >= atoRoot){
          this.list[maeRoot] += this.list[atoRoot];
          this.list[atoRoot] = maeRoot;
        }else{
          this.list[atoRoot] += this.list[maeRoot];
          this.list[maeRoot] = atoRoot;
        }
      }
    },
    //「-X(親、絶対値はグループの大きさ)」
    //なので、インデックスを指定→親を知る→親の持つグループの大きさがわかる。
    //ただしマイナス値なので、掛け算して返す。
    "getSize" : function(index){
      return -this.list[this.getRootIndex(index)];
    }
  }
  return uf;
}

Score : 400 points

Problem Statement

There are N cities. There are also K roads and L railways, extending between the cities.
The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.
No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.

We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads.
We will also define connectivity by railways similarly.

For each city, find the number of the cities connected to that city by both roads and railways.

Constraints

2 ≦ N ≦ 2*10^5

1 ≦ K, L≦ 10^5

1 ≦ p_i, q_i, r_i, s_i ≦ N

p_i < q_i

r_i < s_i

When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)

When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)

Input

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

N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L

Output

Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.

Sample Input 1

4 3 1
1 2
2 3
3 4
2 3

Sample Output 1

1 2 2 1

All the four cities are connected to each other by roads.

By railways, only the second and third cities are connected. Thus, the answers for the cities are 1, 2, 2 and 1, respectively.

Sample Input 2

4 2 2
1 2
2 3
1 4
2 3

Sample Output 2

1 2 2 1

Sample Input 3

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

Sample Output 3

1 1 2 1 2 2 2


function main(input) {
const a = input.split(" ");
  console.log('A'+a[1].charAt(0)+'C');
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

Snuke is going to open a contest named "AtCoder s Contest".
Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.

Snuke has decided to abbreviate the name of the contest as "AxC".
Here, x is the uppercase English letter at the beginning of s.

Given the name of the contest, print the abbreviation of the name.

Constraints

The length of s is between 1 and 100, inclusive.

The first character in s is an uppercase English letter.

The second and subsequent characters in s are lowercase English letters.

Input

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

AtCoder s Contest

Output

Print the abbreviation of the name of the contest.

Sample Input 1

AtCoder Beginner Contest

Sample Output 1

ABC

The contest in which you are participating now.

Sample Input 2

AtCoder Snuke Contest

Sample Output 2

ASC

This contest does not actually exist.

Sample Input 3

AtCoder X Contest

Sample Output 3

AXC


function trans(c){
	if(c == "d")return "b";
	if(c == "b")return "d";
	if(c == "q")return "p";
	if(c == "p")return "q";
}

function Main(inputData) {
	init(inputData);

	var s = inS();

	for(var i = 0; i < s.length; i++){
		if(trans(s[i]) != s[s.length-i-1]){
			outln("No");
			return 0;
		}
	}
	outln("Yes");
}

////////////////////////////////////////////////////////////////////////////////////
var input,inputCnt;

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

function init(inputData){
    //配列inputに順番に代入
	input = inputData.replace( /\n/g , " " );
	input = input.split(" ");
	inputCnt = 0;
}
//output
const out = (output) => { console.log(output) }
const outln = (output) => { console.log(output+"\n") }

//input
const inS = () => {return input[inputCnt++]};
const inI = () => {return parseInt(inS(), 10)};
const inF = () => {return parseFloat(inS())};

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

Score : 100 points

Problem Statement

You are given a string S consisting of letters b, d, p and q.
Determine whether S is a mirror string.

Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S:

Reverse the order of the characters in S.

Replace each occurrence of b by d, d by b, p by q, and q by p, simultaneously.

Constraints

1 \leq |S| \leq 10^5

S consists of letters b, d, p, and q.

Input

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

S

Output

If S is a mirror string, print Yes. Otherwise, print No.

Sample Input 1

pdbq

Sample Output 1

Yes

Sample Input 2

ppqb

Sample Output 2

No


let [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").split(" ").map(Number).sort((x, y) => x - y);
console.log(a + b == c ? "Yes" : "No");

Score : 100 points

Problem Statement

Two students of AtCoder Kindergarten are fighting over candy packs.

There are three candy packs, each of which contains a, b, and c candies, respectively.

Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.

Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

Constraints

1 ≦ a, b, c ≦ 100

Input

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

a b c

Output

If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.

Sample Input 1

10 30 20

Sample Output 1

Yes

Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.

Sample Input 2

30 30 100

Sample Output 2

No

In this case, the student who gets the pack with 100 candies always has more candies than the other.

Note that every pack must be given to one of them.

Sample Input 3

56 25 31

Sample Output 3

Yes


'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let Ns = input[0].split(' ').map(n => Number(n))
	Ns = Ns.sort((a, b) => a - b)
	console.log(Ns)
	console.log(Ns[2] === Ns[0] + Ns[1] ? 'Yes' : 'No')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let Ns = input[0].split(' ').map(n => Number(n))
	Ns = Ns.sort((a, b) => a - b)
	console.log(Ns)
	console.log(Ns[2] === Ns[0] + Ns[1])
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')[0].split(' ')
a = inp.shift() * 1
b = inp.shift() * 1
c = inp.shift() * 1
m = Math.max(a,b,c)
console.log((a + b + c - m) == m  ? 'Yes' : 'No')


function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var Wmax = parseInt(input[0].split(" ")[0]);
  var Hmax = parseInt(input[0].split(" ")[1]);
  var N = parseInt(input[0].split(" ")[2]);
  var Wmin = 0;
  var Hmin = 0;
  for(var i = 1; i <= N ; i++){
    var tmp = input[i].split(" ").map((a)=>Number(a));
    switch(tmp[2]){
      case 1:
        Wmin = tmp[0];
        break;
      case 2:
        Wmax = tmp[0];
        break;
      case 3:
        Hmin = tmp[1];
        break;
      case 4:
        Hmax = tmp[1];
        break;
    }
  }
  if(Wmin > Wmax || Hmin > Hmax){
     myout("0");
  }else{
    myout((Wmax - Wmin) * (Hmax - Hmin));
  }
}

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

Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

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

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

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

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64


var sArr = s.split('')
var cflag = false;
var fflag = false;
for (var i = 0; i < sArr.length; i++) {
  if(sArr[i] == "C") {
    cflag = true;
  } else {
    return false;
  }
  if(sArr[i] == "F" && cflag == true) {
    return true;
  } else {
    return false;
  }
}

Score : 100 points

Problem Statement

This contest is CODEFESTIVAL, which can be shortened to the string CF by deleting some characters.

Mr. Takahashi, full of curiosity, wondered if he could obtain CF from other strings in the same way.

You are given a string s consisting of uppercase English letters.
Determine whether the string CF can be obtained from the string s by deleting some characters.

Constraints

2 ≤ |s| ≤ 100

All characters in s are uppercase English letters (A-Z).

Input

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

s

Output

Print Yes if the string CF can be obtained from the string s by deleting some characters.
Otherwise print No.

Sample Input 1

CODEFESTIVAL

Sample Output 1

Yes

CF is obtained by deleting characters other than the first character C and the fifth character F.

Sample Input 2

FESTIVALCODE

Sample Output 2

No

FC can be obtained but CF cannot be obtained because you cannot change the order of the characters.

Sample Input 3

CF

Sample Output 3

Yes

It is also possible not to delete any characters.

Sample Input 4

FCF

Sample Output 4

Yes

CF is obtained by deleting the first character.


function Main(input) {
  var input = input.split("\n");
  var K = parseInt(input[0].split(" ")[0]);
  var T = parseInt(input[0].split(" ")[1]);
  var a = input[1].split(" ").map((el,i)=>{
    return [i,parseInt(el)];
  });
  var last = -1;
  var count = 0;
  while(1){
    if(K == 0){
      return console.log(count);
    };
    a.sort(function(a,b){return a[1] <= b[1];});
    var found = 0;

    for(var i = 0;i < a.length;i++){
      if(a[i][0] != last){
        last = a[i][0];
        a[i][1]--;
        if(!a[i][1]){
          a.splice(i, 1)
        }
        K--;
        found = 1;
        break;
      }
    };

    if(!found){
      last = a[0][0];
      a[0][1]--;
      if(!a[0][1]){
        a.splice(0, 1)
      }
      K--;
      count++;
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

There are K pieces of cakes.
Mr. Takahashi would like to eat one cake per day, taking K days to eat them all.

There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.

Eating the same type of cake two days in a row would be no fun,
so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before.

Compute the minimum number of days on which the same type of cake as the previous day will be eaten.

Constraints

1 ≤ K ≤ 10000

1 ≤ T ≤ 100

1 ≤ a_i ≤ 100

a_1 + a_2 + ... + a_T = K

Input

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

K T
a_1 a_2 ... a_T

Output

Print the minimum number of days on which the same type of cake as the previous day will be eaten.

Sample Input 1

7 3
3 2 2

Sample Output 1

0

For example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1, he can avoid eating the same type of cake as the previous day.

Sample Input 2

6 3
1 4 1

Sample Output 2

1

There are 6 cakes.
For example, if Mr. Takahashi eats cakes in the order of 2, 3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the previous day only on the fourth day.
Since this is the minimum number, the answer is 1.

Sample Input 3

100 1
100

Sample Output 3

99

Since Mr. Takahashi has only one type of cake, he has no choice but to eat the same type of cake as the previous day from the second day and after.


Score : 400 points

Problem Statement

Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range.
The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N.
Mr. Takahashi traversed the range from the west and Mr. Aoki from the east.

The height of Mt. i is h_i, but they have forgotten the value of each h_i.
Instead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i).
Mr. Takahashi's record is T_i and Mr. Aoki's record is A_i.

We know that the height of each mountain h_i is a positive integer.
Compute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7.

Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights.
In such a case, output 0.

Constraints

1 ≤ N ≤ 10^5

1 ≤ T_i ≤ 10^9

1 ≤ A_i ≤ 10^9

T_i ≤ T_{i+1} (1 ≤ i ≤ N - 1)

A_i ≥ A_{i+1} (1 ≤ i ≤ N - 1)

Input

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

N
T_1 T_2 ... T_N
A_1 A_2 ... A_N

Output

Print the number of possible sequences of the mountains' heights, modulo 10^9 + 7.

Sample Input 1

5
1 3 3 3 3
3 3 2 2 2

Sample Output 1

4

The possible sequences of the mountains' heights are:

1, 3, 2, 2, 2

1, 3, 2, 1, 2

1, 3, 1, 2, 2

1, 3, 1, 1, 2

for a total of four sequences.

Sample Input 2

5
1 1 1 2 2
3 2 1 1 1

Sample Output 2

0

The records are contradictory, since Mr. Takahashi recorded 2 as the highest peak after climbing all the mountains but Mr. Aoki recorded 3.

Sample Input 3

10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5

Sample Output 3

884111967

Don't forget to compute the number modulo 10^9 + 7.

Sample Input 4

1
17
17

Sample Output 4

1

Some mountain ranges consist of only one mountain.


function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0]);
  t = new Array(n).fill(0);
  a = new Array(n).fill(0);
  for(i=0;i<n;i++){
      t[i]=UInt64(parseInt(input[i+1].split(" ")[0]));
      a[i]=UInt64(parseInt(input[i+1].split(" ")[1]));
  }
  var tvote=UInt64(t[0]);
  var avote=UInt64(a[0]);

  for(i=1;i<n;i++){
      var x=UInt64(Math.ceil(tvote/t[i]));
      var y=x.multiply(a[i]);
      if(UInt64.compare(y,avote)==1){
          tvote=UInt64(Math.ceil(tvote/t[i])*t[i]);
          avote=UInt64(((Math.ceil(tvote/t[i])*t[i])/t[i])*a[i]);
      }else{
          tvote=UInt64(((Math.ceil(avote/a[i])*a[i])/a[i])*t[i]);
          avote=UInt64(Math.ceil(avote/a[i])*a[i]);
      }
  }
  var ans=UInt64(0);
  ans.set(avote)
  ans.add(tvote);
  console.log('%s', ans.toString());
}
function UInt64(value) {
    var uint64 = Object.create(UInt64.prototype);
    uint64._wordArray = new Array(4);

    uint64.set(value);

    return uint64;
  }

  UInt64.compare = function(a, b) {
    for (var i = a._wordArray.length; i >= 0; i--) {
        if (a._wordArray[i] > b._wordArray[i]) {
            return 1;
        }
        else if (a._wordArray[i] < b._wordArray[i]) {
            return -1;
        }
        else {
        }
    }
    return 0;
  };

  UInt64.prototype.set = function(value) {
    var div = 0;

    if (UInt64.prototype.isPrototypeOf(value)) {
        for (var i = 0; i < this._wordArray.length; i++) {
            this._wordArray[i] = value._wordArray[i];
        }
    }
    else if (typeof value == 'number') {
        div = 1;
        for (var i = 0; i < this._wordArray.length; i++) {
            this._wordArray[i] = (Math.floor(value / div) & 0xFFFF);
            div *= 0x10000;
        }
    }
    else {
        for (var i = 0; i < this._wordArray.length; i++) {
            this._wordArray[i] = 0;
        }
    }
  };

  UInt64.prototype.add = function(value) {
    var prevCarry = 0;
    var carry = 0;

    for (var i = 0; i < this._wordArray.length; i++) {
        carry = (((this._wordArray[i] + value._wordArray[i] + prevCarry) & 0xFFFF0000) >>> 16);
        this._wordArray[i] = ((this._wordArray[i] + value._wordArray[i] + prevCarry) & 0xFFFF);
        prevCarry = carry;
    }

    return this;
  };

  UInt64.prototype.multiply = function(value) {
    var prevCarry = 0;
    var carry = 0;
    var prod = UInt64(0);

    for (var i = 0; i < this._wordArray.length; i++) {
        prevCarry = 0;
        for (var j = 0; j < value._wordArray.length; j++) {
            if (i + j >= prod._wordArray.length) {
                break;
            }

            carry = (((this._wordArray[i] * value._wordArray[j] + prevCarry + prod._wordArray[i + j]) & 0xFFFF0000) >>> 16);
            prod._wordArray[i + j] = ((this._wordArray[i] * value._wordArray[j] + prevCarry + prod._wordArray[i + j]) & 0xFFFF);
            prevCarry = carry;
        }
    }

    this.set(prod);

    return this;
  };

  UInt64.prototype.isZero = function() {
    var ret = true;

    for (var i = 0; i < this._wordArray.length; i++) {
        if (this._wordArray[i] > 0) {
            ret = false;
            break;
        }
    }

    return ret;
  };

  UInt64.prototype.toString = function() {
    var work = UInt64(this);
    var prevMod = 0;
    var mod = 0;
    var str = '';

    if (work.isZero()) {
        str = '0';
    }
    else {
        while (!work.isZero()) {
            mod = 0;
            prevMod = 0;
            for (var i = work._wordArray.length - 1; i >= 0; i--) {
                mod = (work._wordArray[i] + prevMod) % 10;
                work._wordArray[i] = Math.floor((work._wordArray[i] + prevMod) / 10);
                prevMod = mod << 16;
            }

            str = String.fromCharCode('0'.charCodeAt() + mod) + str;
        }
    }

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

Score : 300 points

Problem Statement

AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.

Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

Constraints

1≦N≦1000

1≦T_i,A_i≦1000 (1≦i≦N)

T_i and A_i (1≦i≦N) are coprime.

It is guaranteed that the correct answer is at most 10^{18}.

Input

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

N
T_1 A_1
T_2 A_2
:
T_N A_N

Output

Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

Sample Input 1

3
2 3
1 1
3 2

Sample Output 1

10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

Sample Input 2

4
1 1
1 1
1 5
1 100

Sample Output 2

101

It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.

Sample Input 3

5
3 10
48 17
31 199
231 23
3 2

Sample Output 3

6930


// inputに入力データ全体が入る
function Main(input) {
	console.log(input.replace(/.{4}/, s=>`${s} `));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

This contest is CODE FESTIVAL.
However, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.

So he has decided to make a program that puts the single space he omitted.

You are given a string s with 12 letters.
Output the string putting a single space between the first 4 letters and last 8 letters in the string s.

Constraints

s contains exactly 12 letters.

All letters in s are uppercase English letters.

Input

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

s

Output

Print the string putting a single space between the first 4 letters and last 8 letters in the string s.
Put a line break at the end.

Sample Input 1

CODEFESTIVAL

Sample Output 1

CODE FESTIVAL

Putting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.

Sample Input 2

POSTGRADUATE

Sample Output 2

POST GRADUATE

Sample Input 3

ABCDEFGHIJKL

Sample Output 3

ABCD EFGHIJKL


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
    var h = parseInt(input[2], 10);
    var ans=(a+b)*h/2;
	//出力
    console.log('%d',ans);

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

Score : 100 points

Problem Statement

You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.

An example of a trapezoid

Find the area of this trapezoid.

Constraints

1≦a≦100

1≦b≦100

1≦h≦100

All input values are integers.

h is even.

Input

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

a
b
h

Output

Print the area of the given trapezoid. It is guaranteed that the area is an integer.

Sample Input 1

3
4
2

Sample Output 1

7

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.

Sample Input 2

4
4
4

Sample Output 2

16

In this case, a parallelogram is given, which is also a trapezoid.