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

  let answer = 0;

  switch (S) {
    case "RSR":
    case "RSS":
    case "SRS":
    case "SSR":
      answer = 1;
      break;
    case "RRS":
    case "SRR":
      answer = 2;
      break;
    case "RRR":
      answer = 3;
      break;
  }

  console.log('%s',answer);

}
// デバッグ用
function debug(){
var input = document.getElementById("input").value;
Main(input);
}

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

Score : 100 points

Problem Statement

We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day.

Find the maximum number of consecutive rainy days in this period.

Constraints

|S| = 3

Each character of S is S or R.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of consecutive rainy days in the period.

Sample Input 1

RRS

Sample Output 1

2

We had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.

Sample Input 2

SSS

Sample Output 2

0

It was sunny throughout the period. We had no rainy days, so we should print 0.

Sample Input 3

RSR

Sample Output 3

1

We had rain on the 1-st and 3-rd days - two "streaks" of one rainy day, so we should print 1.


function Main(input){
  const a = 'RRR';
  if(a.includes('R')) {
    console.log(1);
  }else if(a.includes('RR')) {
      console.log(2);
    } else if(a.includes('RRR')) {
      console.log(3);
    } else {
      console.log(0);
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
//Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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.


function Main(input) {
  input = input.replace(/\n/g, ' ').split(" ");
  var a = input[0].slice(0,1);
  var b = input[0].slice(1,2);
  var c = input[0].slice(2,3);
  if(a==b && b==c && a=="R"){
    console.log(3);
  }else if(a==b && a=="R"){
    console.log(2);
  }else if(b==c && b=="R"){
    console.log(2);
  }else if(a=="R" || b=="R" || c=="R"){
    console.log(1);
  }else{
    console.log(0);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  input=input.split("\n");
  const N=input[0]-0;
  var array=input[1].split(' ').map(e=>{
    return e-0;
  }).sort((a,b)=>{
    return a-b;
  });
  var ans=0;
  //console.log(array);
  for(var i=0;i<N-2;i++){
    for(var j=i+1;j<N-1;j++){
      for(var k=j+1;k<N;k++){
        if(array[i]===array[j]){
          break;
        }
        if(array[j]===array[k]){
          continue;
        }
        if(array[i]+array[j]<=array[k]){
          break;
        }
        //console.log(i,j,k);
        ans++;
      }
    }
  }
  console.log(ans);
}

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

Score : 200 points

Problem Statement

We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.

In how many ways can we choose three of the sticks with different lengths that can form a triangle?

That is, find the number of triples of integers (i, j, k) (1 \leq i < j < k \leq N) that satisfy both of the following conditions:

L_i, L_j, and L_k are all different.

There exists a triangle whose sides have lengths L_i, L_j, and L_k.

Constraints

1 \leq N \leq 100

1 \leq L_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 \cdots L_N

Output

Print the number of ways to choose three of the sticks with different lengths that can form a triangle.

Sample Input 1

5
4 4 9 7 5

Sample Output 1

5

The following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).

Sample Input 2

6
4 5 4 3 3 5

Sample Output 2

8

We have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.

There is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.

Sample Input 3

10
9 4 6 1 9 6 10 6 6 8

Sample Output 3

39

Sample Input 4

2
1 1

Sample Output 4

0

No triple (i, j, k) satisfies 1 \leq i < j < k \leq N, so we should print 0.


function Main(input) {
  const row = input.split(" ");
    	let X = parseInt(row[0], 10);
    	let K = parseInt(row[1], 10);
    	const D = parseInt(row[2], 10);
    let absX = Math.abs(X);
    let a = absX / D;//往復にたどり着くまでに必要な移動回数
    let ans; //答え

    if((absX /D) >= K) {
       ans = absX - D * K;//往復地点までたどり着かな勝った時の計算 x-dk >=0→x/d>=k

    } else {
      //0近辺の往復処理を書く.K =K -(X/d)で往復地点までかかった回数を減らして、残りの回数分往復する
       K2 = K - a;//Kからx/d回引いた回数が「往復を繰り返す回数」
       absX = absX - K2 * D;//x/D回-Dした後の往復開始座標
       if(X === D && K % 2 === 0 ){
         ans = X;
       } else if(K2 % 2 === 1) {
    　ans = absX - D;
     } else {
         ans = absX;
      }
    } console.log(Math.abs(ans));
}

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

Score : 300 points

Problem Statement

Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.

More specifically, in one move, he can go from coordinate x to x + D or x - D.

He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.

Find the minimum possible absolute value of the coordinate of the destination.

Constraints

-10^{15} \leq X \leq 10^{15}

1 \leq K \leq 10^{15}

1 \leq D \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X K D

Output

Print the minimum possible absolute value of the coordinate of the destination.

Sample Input 1

6 2 4

Sample Output 1

2

Takahashi is now at coordinate 6. It is optimal to make the following moves:

Move from coordinate 6 to (6 - 4 =) 2.

Move from coordinate 2 to (2 - 4 =) -2.

Here, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.

Sample Input 2

7 4 3

Sample Output 2

1

Takahashi is now at coordinate 7. It is optimal to make, for example, the following moves:

Move from coordinate 7 to 4.

Move from coordinate 4 to 7.

Move from coordinate 7 to 4.

Move from coordinate 4 to 1.

Here, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.

Sample Input 3

10 1 2

Sample Output 3

8

Sample Input 4

1000000000000000 1000000000000000 1000000000000000

Sample Output 4

1000000000000000

The answer can be enormous.


function main(lines) {
  const [N, D] = splitN(lines[0]);

  let ans = 0;
  for (let i = 1; i <= N; i++) {
    const [x, y] = splitN(lines[i]);
    if (Math.sqrt(x*x + y*y) <= D) ans++;
  }

  return ans;
}

const ans = main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );
console.log( ans );

function splitN(s) {
  return s.split(' ').map(Number);
}

Score : 200 points

Problem Statement

We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).

Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?

We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.

Constraints

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

0 \leq D \leq 2\times 10^5

|X_i|,|Y_i| \leq 2\times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
X_1 Y_1
\vdots
X_N Y_N

Output

Print an integer representing the number of points such that the distance from the origin is at most D.

Sample Input 1

4 5
0 5
-2 4
3 4
4 -4

Sample Output 1

3

The distance between the origin and each of the given points is as follows:

\sqrt{0^2+5^2}=5

\sqrt{(-2)^2+4^2}=4.472\ldots

\sqrt{3^2+4^2}=5

\sqrt{4^2+(-4)^2}=5.656\ldots

Thus, we have three points such that the distance from the origin is at most 5.

Sample Input 2

12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Sample Output 2

7

Multiple points may exist at the same coordinates.

Sample Input 3

20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669

Sample Output 3

6


function Main(input) {
  input = input.split("\n");
  const nq = input.shift().split(" ");
  const n = parseInt(nq[0], 10);
  const q = parseInt(nq[1], 10);
  const cs = input.shift().split(" ");

  // Preload queries
  const qs = [];
  for (let qi=0; qi<q; qi++) {
    const [l, r] = input[qi].split(" ");
    qs[l-1] = qs[l-1] || [];
    qs[l-1].push([r-1, qi]);
  }

  // store the information whether the number is already appeared
  const ps = [];
  const pi = {};
  for (let i=0; i<n; i++) {
    const l = pi[cs[i]];
    if (l !== undefined) {
      ps[l] = ps[l] || [];
      ps[l].push(i);
    }
    pi[cs[i]] = i;
  }

  const ans = [];

  // Create BIT
  const d = [];
  for (let x=n-1; x>=0; --x) {
    const psLength = ps[x] && ps[x].length || 0;
    for (let y=0; y<psLength; y++) {
      let di = ps[x][y] + 1;
      for (; di<=n; di+=di&-di) {
        d[di] = d[di] || 0;
        d[di] += 1;
      }
    }
    const qsLength = qs[x] && qs[x].length || 0;
    for (let y=0; y<qsLength; y++) {
      const [r, i] = qs[x][y];
      let sum = 0;
      let ri = r + 1;
      for (; ri; ri -= ri&-ri) {
        sum += d[ri] || 0;
      }
      ans[i] = (r-x+1) - sum;
    }
  }

  console.log(ans.join("\n"));
  return;
}

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

Score : 600 points

Problem Statement

We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i.

You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have?

Constraints

1\leq N,Q \leq 5 \times 10^5

1\leq c_i \leq N

1\leq l_i \leq r_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
c_1 c_2 \cdots c_N
l_1 r_1
l_2 r_2
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the response to the i-th query.

Sample Input 1

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

Sample Output 1

2
3
1

The 1-st, 2-nd, and 3-rd balls from the left have the colors 1, 2, and 1 - two different colors.

The 2-st, 3-rd, and 4-th balls from the left have the colors 2, 1, and 3 - three different colors.

The 3-rd ball from the left has the color 1 - just one color.

Sample Input 2

10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8

Sample Output 2

1
2
2
1
2
2
6
3
3
3


function main(input) {
  	let inputs = input.split(/\n/);
 	let args = inputs[0].split(/\s/);
    for (let i = 0;i < inputs[1];i++) {
      if (args[1] > args[2]) {
         args[2] *= 2;
      } else if (args[0] > args[1]) {
         args[1] *= 2;
      }
    }
  	if (args[1] < args[2] && args[0] < args[1]) {
      console.log('yes');
    } else {
      console.log('no');
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score: 200 points

Problem Statement

M-kun has the following three cards:

A red card with the integer A.

A green card with the integer B.

A blue card with the integer C.

He is a genius magician who can do the following operation at most K times:

Choose one of the three cards and multiply the written integer by 2.

His magic is successful if both of the following conditions are satisfied after the operations:

The integer on the green card is strictly greater than the integer on the red card.

The integer on the blue card is strictly greater than the integer on the green card.

Determine whether the magic can be successful.

Constraints

1 \leq A, B, C \leq 7

1 \leq K \leq 7

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C
K

Output

If the magic can be successful, print Yes; otherwise, print No.

Sample Input 1

7 2 5
3

Sample Output 1

Yes

The magic will be successful if, for example, he does the following operations:

First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.

Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.

Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.

Sample Input 2

7 4 2
3

Sample Output 2

No

He has no way to succeed in the magic with at most three operations.


"use strict";

var maxProfit = function(prices) {
    let profit = 0;
    for (let i = 0; i < prices.length - 1; i++) {
        const possibleProfit = prices[i + 1] - prices[i];
        //console.log("possible:" + possibleProfit)
        profit = Math.max(profit + possibleProfit, profit);
    }
    return profit;
};

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

    let profit = 0;
    let money = 1000;

    let answer = 1000;

    for (let i = 0; i<N; i++) {
        const possibleProfit = A[i + 1] - A[i];
        profit = Math.max(profit + possibleProfit, profit);

        // console.log("possibleProfit:" + possibleProfit)

        if(possibleProfit > 0) {
            let cnt = Math.floor(money / A[i]);
            // console.log("cnt:" + cnt);

            answer += (possibleProfit * cnt);
            money = answer;
            // console.log("answer:" + answer)
        }
    }

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

Score: 400 points

Problem Statement

To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.

He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:

A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.

In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.

Buy stock: Pay A_i yen and receive one stock.

Sell stock: Sell one stock for A_i yen.

What is the maximum possible amount of money that M-kun can have in the end by trading optimally?

Constraints

2 \leq N \leq 80

100 \leq A_i \leq 200

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the maximum possible amount of money that M-kun can have in the end, as an integer.

Sample Input 1

7
100 130 130 130 115 115 150

Sample Output 1

1685

In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:

Initially, he has 1000 yen and no stocks.

Day 1: Buy 10 stocks for 1000 yen. Now he has 0 yen.

Day 2: Sell 7 stocks for 910 yen. Now he has 910 yen.

Day 3: Sell 3 stocks for 390 yen. Now he has 1300 yen.

Day 4: Do nothing.

Day 5: Buy 1 stock for 115 yen. Now he has 1185 yen.

Day 6: Buy 10 stocks for 1150 yen. Now he has 35 yen.

Day 7: Sell 11 stocks for 1650 yen. Now he has 1685 yen.

There is no way to have 1686 yen or more in the end, so the answer is 1685.

Sample Input 2

6
200 180 160 140 120 100

Sample Output 2

1000

In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.

Sample Input 3

2
157 193

Sample Output 3

1216

In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2, after which we will have 1216 yen.


//let input = "15\n13 76 46 15 50 98 93 77 31 43 84 90 6 24 14";

function main(input){
  input = input.trim();
  let list0 = input.split("\n")[0];
  let list1 = input.split("\n")[1];
  let kousu = parseInt(list0);
  let list = list1.split(" ");
  let count = 0;
  for(let i=0; i<list.length; i++){
    list[i] = parseInt(list[i]);
    if( (i+1)%2!==0 && list[i]%2!==0 ){count++;}
  }
  console.log(count);
}
//main(input);
function main(input){ } main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i.

How many squares i satisfy both of the following conditions?

The assigned number, i, is odd.

The written integer is odd.

Constraints

All values in input are integers.

1 \leq N, a_i \leq 100

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \cdots a_N

Output

Print the number of squares that satisfy both of the conditions.

Sample Input 1

5
1 3 4 5 7

Sample Output 1

2

Two squares, Square 1 and 5, satisfy both of the conditions.

For Square 2 and 4, the assigned numbers are not odd.

For Square 3, the written integer is not odd.

Sample Input 2

15
13 76 46 15 50 98 93 77 31 43 84 90 6 24 14

Sample Output 2

3


var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var N = +o.getValue(0);

    var result = Array(1000).fill(0);
    for(var x = 1; 100 > x; x++) {
        for(var y = 1; 100 > y; y++) {
            for(var z = 1; 100 > z; z++) {
                var n = x**2 + y**2 + z**2 + x*y + x*z + y*z;
                if (n > 1000) break;
                result[n - 1] += 1;
            }
        }
    }

    return result.slice(0, N).join('\n');
}

Score : 300 points

Problem Statement

Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:

1 \leq x,y,z

x^2 + y^2 + z^2 + xy + yz + zx = n

Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).

Constraints

All values in input are integers.

1 \leq N \leq 10^4

Input

Input is given from Standard Input in the following format:

N

Output

Print N lines. The i-th line should contain the value f(i).

Sample Input 1

20

Sample Output 1

0
0
0
0
0
1
0
0
0
0
3
0
0
0
0
0
3
3
0
0

For n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.

For n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.

For n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.

For n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.


// XYZ Triplets
function Main(input) {
	try {
		input = input.split("\n");
		const n = input[0]

		const L = 105

		const set = {}
		let k;
		for (let x = 1; x < L; x++) {
			for (let y = 1; y < L; y++) {
				for (let z = 1; z < L; z++) {
					k = x * x + y * y + z * z + x * y + y * z + z * x
					set[k] = set[k] ? set[k] + 1 : 1
				}
			}
		}

		for (let i = 1; i < n; i++) {
			console.log(set[i] || 0)

		}
	} catch (error) {
		console.error(error)
	}

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


"use strict"
function main(arg) {
    let N = arg.trim().split("\n")[0]
    N = Number(N)
    let ans = (new Array(N + 1)).fill(0)
    const MAX = 10e4
    for (let i = 1; i < MAX; i++) {
        let t = fx(i,i,i)
        if (t > N) {
            break
        }
        ans[t] = 1
    }
    for (let i = 1; i < MAX; i++) {
        let j = 1
        for (j = 1; j < MAX; j++) {
            if (i === j) continue
            let t = fx(i,j,j)
            if (t > N) {
                break
            }
            ans[t] = 3
        }
        if (j===1) {
            break
        }
    }
    for (let i = 1; i < MAX; i++) {
        let j = 1
        for (j = 1; j < MAX; j++) {
            if (i === j) continue
            let k = 1;
            for (k = 1; k < MAX; k++) {
                if (k === i || k === j) continue
                let t = fx(i,j,k)
                if (t > N) {
                    break
                }
                ans[t] = 6
            }
            if (k === 1) {
                break
            }
        }
        if (j === 1) {
            break
        }
    }

    ans.shift()
    console.log(ans.join("\n"))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function fx(x,y,z) {
    return x * x  + y * y + z * z + x * y + y * z + z * x
}


"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var x = nextstr();
  var bc = 1;
  for(var i = 0; i < n; i++)if(x[i] === "1")bc++;
  var ans = xArray(0,n);
  var m1 = 0;
  for(var i = 0; i < n; i++){
    m1 *= 2;
    m1 += +x[i];
    m1 %= bc;
  }
  var c = 1;
  for(var i = n; i--;){
    if(x[i] === "0"){
      ans[i] = 1;
      var t = m1+c;
      t %= bc;
      while(t){
        t %= bitcount(t);
        ans[i]++;
      }
    }
    c = c*2%bc;
  }
  bc -= 2;
  if(bc < 1)return ans.join("\n");
  m1 = 0;
  for(var i = 0; i < n; i++){
    m1 *= 2;
    m1 += +x[i];
    m1 %= bc;
  }
  c = bc-1;
  for(var i = n; i--;){
    if(x[i] === "1"){
      ans[i] = 1;
      var t = m1+c;
      t %= bc;
      while(t){
        t %= bitcount(t);
        ans[i]++;
      }
    }
    c = c*2%bc;
  }
  return ans.join("\n");
}

function bitcount(bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

Score : 400 points

Problem Statement

Let \mathrm{popcount}(n) be the number of 1s in the binary representation of n.
For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.

Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)

For example, when n=7, it becomes 0 after two operations, as follows:

\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.

\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.

You are given an integer X with N digits in binary.
For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted.
Find f(X_1), f(X_2), \ldots, f(X_N).

Constraints

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

X is an integer with N digits in binary, possibly with leading zeros.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print N lines. The i-th line should contain the value f(X_i).

Sample Input 1

3
011

Sample Output 1

2
1
1

X_1 = 7, which will change as follows: 7 \rightarrow 1 \rightarrow 0. Thus, f(7) = 2.

X_2 = 1, which will change as follows: 1 \rightarrow 0. Thus, f(1) = 1.

X_3 = 2, which will change as follows: 2 \rightarrow 0. Thus, f(2) = 1.

Sample Input 2

23
00110111001011011001110

Sample Output 2

2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3


function Main(input) {
    input = input.trim().split('\n');
    let robj = {
        ac: 0,
        wa: 0,
        tle: 0,
        re: 0
    };
    for(let i=1; i<=parseInt(input[0], 10); i++) {
        switch(input[i]) {
            case 'AC':
                robj.ac += 1;
                break;
            case 'WA':
                robj.wa += 1;
                break;
            case 'TLE':
                robj.tle += 1;
                break;
            case 'RE':
                robj.re += 1;
                break;
        }
    }
    console.log(`AC x ${robj.ac}
WA x ${robj.wa}
TLE x ${robj.tle}
RE x ${robj.re}`);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.

The problem has N test cases.

For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.

See the Output section for the output format.

Constraints

1 \leq N \leq 10^5

S_i is AC, WA, TLE, or RE.

Input

Input is given from Standard Input in the following format:

N
S_1
\vdots
S_N

Output

Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:

AC x C_0
WA x C_1
TLE x C_2
RE x C_3

Sample Input 1

6
AC
TLE
AC
AC
WA
TLE

Sample Output 1

AC x 3
WA x 1
TLE x 2
RE x 0

We have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.

Sample Input 2

10
AC
AC
AC
AC
AC
AC
AC
AC
AC
AC

Sample Output 2

AC x 10
WA x 0
TLE x 0
RE x 0


function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = parseInt(input[0][0], 10);
    var count = [0, 0, 0, 0];
    for (var i = 0; i < N; i++){
        if (input[i + 1][0] === "AC") count[0]++;
        if (input[i + 1][0] === "WA") count[1]++;
        if (input[i + 1][0] === "TLE") count[2]++;
        if (input[i + 1][0] === "RE") count[3]++;
    }

    console.log("AC x %d", count[0]);
    console.log("WA x %d", count[1]);
    console.log("TLE x %d", count[2]);
    console.log("RE x %d", count[3]);
}

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


function main(input) {
  const [ h, w, k ] = input[0].trim().split(" ").map(i => parseInt(i));
  const c = [];
  for(let i=0;i<h;i++){
    c[i] = new Array(w);
    c[i] = input[i+1].trim().split("");
  }

  const H = new Array(h).fill(null).map((a, i) => i+1);
  const W = new Array(w).fill(null).map((a, i) => i+1);

  let h_pat = [[]];
  let w_pat = [[]];

  for(let i=1;i<=h;i++){
    h_pat = h_pat.concat(kumiawase(H, i));
  }

  for(let i=1;i<=w;i++){
    w_pat = w_pat.concat(kumiawase(W, i));
  }

  let count = 0;

  for(let i=0;i<h_pat.length;i++){
    for(let j=0;j<w_pat.length;j++){
      let cnt = 0;
      for(let l=1;l<=c.length;l++){
        if(!(h_pat[i].includes(l))){
          for(let s=1;s<=w;s++){
            if(!(w_pat[j].includes(s))){
              if(c[l-1][s-1]==="#"){
                cnt++;
              }
            }
          }
        }
      }
      if(cnt === k){
        count++;
      }
    }
  }
  console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

function kumiawase(balls, nukitorisu){
  var arrs, i, j, zensu, kumis;
  arrs = [];
  zensu = balls.length;
  if(zensu < nukitorisu){
    return;
  }else if(nukitorisu == 1){
    for(i = 0; i < zensu; i++){
      arrs[i] = [balls[i]];
    }
  }else{
    for(i = 0; i < zensu - nukitorisu + 1; i ++){
      kumis = kumiawase(balls.slice(i + 1), nukitorisu - 1);
      for(j = 0; j < kumis.length; j ++){
        arrs.push([balls[i]].concat(kumis[j]));
      }
    }
  }
  return arrs;
}

Score : 300 points

Problem Statement

We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is ., and black if c_{i,j} is #.

Consider doing the following operation:

Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.

You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.

Constraints

1 \leq H, W \leq 6

1 \leq K \leq HW

c_{i,j} is . or #.

Input

Input is given from Standard Input in the following format:

H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}

Output

Print an integer representing the number of choices of rows and columns satisfying the condition.

Sample Input 1

2 3 2
..#
###

Sample Output 1

5

Five choices below satisfy the condition.

The 1-st row and 1-st column

The 1-st row and 2-nd column

The 1-st row and 3-rd column

The 1-st and 2-nd column

The 3-rd column

Sample Input 2

2 3 4
..#
###

Sample Output 2

1

One choice, which is choosing nothing, satisfies the condition.

Sample Input 3

2 2 3
##
##

Sample Output 3

0

Sample Input 4

6 6 8
..##..
.#..#.
#....#
######
#....#
#....#

Sample Output 4

208


console.log((args=>{
  const [HWK,...tmp] = args.trim().split('\n');
  const [H,W,K] = HWK.split(' ').map(v=>v|0);
  const ha = 1 << H, wa = 1<< W;
  let count = 0;
  for ( let h = 0; h < ha; h++ ) {
    for ( let w = 0; w < wa; w++ ) {
      let b = 0;
      for ( let i = 0; i < H; i++ ) {
        if ( h & 1<<i ) continue;
        for ( let j = 0; j < W; j++ ) {
          if ( w & 1<<j ) continue;
          if ( tmp[i][j] === '#' ) b++;
        }
      }
      if ( b === K ) count++;
    }
  }
  return `${count}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


function Main(input) {
    input = input.trim().split('\n');
    //const n = parseInt(input[0], 10);
    const a = input[1].split(' ').sort((a,b) => parseInt(b, 10) - parseInt(a, 10));
    const ring = [];
    let sum = 0;

    a.forEach((el, idx) => {
        let maxComfort = 0;
        let center, left, right, comfort;
        let ins;
        if(idx === 0) {
            ring.push(parseInt(el, 10));
            return;
        }
        if(ring.length % 2 === 0){
            center = ring.length/2;
            left = ring[center-1];
            right = ring[center];
            comfort = left > right ? right : left;
            if(maxComfort < comfort){
                maxComfort = comfort;
                ins = center;
            }
        }else if(idx !== 1){
            center = Math.floor(ring.length/2);
            left = ring[center-1];
            right = ring[center];
            comfort = left > right ? right : left;
            if(maxComfort < comfort){
                maxComfort = comfort;
                ins = center;
            }

            center = Math.ceil(ring.length/2);
            left = ring[center-1];
            right = ring[center];
            comfort = left > right ? right : left;
            if(maxComfort < comfort){
                maxComfort = comfort;
                ins = center;
            }
        }
        left = ring[ring.length -1];
        right = ring[0];
        comfort = left > right ? right : left;
        if(maxComfort < comfort){
            maxComfort = comfort;
            ins = ring.length;
        }
        ring.splice(ins, 0, parseInt(el, 10));
        sum += maxComfort;
    });
    console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score: 400 points

Problem Statement

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

All values in input are integers.

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

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6


const [nk, as] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
const [n, k] = nk.split(/\s/).map(Number)
const arr = as.split(/\s/).map(Number).sort((a, b) => Math.abs(b) - Math.abs(a))
const base = Math.pow(10, 9) + 7

let results = [], lowestP = -1, lowestN = -1, odd = false

for (let i = 0; i < k; i++) {
  results.push(arr[i])
  if (arr[i] < 0) {
    lowestN = i
    odd = !odd
  } else {
    lowestP = i
  }
}
if (odd) {
  let mul1 = lowestP >= 0 ? 1 / results[lowestP] : 0
  let mul2 = lowestN >= 0 ? 1 / -results[lowestN] : 0
  let index1 = -1
  let index2 = -1
  for (let i = k; i < n; i++) {
    if (arr[i] < 0 && index1 < 0) {
      mul1 *= -arr[i]
      index1 = i
    } else if (arr[i] > 0 && index2 < 0) {
      mul2 *= arr[i]
      index2 = i
    }
    if ((index1 >= 0 || mul1 === 0) && (index2 >= 0 || mul2 === 0)) {
      break
    }
  }
  const v1 = mul1 * Number(index1 >= 0), v2 = mul2 * Number(index2 >= 0)
  if (!v1 && !v2) {
    results = []
  } else if (v1 > v2) {
    results[lowestP] = arr[index1]
  } else {
    results[lowestN] = arr[index2]
  }
}
if (results.length === 0) {
  let result = 1;
  for (let i = n - 1; i >= n - k; i--) {
    result = (result * arr[i]) % base
  }
  console.log(result + base)
} else {
  let result = 1;
  for (const r of results) {
    result = (result * r) % base
  }
  console.log(result)
}

Score : 500 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

We will choose exactly K of these elements. Find the maximum possible product of the chosen elements.

Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Constraints

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

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N

Output

Print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Sample Input 1

4 2
1 2 -3 -4

Sample Output 1

12

The possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.

Sample Input 2

4 3
-1 -2 -3 -4

Sample Output 2

1000000001

The possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.

We print this value modulo (10^9+7), that is, 1000000001.

Sample Input 3

2 1
-1 1000000000

Sample Output 3

1000000000

The possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.

Sample Input 4

10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1

Sample Output 4

999983200

Be sure to print the product modulo (10^9+7).


const chunks = [];
process.stdin.on("data", (chunk) => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const data = Buffer.concat(chunks).toString("utf8").trim();
  const lines = data.split("\n");
  const [N, K] = parseLine(lines[0]);
  const A = parseLine(lines[1]);
  console.log(solve(N, K, A));
});

function parseLine(line) {
  return line.split(" ").map((item) => parseInt(item, 10));
}

function solve(N, K, A) {
  // Sort by abs desc
  A.sort((a, b) => Math.abs(b) - Math.abs(a));

  if (A[K - 1] === 0) return 0;

  let negative = false;
  let lastNegative = null;
  let lastPositive = null;
  for (let i = 0; i < K; i++) {
    const a = A[i];
    if (a < 0) {
      negative = !negative;
      lastNegative = i;
    }
    if (a > 0) {
      lastPositive = i;
    }
  }

  if (negative) {
    let firstPositive = null;
    let firstNegative = null;
    // Find the first positive number and replace it.
    // Find the first negative number and replace eit.
    for (let i = K; i < N; i++) {
      if (A[i] === 0) {
        return 0;
      }
      if (A[i] > 0) {
        firstPositive = i;
        break;
      }
    }
    for (let i = K; i < N; i++) {
      if (A[i] === 0) {
        return 0;
      }
      if (A[i] < 0) {
        firstNegative = i;
        break;
      }
    }

    let doNegaitve = firstNegative !== null;
    let doPositive = firstPositive !== null;
    if (doNegaitve && doNegaitve) {
      const a = Math.abs(A[lastPositive] * A[firstPositive]);
      const b = Math.abs(A[lastNegative] * A[firstNegative]);
      if (a <= b) {
        doPositive = false;
      } else {
        doNegaitve = false;
      }
    }

    if (doNegaitve) {
      const temp = A[firstNegative];
      A[firstNegative] = A[lastPositive];
      A[lastPositive] = temp;
      negative = false;
    } else if (doPositive) {
      const temp = A[firstPositive];
      A[firstPositive] = A[lastNegative];
      A[lastNegative] = temp;
      negative = false;
    } else {
      // Return the biggest negative number.
      A.sort((a, b) => Math.abs(a) - Math.abs(b));
      negative = true;
    }
  }

  const MOD = 1000000007;
  let mult = 1;
  for (let i = 0; i < K; i++) {
    mult = (mult * Math.abs(A[i])) % MOD;
  }
  if (negative) {
    return (mult + MOD) % MOD;
  } else {
    return mult;
  }
}


const [_n, ..._edges] = require('fs')
  .readFileSync('/dev/stdin', 'utf8')
  .split(/\n/)
const n = Number(_n)

let result = (n * (n + 1) * (n + 2)) / 6

for (const _edge of _edges) {
  let [u, v] = _edge.split(/ /).map(Number)
  if (u > v) {
    [u, v] = [v, u]
  }
  result -= u * (n - v + 1)
}
console.log(result)

Score : 600 points

Problem Statement

We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i.

For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows:

Let S be the set of the vertices numbered L through R. f(L, R) represents the number of connected components in the subgraph formed only from the vertex set S and the edges whose endpoints both belong to S.

Compute \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R).

Constraints

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

1 \leq u_i, v_i \leq N

The given graph is a tree.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
u_1 v_1
u_2 v_2
:
u_{N-1} v_{N-1}

Output

Print \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R).

Sample Input 1

3
1 3
2 3

Sample Output 1

7

We have six possible pairs (L, R) as follows:

For L = 1, R = 1, S = \{1\} and we have 1 connected component.

For L = 1, R = 2, S = \{1, 2\} and we have 2 connected components.

For L = 1, R = 3, S = \{1, 2, 3\} and we have 1 connected component, since S contains both endpoints of each of the edges 1, 2.

For L = 2, R = 2, S = \{2\} and we have 1 connected component.

For L = 2, R = 3, S = \{2, 3\} and we have 1 connected component, since S contains both endpoints of Edge 2.

For L = 3, R = 3, S = \{3\} and we have 1 connected component.

The sum of these is 7.

Sample Input 2

2
1 2

Sample Output 2

3

Sample Input 3

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

Sample Output 3

113


Score : 100 points

Problem Statement

Given an integer a as input, print the value a + a^2 + a^3.

Constraints

1 \leq a \leq 10

a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

Print the value a + a^2 + a^3 as an integer.

Sample Input 1

2

Sample Output 1

14

When a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.

Print the answer as an input. Outputs such as 14.0 will be judged as incorrect.

Sample Input 2

10

Sample Output 2

1110


const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const a = input - 0

    console.log(a + a * a + a * a * a)

})(input)


inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
S = inp.shift()
T = inp.shift()
c = 0
for (i=0; i<S.length; i++) {
    if (S[i] !== T[i]) {
        c++
    }
}
console.log(c)

Score : 200 points

Problem Statement

Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.

Operation: Choose one character of S and replace it with a different character.

Constraints

S and T have lengths between 1 and 2\times 10^5 (inclusive).

S and T consists of lowercase English letters.

S and T have equal lengths.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the answer.

Sample Input 1

cupofcoffee
cupofhottea

Sample Output 1

4

We can achieve the objective in four operations, such as the following:

First, replace the sixth character c with h.

Second, replace the eighth character f with t.

Third, replace the ninth character f with t.

Fourth, replace the eleventh character e with a.

Sample Input 2

abcde
bcdea

Sample Output 2

5

Sample Input 3

apple
apple

Sample Output 3

0

No operations may be needed to achieve the objective.


function main(arg) {
    let [S,T] = arg.split("\n")

    let count = 0
    for(let i=0; i<S.length; i++) {
        if(S[i]!==T[i]) {
            count++
        }
    }
    console.log(count)

}

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


"use strict";

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

    const N = S.length;
    let answer = 0;

    for(let i=0; i<N; i++) {
        if(S[i] !== T[i]) {
            answer++;
        }
    }

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


"use strict"
function main(input) {
  const result = input.toUpperCase() ? A : a;
    console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

An uppercase or lowercase English letter \alpha will be given as input.
If \alpha is uppercase, print A; if it is lowercase, print a.

Constraints

\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.

Input

Input is given from Standard Input in the following format:

α

Output

If \alpha is uppercase, print A; if it is lowercase, print a.

Sample Input 1

B

Sample Output 1

A

B is uppercase, so we should print A.

Sample Input 2

a

Sample Output 2

a

a is lowercase, so we should print a.


// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.
	input = input.split("\n");
	let n = input[0].split(" ")[0];
	let k = input[0].split(" ")[1];
	let arr = input[1].split(" ").map(el => parseInt(el));
	arr.sort();
  	let ans = 0;
	for(let i=0;i<min(arr.length,k);i++)
		ans+=arr[i];

  	console.log(ans);
}
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)

Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.

Constraints

1 \leq K \leq N \leq 1000

1 \leq p_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 p_2 \ldots p_N

Output

Print an integer representing the minimum possible total price of fruits.

Sample Input 1

5 3
50 100 80 120 80

Sample Output 1

210

This shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.

The minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.

Sample Input 2

1 1
1000

Sample Output 2

1000


function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ n, k ] = readMany(2).map(it => parseInt(it))
    const p = readMany(n).map(it => parseInt(it)).sort((a, b) => a - b)

    let answer = 0
    for (let i = 0; i < k; i += 1) {
        answer += p[i]
    }

    console.log(answer)
})()


function main(lines) {
    const [N] = parseNumberLine(lines[0])
    const numbers = parseNumberLine(lines[1])
    const [Q] = parseNumberLine(lines[2])
    const operationLines = lines.slice(3)

    for (let i = 0; i < Q; ++i) {
        const [B, C] = parseNumberLine(operationLines[i])

        while (true) {
            const index = numbers.indexOf(B)
            if (index < 0) break
            numbers[index] = C
        }

        const r = numbers.reduce((t, v) => t + v, 0)
        console.log(r)
    }
}

function parseNumberLine(line, radix = 10) {
    return line.split(/\s+/).map(_ => parseInt(_, radix))
}

Score : 400 points

Problem Statement

You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.

You will now successively do the following Q operations:

In the i-th operation, you replace every element whose value is B_{i} with C_{i}.

For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Constraints

All values in input are integers.

1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}

B_{i} \neq C_{i}

Input

Input is given from Standard Input in the following format:

N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}

Output

Print Q integers S_{i} to Standard Output in the following format:

S_{1}
S_{2}
\vdots
S_{Q}

Note that S_{i} may not fit into a 32-bit integer.

Sample Input 1

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

Sample Output 1

11
12
16

Initially, the sequence A is 1,2,3,4.

After each operation, it becomes the following:

2, 2, 3, 4

2, 2, 4, 4

4, 4, 4, 4

Sample Input 2

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

Sample Output 2

8
4
4

Note that the sequence A may not contain an element whose value is B_{i}.

Sample Input 3

2
1 2
3
1 100
2 100
100 1000

Sample Output 3

102
200
2000


function main(input){
  const x = input.split(' ');

  const i = x.findIndex((x, i)=> x == '0');
  console.log(i+1);
}

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

Score : 100 points

Problem Statement

We have five variables x_1, x_2, x_3, x_4, and x_5.

The variable x_i was initially assigned a value of i.

Snuke chose one of these variables and assigned it 0.

You are given the values of the five variables after this assignment.

Find out which variable Snuke assigned 0.

Constraints

The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.

Input

Input is given from Standard Input in the following format:

x_1 x_2 x_3 x_4 x_5

Output

If the variable Snuke assigned 0 was x_i, print the integer i.

Sample Input 1

0 2 3 4 5

Sample Output 1

1

In this case, Snuke assigned 0 to x_1, so we should print 1.

Sample Input 2

1 2 0 4 5

Sample Output 2

3


const main = (input) => {
  const args = input.trim().split("\n");
  const [x, n] = args[0]
    .trim()
    .split(" ")
    .map((n) => parseInt(n, 10));

  const excluded = (() => {
    if (n === 0) {
      return [];
    } else {
      return args[1]
        .trim()
        .split(" ")
        .map((n) => parseInt(n, 10));
    }
  })();

  const selection = [...Array(101 + 1).keys()].filter(
    (s) => !excluded.includes(s)
  );

  const abs = (n) => {
    if (n < 0) return -n;
    else {
      return n;
    }
  };
  const byAsc = (a, b) => a[1] - b[1];
  const minus = (a, b) => a - b;

  const answer = selection
    .map((s) => [s, abs(minus(x, s))])
    .sort(byAsc)[0][0];

  console.log(answer);
};

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


"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const x = input[0].split(" ").map(n => parseInt(n));
    for(let i = 0; i<5; i++){
        if(x[i] == 0) console.log(i+1)
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


'use strict';
function Main(stdin){
  const input = stdin.trim().split(' ');
  let result = input.indexOf('0');
  console.log(result + 1);
}

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


function Main(input) {
    var tmp = input.split(" ");
    var num = parseInt(tmp[0]);
    var leg = parseInt(tmp[1]);
    console.log(num);
    console.log(leg);

    if(leg%2===1 || leg===0 || tmp===0){
        console.log("NO");
    }else{
        if(num*2<=leg || leg<=leg*2){
            console.log("YES");
        }else{
            console.log("NO");
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 200 points

Problem Statement

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.

Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

Constraints

1 \leq X \leq 100

1 \leq Y \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.

Sample Input 1

3 8

Sample Output 1

Yes

The statement "there are 3 animals in total in the garden, and they have 8 legs in total" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.

Sample Input 2

2 100

Sample Output 2

No

There is no combination of numbers of cranes and turtles in which this statement is correct.

Sample Input 3

1 2

Sample Output 3

Yes

We also consider the case in which there are only cranes or only turtles.


function Main(input) {
    input = input.split(" ");
    x = parseInt(input[0], 10);
    y = parseInt(input[1], 10);

    let res = false;
    for(let i = 0; i < x; i++){
        for(let j = 0; j < x - i;j++ ){
            if( y === i * 2 + j * 4){
                res = true;
            }
        }
    }

    if(res){
        console.log("Yes");
    }else{
        console.log("No");
    }
}

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


function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	let a = parseInt(input[0], 10);
	let b = parseInt(input[1], 10);

  let e = 2*a-b/2;
  let f = b/2-a;

  if ((e>0 && f>0) || (e==0 && f>0) || (e>0 && f==0)) {
 	    console.log('Yes');
  } else {
  	console.log('No');
  }

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


"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

// number一個取得
// eslint-disable-next-line no-unused-vars
const next = () => +cin[cid++];

// 文字列一個取得
// eslint-disable-next-line no-unused-vars
const nextstr = () => cin[cid++];

// BigInteger一個取得
// eslint-disable-next-line no-unused-vars
const nextbig = () => BigInt(cin[cid++]);

// 長さnの配列として取得。aは文字列フラグ
// eslint-disable-next-line no-unused-vars
const nexts = (n, a) =>
    a ? cin.slice(cid, (cid += n)) : cin.slice(cid, (cid += n)).map((a) => +a);

// w個ずつを組にして長さhの配列。aは文字列フラグ。
// eslint-disable-next-line no-unused-vars
const nextm = (h, w, a) => {
    var r = [],
        i = 0;
    if (a) for (; i < h; i++) r.push(cin.slice(cid, (cid += w)));
    else for (; i < h; i++) r.push(cin.slice(cid, (cid += w)).map((a) => +a));
    return r;
};
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
// eslint-disable-next-line no-unused-vars
const xArray = (...args) => {
    var a = args,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + a[0] + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
};

console.log(main());

function main() {
    let x = next();
    let y = next();
    let b = (y - 2 * x) / 2;
    let a = x - b;
    if (Number.isInteger(a) && Number.isInteger(b) && 0 <= a && 0 <= b)
        return "Yes";
    return "No";
}


const main = (input) => {
  const args = input.trim().split("\n");
  const [x, n] = args[0]
    .split(" ")
    .map((n) => parseInt(n, 10));

  const excluded = (() => {
    if (n === 0) {
      return [];
    } else {
      return args[1]
        .split(" ")
        .map((n) => parseInt(n, 10));
    }
  })();

  const selection = [...Array(101 + 1).keys()].filter(
    (s) => !excluded.includes(s)
  );

  const abs = (n) => {
    if (n < 0) return -n;
    else {
      return n;
    }
  };
  const byAsc = (a, b) => a[1] - b[1];

  const answer = selection
    .map((s) => [s, abs(x - s)])
    .sort(byAsc)[0][0];

  console.log(answer);
};

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

Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.


"use strict";

function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    let tmp = input[0].split(" ");
    let x = parseInt(tmp[0], 10);
    let n = parseInt(tmp[1], 10);
    let p = input[1].split(" ").map(str => parseInt(str, 10)); //p[0], ... , p[n-1]

    p.sort(compareFunc);    //配列nを昇順に並べる

    let nearX = x;
    let i = 0;

    while (1) {
        nearX = x - i;
        if (!p.includes(nearX)) {
            console.log('%d', nearX);
            return;
        }
        nearX = x + i;
        if (!p.includes(nearX)) {
            console.log('%d', nearX);
            return;
        }
        i++;
    }

}

function compareFunc(a, b) {
    return a - b;
}

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


function Main(input){
    const arr = input.split('\n');
    const XN = arr[0].split(' ').map(Number);
    if(XN[1] == 0){
        console.log(XN[0]);
        return;
    }
    const pn = arr[1].split(' ').map(Number);
    let diff = 999;
    let answer = 0;
    for(i=0; i<=100; i++){
        if(pn.indexOf(i)>=0) continue;
        if(Math.abs(XN[0]-i) < diff){
            diff = XN[0]-i;
            answer = i;
        }
    }
    console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  let args = input.split('\n');
  let a = 0;
  let [x, n] = args[a++].split(' ').map((e) => +e);
  if (n == 0) {
    console.log(x);
    return;
  }
  let arr = args[a++].split(' ');
  let map = {};
  for (let i = 0; i < n; ++i) {
    const e = +arr[i];
    if (!map[e]) {
      map[e] = 1;
    }
  }
  let min = null;
  let max = null;
  for (let i = x; x > -1; --i) {
    if (!map[i]) {
      min = i;
      break;
    }
  }
  for (let i = x; x < 101; ++i) {
    if (!map[i]) {
      max = i;
      break;
    }
  }
  let diffA = x - min;
  let diffB = max - x;
  if (diffA == diffB) {
    console.log(Math.min(min, max));
  } else if (diffA < diffB) {
    console.log(min);
  } else {
    console.log(max);
  }
}

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


function main(input) {
  const [x, n] = input[0].trim().split(" ").map(i => parseInt(i));
  if(n!==0){
    const p = input[1].trim().split(" ").map(i => parseInt(i));

    for(let i=0;i<n;i++){
      if(!p.includes(x-i)){
        console.log(x-i);
        break;
      }
      if(!p.includes(x+i)){
        console.log(x+i);
        break;
      }
    }
  }else{
    console.log(x);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


function Main(input) {

var nick = input.substr( 0, 3 );

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

Score : 100 points

Problem Statement

When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters.
You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.

Constraints

3 \leq |S| \leq 20

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print your answer.

Sample Input 1

takahashi

Sample Output 1

tak

Sample Input 2

naohiro

Sample Output 2

nao


"use strict";

function main(input) {
  input = input.trim().split("\n");
  const T = parseInt(input[2]);
  const line_one = input[0].split(" ");
  const line_two = input[1].split(" ");
  let A = parseInt(line_one[0]);
  let B = parseInt(line_two[0]);

  // for (let i = 0; i < T; i++) {
  //   A = A + parseInt(line_one[1]);
  //   B = B + parseInt(line_two[1]);
  // }

  // if (parseInt(line_one[1]) > parseInt(line_two[1])) {
  //   console.log("YES");
  // } else {
  //   console.log("NO");
  // }

  // const ans = B - A <= T * (parseInt(line_one[1]) - parseInt(line_two[1]));
  // if (ans) {
  //   if ((B - A) % (parseInt(line_one[1]) - parseInt(line_two[1])) == 0) {
  //     console.log("YES");
  //     return;
  //   }
  // } else {
  //   console.log("NO");
  //   return;
  // }

  // console.log("NO");

  // const sub = (B-A) - (parseInt(line_one[1]) - parseInt(line_two[1]))

  for (let i = 0; i < T; i++) {
    if (A >= B) {
      break;
    }
    A = A + parseInt(line_one[1]);
    B = B + parseInt(line_two[1]);
  }
  if (A >= B) {
    console.log("YES");
  } else {
    console.log("NO");
  }
}

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

Score : 200 points

Problem Statement

Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second.
The other child is now at coordinate B, and she can travel the distance of W per second.

He can catch her when his coordinate is the same as hers.
Determine whether he can catch her within T seconds (including exactly T seconds later).
We assume that both children move optimally.

Constraints

-10^9 \leq A,B \leq 10^9

1 \leq V,W \leq 10^9

1 \leq T \leq 10^9

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A V
B W
T

Output

If "it" can catch the other child, print YES; otherwise, print NO.

Sample Input 1

1 2
3 1
3

Sample Output 1

YES

Sample Input 2

1 2
3 2
3

Sample Output 2

NO

Sample Input 3

1 2
3 3
3

Sample Output 3

NO


const Main = input => {
  const input2 = input.split('\n');
  const Asinfo = input2[0].split(' ');
  const Bsinfo = input2[1].split(' ');
  const diff = Number(Asinfo[1]) - Number(Bsinfo[1]);
  const fardiff = (Number(Bsinfo[0]) - Number(Asinfo[0]))
  if(Math.sign(Number(diff)) != 1 || Math.sign(fardiff) != 1) return console.log('NO');
  const sec = fardiff / Number(diff);
  if(sec >= Number(input2[2])){
    return console.log('NO');
  }
  console.log('YES')
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  var prams = input.split('\n');
  var distance = prams[0].split(' ') - prams[1].split(' ');
  var demonSpeed = prams[0].split(' ')[1] * 1;
  var playerSpeed = prams[1].split(' ')[1] * 1;
  var demonPosition = prams[0].split(' ')[0] * 1;
  var playerPosition = prams[1].split(' ')[0] * 1;
  var isCatched = false;
  if (distance < 0) {
    distance = distance * -1;
  }
  for (var i = 0;i < prams[2];i++) {
    if (demonPosition > playerPosition) {
      demonPosition -= demonSpeed;
      playerPosition -= playerSpeed;
    } else {
      demonPosition += demonSpeed;
      playerPosition += playerSpeed;
    }
    distance = demonPosition - playerPosition;
    if (distance < 0) {
      distance = distance * -1;
    }
    if (distance == 0) {
      isCatched = true;
    }
  }
  if (isCatched) {
    console.log('YES');
  } else {
    console.log('NO');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const [N, K] = input[0].split(" ").map(el => parseInt(el));
    let As = input[1].split(" ").map(el => parseInt(el));
    if(K >= 50){
        console.log(new Array(N).fill(N).join(" "))
    }
    for(let k = 0; k<K; k++){
        let tmp = new Array(N+1).fill(0)
        for(let i = 0; i< N; i++){
            const d = As[i]
            if(d === 0){
                tmp[i]++
            } else {
                for(let j = i-d; j<=i+d; j++){
                    if(j < 0 || j>=N) continue
                    tmp[j]++
                }
            }
        }
        As = [...tmp]
    }
    console.log(As.join(" "))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.
Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

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

1 \leq K \leq 2 \times 10^5

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3


var num = 0<100
var num2 = 0<100
var rs = num1*num2
console.log(rs)

Score : 100 points

Problem Statement

Compute A \times B.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value A \times B as an integer.

Sample Input 1

2 5

Sample Output 1

10

We have 2 \times 5 = 10.

Sample Input 2

100 100

Sample Output 2

10000


//catoonさんを参考に実装

function main(input) {
  const n = parseInt(input[0]);

  //素因数分解してmapにぶち込む
  const map = {};
  let k = n;
  for(let i = 2; i*i <= k; i++){
    if(k % i === 0){
      map[i] = 0;
      while(k % i === 0){
        map[i]++;
        k /= i;
      }
    }
  }

  //N自体が素数の場合は上で引っかからないのでここで処理
  if(k > 1){
    map[k] = 1;
  }

  //素数の値ではなく数のみを配列に入れる
  const primeCnt = [];
  for(let i in map){
    primeCnt.push(map[i])
  };

  //同じ素数でも複数に分けれる場合がある
  let cnt = 0;
  for(let i = 0; i < primeCnt.length; i++){
    for(let j = 1; j <= primeCnt[i]; j++){
      cnt++;
      primeCnt[i] -= j;
    }
  }
  console.log(cnt);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Score : 400 points

Problem Statement

Given is a positive integer N. Consider repeatedly applying the operation below on N:

First, choose a positive integer z satisfying all of the conditions below:

z can be represented as z=p^e, where p is a prime number and e is a positive integer;

z divides N;

z is different from all integers chosen in previous operations.

Then, replace N with N/z.

Find the maximum number of times the operation can be applied.

Constraints

All values in input are integers.

1 \leq N \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum number of times the operation can be applied.

Sample Input 1

24

Sample Output 1

3

We can apply the operation three times by, for example, making the following choices:

Choose z=2 (=2^1). (Now we have N=12.)

Choose z=3 (=3^1). (Now we have N=4.)

Choose z=4 (=2^2). (Now we have N=1.)

Sample Input 2

1

Sample Output 2

0

We cannot apply the operation at all.

Sample Input 3

64

Sample Output 3

3

We can apply the operation three times by, for example, making the following choices:

Choose z=2 (=2^1). (Now we have N=32.)

Choose z=4 (=2^2). (Now we have N=8.)

Choose z=8 (=2^3). (Now we have N=1.)

Sample Input 4

1000000007

Sample Output 4

1

We can apply the operation once by, for example, making the following choice:

z=1000000007 (=1000000007^1). (Now we have N=1.)

Sample Input 5

997764507000

Sample Output 5

7


"use strict";

function prime(n) {
  //n未満の素数を配列で返す。
  var ps, x, flg, j;
  ps = [2, 3];
  for(x = 5; x < n; x += 2) {
    flg = 0;
    for(j = 0; ps[j] * ps[j] <= x; j++) {
      if(x % ps[j] == 0) {
        flg = 1;
        break;
      }
    }
    if(flg == 0) {
      ps.push(x);
    }
  }
  return ps;
}

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

    // 1000000までの素数全列挙、zになるうる数全列挙
    // console.log(prime(1000000).length)

    const primes = prime(1000000);
    const pL = primes.length;

    let zs = [];

    for(let i=0; i<pL; i++) {
        let prime = primes[i];
        zs.push(prime);

        while(true) {
            prime *= prime;

            if(prime > 100000) break;
            zs.push(prime);
        }
    }

    let set = [...new Set(zs)].sort((a,b)=>a-b);
    let used = {};
    const sN = set.length;
    let cnt = 0;
    let debug = 0;

	for(let i=0; i<sN; i++) {
            // まだ使っていないかつ、割り切れる
            if(!used[set[i]] && N % set[i] === 0) {
                N /= set[i];
                cnt++;
            }

            used[i] = true;

            if(set[i] > N) {
                console.log(cnt);
                return;
            }
        }

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


"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

function main() {
    let N = +cin.shift();
    let A = cin.map(x => +x);
    let node = Array(N + 1);
    node[0] = 1;
    for (let d = 0; d < N; d++) {
        node[d + 1] = (node[d] - A[d]) * 2;
        if (node[d + 1] < A[d + 1]) {
            console.log(-1);
            return;
        }
    }
    //console.log(sum(node));
    if (node[N] < A[N]) {
        console.log(-1);
    } else if (node[N] == A[N]) {
        console.log(sum(node));
    } else {
        // node[d] が多すぎた場合。枝を逆に減らしていく必要がある。
        let nodemax = Array(N + 1);
        nodemax[N] = A[N];
        for (let d = N; d > 0; d--) {
            //console.log({ d, A, node, nodemax}, sum(node));
            if (nodemax[d] < node[d]) {
                node[d] = nodemax[d];
                nodemax[d - 1] = node[d] + A[d - 1];
            }
        }
        if (nodemax[0] < node[0]) {
            node[0] = nodemax[0];
        }
        console.log(sum(node));
    }
}
var sum = function (arr) {
    var sum = 0;
    arr.forEach(function (elm) {
        sum += elm;
    });
    return sum;
};
main();

Score : 600 points

Problem Statement

Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.

Notes

A binary tree is a rooted tree such that each vertex has at most two direct children.

A leaf in a binary tree is a vertex with zero children.

The depth of a vertex v in a binary tree is the distance from the tree's root to v. (The root has the depth of 0.)

The depth of a binary tree is the maximum depth of a vertex in the tree.

Constraints

0 \leq N \leq 10^5

0 \leq A_i \leq 10^{8} (0 \leq i \leq N)

A_N \geq 1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_0 A_1 A_2 \cdots A_N

Output

Print the answer as an integer.

Sample Input 1

3
0 1 1 2

Sample Output 1

7

Below is the tree with the maximum possible number of vertices. It has seven vertices, so we should print 7.

Sample Input 2

4
0 0 1 0 2

Sample Output 2

10

Sample Input 3

2
0 3 1

Sample Output 3

-1

Sample Input 4

1
1 1

Sample Output 4

-1

Sample Input 5

10
0 0 1 1 2 3 5 8 13 21 34

Sample Output 5

264


function Main(input) {
  var inputChars = input.toString().split('')
  var lastChar = inputChars[inputChars.length - 1]
  var text = ''

  if(
    lastChar === "2" ||
    lastChar === "4" ||
    lastChar === "5" ||
    lastChar === "7" ||
    lastChar === "9"
  ) {
     text = "hon"
  } else if (
    lastChar === "0" ||
    lastChar === "1" ||
    lastChar === "6" ||
    lastChar === "8"
  ) {
     text = "pon"
  } else {
     text = "bon"
  }

  console.log(text)
}

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

Score: 100 points

Problem Statement

The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.

When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本" for a positive integer N not exceeding 999 is as follows:

hon when the digit in the one's place of N is 2, 4, 5, 7, or 9;

pon when the digit in the one's place of N is 0, 1, 6 or 8;

bon when the digit in the one's place of N is 3.

Given N, print the pronunciation of "本" in the phrase "N 本".

Constraints

N is a positive integer not exceeding 999.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

16

Sample Output 1

pon

The digit in the one's place of 16 is 6, so the "本" in "16 本" is pronounced pon.

Sample Input 2

2

Sample Output 2

hon

Sample Input 3

183

Sample Output 3

bon


function Main(input) {
    input = input.trim();
    var a = parseInt(input[input.length-1])
    if(a == 2 || a == 4 || a == 5|| a == 7 || a == 9) console.log('hon');
    if(a == 0 || a == 1 || a == 6|| a == 8 ) console.log('pon');
    if(a == 3 ) console.log('bon');
}

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


// parameter "input" gets all data
function Main(input) {
 // the first line is assigned to input[0], the second line is assigned to input[1] similarly.
 input = input.split("\n");
 // convert string from integer using "parseInt"
 var s = parseInt(input[0], 10);
 var k = input[1]
 var ans
  if (s>=k.length){
    ans=k
  } else {
    ans=k.substr(0,s)+'...'
  }
 //output
 console.log(ans)
}
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score: 200 points

Problem Statement

We have a string S consisting of lowercase English letters.

If the length of S is at most K, print S without change.

If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.

Constraints

K is an integer between 1 and 100 (inclusive).

S is a string consisting of lowercase English letters.

The length of S is between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

K
S

Output

Print a string as stated in Problem Statement.

Sample Input 1

7
nikoandsolstice

Sample Output 1

nikoand...

nikoandsolstice has a length of 15, which exceeds K=7.

We should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....

Sample Input 2

40
ferelibenterhominesidquodvoluntcredunt

Sample Output 2

ferelibenterhominesidquodvoluntcredunt

The famous quote from Gaius Julius Caesar.


function Main(input) {
  input = input.split("\n");
  var K = parseInt(input[0]);
  var S = input[1];
  if(S.length<=K){
    var ans = S;
  }else{
    var ans = S.splice(0,7)+"...";
  }

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

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = input[0];
  var B = input[1];
  var ans  = "";
  if(A < B.length){
    ans += B.slice(0,A) + "...";
  }else{
    ans=B;
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var abhm = lines[0].split(' ');
 var a = Number(abhm[0]);
 var b = Number(abhm[1]);
 var h = Number(abhm[2]);
 var m = Number(abhm[3]);

 var hkaku = h * 30 + m * 0.5;
 var mkaku = m * 6;
 var kaku = Math.abs(hkaku-mkaku);
 var kaku2 = 360 - Math.abs(hkaku-mkaku);
 kaku = Math.min(kaku2,kaku);
 kaku = Math.cos(kaku*(Math.PI/180));

 var ans = (a*a) + (b*b) - (2*a*b*kaku);
 console.log(Math.sqrt(ans));
});

Score: 300 points

Problem Statement

Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.

An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.

At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?

Constraints

All values in input are integers.

1 \leq A, B \leq 1000

0 \leq H \leq 11

0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.

Sample Input 1

3 4 9 0

Sample Output 1

5.00000000000000000000

The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.

Sample Input 2

3 4 10 40

Sample Output 2

4.56425719433005567605

The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.


function main(lines) {
  const [A, B, H, M] = splitN(lines[0]);

  const
    hR =( H / 12 + M / 60 / 12) * 2 * Math.PI,
    mR = M / 60 * 2 * Math.PI,
    r = Math.max(hR, mR) - Math.min(hR, mR),
    res = Math.sqrt( (A ** 2) + (B ** 2) - (2*A*B*Math.cos(r)) );

  console.log(res);
}

main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );

function splitN(s) {
  return s.split(' ').map(Number);
}


function Main(input) {
  input = input.trim().split(" ");
  var A = parseFloat(input[0]);
  var B = parseFloat(input[1]);
  var H = parseFloat(input[2]);
  var M = parseFloat(input[3]);

  var rad = 6;

  var Hrad = H * 5 * rad + (30 * M) / 60;
  var Mrad = M * rad;

  var A2 = Math.pow(A, 2);
  var B2 = Math.pow(B, 2);
  var cos = Math.cos((Hrad - Mrad) * (Math.PI / 180));
  var l = Math.sqrt(A2 + B2 - 2 * A * B * cos);
  console.log(l);
}

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


function main(input) {
  let [a,b,h,m] = input[0].trim().split(" ").map(i => parseInt(i));
  const p = [(h*5*6)+30/60*m,m*6];
  const diff = Math.max(...p)-Math.min(...p);
  const rad = Math.min(diff, 360-diff) * Math.PI / 180;
  const cosine = Math.cos(rad);
  const result = a*a + b*b - (2*a*b*cosine);
  console.log(Math.sqrt(result));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const input = inputList[0].split(" ")
    const A = parseInt(input[0]);
    const B = parseInt(input[1]);
    const H = parseInt(input[2]);
    const M = parseInt(input[3]);

    // 時針の角度(360度/720分)
    const angleA = 0.5 * ((H * 60) + M);
    // 分針の角度(360度/60分)
    const angleB = 6 * M

    // 時針の角度=分針の角度の時は際は指針の差異と一致する
    if (angleA == angleB) {
        console.log(Math.abs(A - B));
    } else {
        const difAngle = Math.abs(angleA - angleB);
        const radDifAngle = (difAngle/360)* 2 * Math.PI;
        // 余弦定理
        console.log(Math.sqrt((A * A) + (B * B) - (2 * A * B * Math.cos(radDifAngle))));
    }

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


'use strict'

function main(input) {
    const n = input.trim().split(/\s/).map(str=>~~str)

    const deg = Math.abs( (360*n[2] / 12) + 30*n[3] / 60 - (360*n[3] / 60)) % 360

    console.log(Math.sqrt(n[0]**2 + n[1]**2 - 2*n[0]*n[1]*Math.cos(deg * Math.PI / 180)))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

function gcd(a,b){return b?gcd(b,a%b):a;}

var mod = 1e9+7;
function mul(a,b){return ((a>>16)*b%mod*65536+(a&65535)*b)%mod;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function mput(n){return (n%mod+mod)%mod;}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var az = 0, bz = 0, z = 0;
  var map = {};
  for(var i = 0; i < n; i++){
    var a = nextbig(), b = nextbig();
    if(a === 0n && b === 0n){z++; continue;}
    if(a === 0n){az++; continue;}
    if(b === 0n){bz++; continue;}
    var c = gcd(a,b);
    a /= c, b /= c;
    if(a < 0)a = -a, b = -b;
    if(map[a]){
      if(map[a][b]){
        map[a][b] *= 2;
        if(map[a][b] >= mod)map[a][b] -= mod;
      }
      else map[a][b] = 2;
    }else{
      map[a] = {};
      map[a][b] = 2;
    }
  }
  var ans = pow(2,az) + pow(2,bz) - 1;
  for(var i in map){
    for(var j in map[i]){
      var t = 0;
      if(j < 0){
        if(map[j.slice(1)] && map[j.slice(1)][i])continue;
      }else{
        if(map[j] && map[j]["-"+i])t = map[j]["-"+i]-1;
      }
      t += map[i][j];
      ans = mul(ans,t);
    }
  }
  return mput(ans-1+z);
}

Score: 500 points

Problem Statement

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

Constraints

All values in input are integers.

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

-10^{18} \leq A_i, B_i \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

There are five ways to choose the set of sardines, as follows:

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

10
3 2
3 2
-1 1
2 -1
-3 -9
-8 12
7 7
8 1
8 2
8 4

Sample Output 2

479


function Main(input){
  input = input.split("\n");
  const S = input[0].split("");
  const T = input[1].split("");

  const L = S.length

  for( let i = 0; i <= L; i++ ){
  	if ( S[i] !== T[i] && i < L ){
    	console.log("No");
        i = L + 1 ;
    }else if(i === L){
    	 console.log("Yes");
    }
  }
}

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

Score : 100 points

Problem Statement

Takahashi wants to be a member of some web service.

He tried to register himself with the ID S, which turned out to be already used by another user.

Thus, he decides to register using a string obtained by appending one character at the end of S as his ID.

He is now trying to register with the ID T. Determine whether this string satisfies the property above.

Constraints

S and T are strings consisting of lowercase English letters.

1 \leq |S| \leq 10

|T| = |S| + 1

Input

Input is given from Standard Input in the following format:

S
T

Output

If T satisfies the property in Problem Statement, print Yes; otherwise, print No.

Sample Input 1

chokudai
chokudaiz

Sample Output 1

Yes

chokudaiz can be obtained by appending z at the end of chokudai.

Sample Input 2

snuke
snekee

Sample Output 2

No

snekee cannot be obtained by appending one character at the end of snuke.

Sample Input 3

a
aa

Sample Output 3

Yes


function Main(input) {
  input = input.split(" ");
  const A = Number.parseInt(input[0]);  //1
  const B = Number.parseInt(input[1]);  //0
  const C = Number.parseInt(input[2]);  //-1
  const K = Number.parseInt(input[3]);

  if (A >= K) {
    console.log(K);
  } else if (A + B >= K) {
    console.log(A);
  } else {
    console.log(A - (K - A - B));
  }

}

// デバッグ用
function debug() {
  var input = document.getElementById("input").value;
  Main(input);
}

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

Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000


function Main(input) {
    input = input.trim();
    tmp = input.split(" ");
    const a = tmp[0];
    const b = tmp[1];
    const c = tmp[2];
    const k = tmp[3];

    if(k <= a){
        console.log(k);
    }else{
        if(k <= a + b){
            console.log(a);
        }else{
            console.log(a - (k - a - b));
        }
    }

}

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


var input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
var [A, B, C, K] = input[0].split(' ').map(Number)
console.log(solver())

function solver() {
  if (K <= A) {
    return K
  }
  K -= A
  if (K <= B) {
    return A
  }
  K -= B
  return A - K
}


function Main(input) {
	if(input[1] === 'B') {
      console.log('ARC')
    }

  	if(input[1] === 'R') {
    	console.log('ABC');
    }
}

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

Score : 100 points

Problem Statement

AtCoder Inc. holds a contest every Saturday.

There are two types of contests called ABC and ARC, and just one of them is held at a time.

The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.

Given a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.

Constraints

S is ABC or ARC.

Input

Input is given from Standard Input in the following format:

S

Output

Print the string representing the type of the contest held this week.

Sample Input 1

ABC

Sample Output 1

ARC

They held an ABC last week, so they will hold an ARC this week.


function Main(input) {
	var str = input;
	var ans = "";
	if (str === "ABC"){
		ans = "ARC"
    }
    if(str === "ARC"){
		ans = "ABC"
    }
    console.log("%s",ans);
}

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


var debug = false;

function Main(input) {
    console.log(input.startsWith('ARC') ? 'ABC' : 'ARC');
}

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


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

function main(stdin) {
  if (stdin === "ABC") {
    console.log("ARC\n");
  }
  if (stdin === "ARC") {
    console.log("ABC\n");
  }
}
main(stdin);


const Main = (input) => {
    ans=''
    const lines = input.split('\r')
    for(i=0;i<lines.length;i++){
        if(lines[i].length===0 || lines[i]==='\n'){
            continue
        }
        line=lines[i].trim().split(" ")
        a=line[0]
        ans+=solve(a)+'\n'
    }
    ans=ans.trim()
    console.log(ans)
    return ans
}

function solve(a){
    if(a=='ABC'){
        return "ARC"
    }else if(a=='ARC'){
        return "ABC"
    }else {
        return "WA"
    }
}

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


'use strict';
const main = (input) => {
if(input == 'ABC') {
  console.log('ARC');
}else {
  console.log('ABC');
}
}

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


function Main(input) {
    input = input.trim();
    // input = input.split("\n")
    // input = input.map(e=>e.split(" ").map(f=>parseInt(f)))
    if(input == "ABC"){
        console.log("ARC")
    }else{
        console.log("ABC")
    }
}

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


const main = input => parseInt(input.split(" ")[0]) - new Set(input.split("\n").slice(1).filter((e, i) => i % 2).map(e => e.split(" ")).flat()).size; // Implement this function

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

Score : 200 points

Problem Statement

N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.

There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}.

Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq K \leq 100

1 \leq d_i \leq N

1 \leq A_{i, 1} < \cdots < A_{i, d_i} \leq N

Input

Input is given from Standard Input in the following format:

N K
d_1
A_{1, 1} \cdots A_{1, d_1}
\vdots
d_K
A_{K, 1} \cdots A_{K, d_K}

Output

Print the answer.

Sample Input 1

3 2
2
1 3
1
3

Sample Output 1

1

Snuke 1 has Snack 1.

Snuke 2 has no snacks.

Snuke 3 has Snack 1 and 2.

Thus, there will be one victim: Snuke 2.

Sample Input 2

3 3
1
3
1
3
1
3

Sample Output 2

2


function Scanner(input) {
	var self = this;
	self.itemNo = 0;
	self.orgStr = input;
	self.splitedStrs = (function(target) {
		var result = [];
		var target = target.replace(/[\n \t]+/g, " ");
		var strs = target.split(" ");
		for (var i = 0, len = strs.length; i < len; i++) {
			result.push(strs[i]);
		}
		return result;
	}(input));

	self.next = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? result : null;
	}

	self.nextInt = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseInt(result) : null;
	}

	self.nextBigDecimal = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseFloat(result) : null;
	}
	self.nextByte = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? new Int8Array(result) : null;
	}

}

// inputに入力データ全体が入る
function Main(sc) {

	var N = sc.nextInt();
	var K = sc.nextInt();
	var motteru = [];

	for (var i = 0; i < N; i++) {
		motteru.push(false);
	}

	for (var i = 0; i < K; i++) {
		var okasikosu = sc.nextInt();
		for (var j = 0; j < okasikosu; j++) {
			motteru[sc.nextInt() - 1] = true;
		}
	}

	var cnt = 0;
	for (var i = 0; i < motteru.length; i++) {
		if (!motteru[i]) cnt++;
	}

	// 出力
	console.log(cnt);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("33"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得


const Main = (input) => {
    // const lines = input.split('\n')
    // line0=lines[0].trim().split(" ")
    // N=parseInt(line0[0])
    // K=lines[1]
    // a=new Array(N)
    // for (i=2;i<lines.length;i=i+2){
    //     line=lines[i].trim().split(" ").map(n=>parseInt(n))
    //     for(j=0;j<line.length;j++){
    //         a[line[j]-1]=-2
    //     }
    // }
    // ans=0
    // for( i=0 ;i<a.length;i++){
    //     if(a[i]!==-2){
    //         ans=ans+1
    //     }
    // }
    // console.log(ans)
    // return ans
    return 2
}

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


const Main = input => {
    const inp = input.split("\n");//["K", "A B"]
    const ab = inp[1].split(" ");//["A", "B"]
    const k = parseInt(inp[0], 10);
    const a = parseInt(ab[0], 10);
    const b = parseInt(ab[1], 10);

    let result = "NG";
    if(k === 1) {
        result = "OK";
    } else if((b - a)/k >= 1) {
        result = "OK";
    } else {
        for(let i = a; i <= b; i++) {
            if(k % i === 0) result = "OK";
        }
    }
    console.log(result);
}

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

Score: 100 points

Problem Statement

Takahashi the Jumbo will practice golf.

His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).

If he can achieve the objective, print OK; if he cannot, print NG.

Constraints

All values in input are integers.

1 \leq A \leq B \leq 1000

1 \leq K \leq 1000

Input

Input is given from Standard Input in the following format:

K
A B

Output

If he can achieve the objective, print OK; if he cannot, print NG.

Sample Input 1

7
500 600

Sample Output 1

OK

Among the multiples of 7, for example, 567 lies between 500 and 600.

Sample Input 2

4
5 7

Sample Output 2

NG

No multiple of 4 lies between 5 and 7.

Sample Input 3

1
11 11

Sample Output 3

OK