function main(input) {
    var A = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
    var reducer = (accumulator, currentValue) => accumulator * currentValue;
    console.log(A.reduce(reducer))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

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

Sample Output 3

0

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.


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	int n;
	cin >> n;
	unsigned long long ans = 1;
	int f = 0;
	rep(i, n){
		unsigned long long in;
		cin >> in;
		unsigned long long ans0 = ans;
		unsigned long long in0 = in;
		int ansk = 0;
		int ink = 0;
		ans *= in;
		while(ans0 >= 10){
			ans0 /= 10;
			ansk++;
		}
		while(in0 >= 10){
			in0 /= 10;
			ink++;
		}
		if(ink + ansk > 18){
			f = 1;
			ans = 1;
		}
		if(ink + ansk == 18 && ans0 * in0 > 1){
			f = 1;
			ans = 1;
		}
		//cout << ink << ' '  << ansk << endl;

		if(ans > 1000000000000000000){
			f = 1;
			ans = 1;
		}
	}
	if(ans == 0){
		cout << 0 << endl;
	}else if(f == 1){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
	return 0;
}


function main(lines) {
  const N = lines[0];
  const a = lines[1].split(' ').map(BigInt);

  if (a.includes(BigInt(0))) return console.log(0);
  let res = BigInt(1);
  for (let i = 0; i < N; i++) {
    res *= a[i];
    if (res > BigInt(10) ** BigInt(18)) {
      res = BigInt(-1);
      break;
    }
  }

  console.log(res.toString());
}

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

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


function Main(input) {
	var str = input;
	var ans = 1;
	var count = 1;
	var str = str.split("\n");
	var a = str[1].split(" ");
	for(var i = 0;i<a.length;i++){
		a[i]=Number(a[i]);
		ans = ans/1000 *(a[i]/1000)*1000000;
		if(ans > 10**18){
			ans = -1;
          break;
		}
    }

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


function Main(input) {
	var str = input;
	var ans = -1;
	var count = 1;
	var str = str.split("\n");
	var a = str[1].split(" ");
	setTimeout(function() {
	for(var i = 0;i<a.length;i++){
		a[i]=Number(a[i]);
		ans = ans *(a[i]/100)*100;
		if(ans > 10**18){
			ans = -1;
          break;
		}
    }
     }, 0);
   console.log(ans);
   }
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line1 = inputLines[1];
	const line1vars = line1.split(" ");

	const n = parseInt(line0, 10);

	// console.log({
	// 	n: n,
	// 	line1: line1,
	// 	line1vars: line1vars
	// });

	let result = 1;
	let limit = Math.pow(10, 18)

	for (let i = 0; i < n; i++) {
		// if (limit < result) {
		// 	continue;
		// }
		let a = parseInt(line1vars[i], 10);
		result = result * a;
		// console.log({
		// 	a: a,
		// 	result: result,
		// 	limit: limit
		// });

	}
	if (limit <= result) {
		result = -1;
	}
	console.log(result);
// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

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

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


const main = (input) => {
  const [_a, _b] = input.trim().split(' ')
  const a = BigInt(_a)
  const b = BigInt(Math.floor(_b*100))

  return console.log(`${a*b/100n}`)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Score : 300 points

Problem Statement

Compute A \times B, truncate its fractional part, and print the result as an integer.

Constraints

0 \leq A \leq 10^{15}

0 \leq B < 10

A is an integer.

B is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer as an integer.

Sample Input 1

198 1.10

Sample Output 1

217

We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.

Sample Input 2

1 0.01

Sample Output 2

0

Sample Input 3

1000000000000000 9.99

Sample Output 3

9990000000000000


function main(input){
  const [A, B] = input.split(' ').map(Number);
  console.log(Math.trunc(A*(B*100)/100));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


function main(input){
  const [A, B] = input.split(' ').map(Number);
  console.log(Math.trunc(A*B));
}

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


const main = (input) => {
  const [a, b] = input.trim().split(' ')
  const _ans = (BigInt(a)*BigInt(parseInt(b*100, 10))).toString()

  return console.log(_ans.length > 2 ? _ans.slice(0, _ans.length-2) : 0)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))


function Main(input) {
	input = input.trim().split(" ");
	var A = input[0];
	var B = input[1];
	var a1 = parseInt(A.slice(0, -7),10);
	var a2 = parseInt(A.substr(-7, 7),10);
	var b1 = parseInt(B.trim().split(".")[0]);
	var b2 = parseInt(B.trim().split(".")[1]);
	if (isNaN(a1)) a1 = 0;
	if (isNaN(a2)) a2 = 0;
	if (isNaN(b1)) b1 = 0;
	if (isNaN(b2)) b2 = 0;
  	if (b2 < 10 ) b2 *= 10;
	var ANS, ans1, ans2, ansMiddle, tmp;

	ans1 = a1 * (b1 * 100 + b2);
	tmp = String(a2 * (b1 * 100 + b2)).slice(0,-2);
	ansMiddle = parseInt(tmp.slice(0, -5),10);
  	if (isNaN(ansMiddle)) ansMiddle = 0;
	ans2 = parseInt(tmp.substr(-5, 5),10);
	if (isNaN(ans2)) ans2 = 0;
	ans1 = String(ans1 + ansMiddle);
	if (ans1 === '0'){
		ANS = String(ans2);
	} else {

		ANS = ans1 + String(ans2 + 100000).substr(-5,5);
	}
 	console.log(ANS);
}

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


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

function main({ input, load, yesno, math_sum, math_max, math_min, log_json }) {
    const [A] = load(1,1,BigInt)
    let [B] = load()
    B = BigInt(Math.floor(B*1000))
    return (A*B/1000n).toString()
}

let inputs = input.split(/[\s\n]/)
let result = main({
    input,
    yesno: value => value ? 'Yes' : 'No',
    math_sum: numbers => numbers.reduce((acc, cur) => acc + cur, 0),
    load(rows = 1, cols = 1, type = Number) {
        const length = rows * cols
        let result = inputs.splice(0, length)
        if(type !== String) result = result.map(type)
        if(cols > 1) {
            const arrays = new Array(cols)
            for(let col = 0; col < cols; col++) {
                arrays[col] = new Array()
                for(let row = 0; row < rows; row++) {
                    arrays[col].push(result[row * cols + col])
                }
            }
            result = arrays
        }
        return result
    },
    inifinite_loop_preventer() {
        throw new Error("Infinite loop")
    },
    math_max,
    math_min,
    log_json(value) {
        console.log(JSON.stringify(value))
    },
})

if(result === undefined) {
    console.warn("result is undefined")
} else {
    console.log(result)
}

function math_max(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n > result) result = n
    return result
}

function math_min(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n < result) result = n
    return result
}


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  	let [a, b] = input[0].split(' ').map(x => +x)
  	return console.log(Math.floor((a * (b * 100)) / 100))
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

let inputData = '';
let a, b;

process.stdin.on('data', inputStdin => {
  inputData += inputStdin;
});

process.stdin.on('end', _ => {
  inputData = inputData.replace(/\s*$/g, '')
    .split(' ');
  main();
});

function solve() {
  return a * b / 100n;
}

function main() {
  a = BigInt(inputData[0]);
  b = BigInt(Math.floor(inputData[1] * 100));

  process.stdout.write(solve().toString());
}


function main(input) {
    console.log(parseInt((input.split(' ')[0] * input.split(' ')[1]), 10));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


'use strict';
function Main(inputs) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const input = inputs.split("\n");
  const [a, b] = input[0].split(' ').map(Number);
  const c = Math.floor(a * b);
  console.log(c);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main( args ) {
  const tmp = args.split(' ');
  const A = parseInt(tmp[0],10);
  const B = parseFloat(tmp[1])
  console.log(Math.floor(A*B).toString());
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input){
  input = input.split(" ");
  var a = BigInt(input[0]);
  var b = BigInt(input[1].split(".").join(""));
  console.log(String(a*b/100n).split("n").join(""));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


function Main (input) {
  input = input.split("\n")[0].split(" ").map(Number);
  console.log(Math.floor(input[0] * input[1]));
}

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


function Main(input) {
  input = input.split("\n");
  var A = BigInt(input[0].split(" ")[0]);
  var B = BigInt(parseInt(input[0].split(" ")[1].split(".")[0])*100+parseInt(input[0].split(" ")[1].split(".")[1]));
  var ans = A * B /100n;
  var ans = ans.toString();

  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 = Number(input[0]);
  var B = input[1].split(".");
  var C = Number(B[0]);
  var D = Number(B[1]);
  var E = A*D;
  var F = (E.length<=2)?0:Number(String(E).slice(0,-2));
  var ans = A*C + F;
  console.log(Math.floor(ans));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var B = parseInt(Math.floor(Number(input[0].split(" ")[1]))*100);
  var ans = Math.floor(A * B);

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


process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_string = '';

process.stdin.on('data', function (chunk) {
    input_string = chunk;
    const lines = input_string;
    const c = []
    c.push(lines.split(' ').map(value => parseFloat(value)));

    // console.log("c:", c);
    var A = c[0][0];
    var B = c[0][1];

    console.log(Math.floor(A * B));

});


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 ab = lines[0].split(' ');
 var a = BigInt(ab[0]);
 var b = ab[1];

 ans = Number(a) * b;

 console.log(Math.floor(ans));
});


function main(input) {
    const [ a, b ] = input.split(' ')
    const ceiled = Math.ceil(a * b)

    if (ceiled == a * b) {
        console.log(ceiled)
    } else {
        console.log(ceiled - 1)
    }
}

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


function main(input) {
    const [ a, b ] = input.split(' ')
    console.log(Math.ceil(a * b))
}

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


function main(input) {
  let [a, b] = input[0].trim().split(" ").map(i => i);
  a = BigInt(parseInt(a));
  b = parseInt(b.split(".").join(""));
  ans = 0n;

  for(let i=0;i<b;i++){
    ans += a;
  }
  ans = ans + "";

  if(ans.length<=2){
    console.log(0);
  }else{
    const ans1 = ans.slice(0,ans.length-2);
    console.log(ans1);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


function main(input) {
  const inputs = input.trim().split('\n');
  var input1 = inputs[0].split(' ');
  var A = input1[0].split('').reverse();
  var B = input1[1];

  var B1 = B.split('.')[0] - 0;
  var B2 = B.split('.')[1].split('').reverse();

  var temp = Array(A.length + 2 + 1);
  var tempLength = temp.length;

  for (var i = 0; i < tempLength; i++) {
    temp[i] = 0;
  }

  var multi = '';
  for (var i = 0; i < B2.length; i++) {
    for (var j = 0; j < A.length; j++) {
      multi = ('' + ((B2[i] - 0) * (A[j] - 0))).split('').reverse();
      for (var k = 0; k < multi.length; k++) {
        temp[tempLength - i - j - k - 1] += (multi[k] - 0);
        for (var l = tempLength - 1; l >= 0; l--) {
          if (temp[l] >= 10) {
            temp[l] -= 10;
            temp[l - 1] += 1;
          }
        }
      }
    }
  }

  var multi = '';
  for (var i = 0; i < A.length; i++) {
    multi = ('' + (B1 * (A[i] - 0))).split('').reverse();
    for (var k = 0; k < multi.length; k++) {
      temp[tempLength - 2 - i - k - 1] += (multi[k] - 0);
      for (var l = tempLength - 1; l > 0; l--) {
        if (temp[l] >= 10) {
          temp[l] -= 10;
          temp[l - 1] += 1;
        }
      }
    }
  }

  temp = temp.slice(0, -2);

  var cont = true;
  while (cont) {
    if (temp[0] == 0) {
      temp = temp.slice(1);
    } else {
      cont = false;
    }
  }

  if (temp.length == 0) {
    temp.push(0);
  }

  console.log(temp.join(''));
}

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


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const A = BigInt(arg[0].split(" ")[0]);
    const B = BigInt(arg[0].split(" ")[1].split(".").join(""));

    // const J  = BigInt(B.split(".")[0]);
    // const S1 = BigInt(B.split(".")[1].split("")[0]);
    // const S2 = BigInt(B.split(".")[1].split("")[1]);

    // let answer = (A * J) + ((A * S1) / 10n) + ((A * S2) / 100n);

    let answer = A * BigInt(B);
    let length = String(answer).length;

    let temp = answer.toString().split("").slice(0, length - 2).join("");

    if(temp.length) {
        console.log(temp);
    } else {
        console.log(0);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
    // 入力値の分離
	param = input.split(" ");
	var result = param[0] * param[1];
	result = Math.floor(result);
	console.log(parseInt(result));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  const inputs = input.trim().split('\n');
  var input1 = inputs[0].split(' ');
  var A = input1[0].split('').reverse();
  var B = input1[1];

  var B1 = B.split('.')[0] - 0;
  var B2 = B.split('.')[1].split('').reverse();

  var temp = Array(A.length + 2 + 1);
  var tempLength = temp.length;

  for (var i = 0; i < tempLength; i++) {
    temp[i] = 0;
  }

  // 小数点部分の処理
  var multi = '';

  for (var i = 0; i < B2.length; i++) {
    for (var j = 0; j < A.length; j++) {
      multi = ('' + ((B2[i] - 0) * (A[j] - 0))).split('').reverse();
      for (var k = 0; k < multi.length; k++) {
        temp[tempLength - i - j - k - 1] += (multi[k] - 0);
        for (var l = tempLength - 1; l >= 0; l--) {
          if (temp[l] > 10) {
            temp[l] -= 10;
            temp[l - 1] += 1;
          }
        }
      }
    }
  }

  // 整数部分の処理
  var multi = '';
  for (var i = 0; i < A.length; i++) {
    multi = ('' + (B1 * (A[i] - 0))).split('');
    for (var k = 0; k < multi.length; k++) {
      temp[tempLength - 2 - i - k - 1] += (multi[k] - 0);
      for (var l = tempLength - 1; l >= 0; l--) {
        if (temp[l] > 10) {
          temp[l] -= 10;
          temp[l - 1] += 1;
        }
      }
    }
  }

  temp = temp.slice(0, -2);

  var cont = true;
  while (cont) {
    if (temp[0] == 0) {
      temp = temp.slice(1);
    } else {
      cont = false;
    }
  }

  if (temp.length == 0) {
    temp.push(0);
  }

  console.log(temp.join(''));
}

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


function main(input) {
    console.log(Math.floor(input.split(' ')[0] * input.split(' ')[1]));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const input = require("fs").readFileSync("/dev/stdin", "utf8")
const A = input.split(" ")[0]
const B = input.split(" ")[1]

console.log(Math.floor(A * (B * 100) / 100))


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;
	}

}

function Main(sc) {

	var A = BigInt(sc.next());
	var B = sc.nextBigDecimal();

	var B2 = BigInt(parseInt(Math.floor(B * 100));

	var ans = A * B2;
	if (ans >= BigInt(100)) {
		ans = ans.toString();
		ans = ans.substring(0, ans.length - 2);
	} else {
		ans = 0;
	}

	console.log(ans);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("10 1 2 5 3 4 6 7 3 2 4 1 2 2 3 3 4 4 5 3 6 6 7 1 8 8 9 9 10"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得
// for (var i = 0; i < 1000000000; i++) var toDelay = "aaa"; // 1000msくらいの遅延
// console.log(wrtnNos); return;


function Main(input){
    const arr = input.trim().split(' ').map(Number);
    console.log(Math.floor(arr[0]*arr[1]));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


const input = require("fs").readFileSync("/dev/stdin", "utf8")
const A = input.split(" ")[0]
const B = input.split(" ")[1]

console.log(Math.floor(A * B))


function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = Number(input[0]);
  var B = Number(input[1])*100;
  var c = "" + A*B;
  console.log(Math.floor(c.slice(0,c.length-2)));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
	input = input.split(" ");
	var a = parseInt(input[0], 10);
	var b = Math.floor(input[1]*100)/100;
　  var total = Math.floor(a*b)
	console.log(total);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(x => x*1);
  let ans = Math.floor(inp[0]*inp[1]);
  console.log(ans);
}

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


"use strict";

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

    const a = parseInt(input[0].split(" ")[0]);
    const b = parseInt(input[0].split(" ")[1]);
    console.log(Math.trunc(a*b))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const i = require("fs").readFileSync("/dev/stdin", "UTF-8");

let [a, b] = i.split(' ');

console.log(Math.floor(+a * +b));


function main(input) {
  let [a, b] = input[0].trim().split(" ").map(i => i);
  a = BigInt(parseInt(a));
  b = BigInt(parseInt(b*100));
  let ans = a * b;
  ans = ans+"";

  if(ans.length<=2){
    console.log(0);
  }else{
    const ans1 = ans.slice(0,ans.length-2);
    console.log(ans1);
  }

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


function Main(input){
    const arr = input.split(' ').map(Number);
    console.log(Math.floor(arr[0]*arr[1]));
}
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 ab = lines[0].split(' ');
 var a = Number(ab[0]);
 var b = Number(ab[1]);

 console.log(Math.floor(a * b));
});


const main = (input) => {
  input = input.trim().split('\n')

  let [, k] = input[0].split(' ').map(BigInt)
  const cities = input[1].split(' ').map(v => parseInt(v, 10) - 1)

  let loop_size = null
  let before_loop = null

  for (let his=[0], i=0; true;) {
    const head = his.indexOf(cities[i])
    if (head !== -1) {
      before_loop = head
      loop_size = his.length
      break
    }

    his.push(cities[i])
    i = cities[i]
  }

  let start = 0
  let move = k

  if (loop_size < k) {
    start = before_loop
    k -= BigInt(before_loop)
    move = k % BigInt(loop_size)
  }

  let ans = start
  for (let c=0n; c<move; c++) {
    ans = cities[ans]
  }

  return console.log(ans + 1)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Score: 400 points

Problem Statement

The Kingdom of Takahashi has N towns, numbered 1 through N.

There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Help the king by writing a program that answers this question.

Constraints

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

1 \leq A_i \leq N

1 \leq K \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Sample Input 1

4 5
3 2 4 1

Sample Output 1

4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.

Sample Input 2

6 727202214173249351
6 5 2 5 3 2

Sample Output 2

2


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

function main() {
    const [N] = load(1)
    let [K] = load(1,1,BigInt)
    const A = load(N)
    const visiteds = {}

    let city = 1
    while(K > 0) {
        if(city in visiteds) {
            const ommitable_times = visiteds[city] - K
            K = K % BigInt(ommitable_times)
            if(K === 0n) break
        } else {
            visiteds[city] = K
        }

        city = A[city - 1]
        K--
    }

    return city
}

/*

入力値を読み込む
load(rows = 1, cols = 1, type = Number)

TruthyならYes, FalsyならNo
yesno(boolean) => String

数列の和
array_sum(numbers) => Number

対無限ループ安全装置
inifinite_loop_preventer(max = 1e5)

配列の中から最大値を返す
array_max(numbers, initial_value = null) => Number

配列の中から最小値を返す
array_min(numbers, initial_value = null) => Number

オブジェクトのスナップショットをconsole.logする
log_obj(value)

nを素因数分解
math_prime_factors(n) => { 素数: n乗 }

2次元配列を作る
new_array_2d(x_len, y_len = 0, init_value = 0) => [[]]

最大公約数
gcd(a, b) => Number

最小公倍数
lcm(a,b) => Number

subsetはsetの部分集合である
check_if_superset(set, subset) => Boolean

和集合
set_union(a, b) => Set

積集合
set_intersection(a, b) => Set

対称差集合
set_symmetric_difference(a, b) => Set

差集合
set_difference(a, b) => Set

配列からc個取る組み合わせ全列挙
set_combinations(array, count) => [[]]

*/

// console.time()
let inputs = input.split(/[\s\n]/)
let inifinite_loop_prevent_counter = 0
let result = main()
if(result === undefined) {
    console.warn("result is undefined")
} else {
    console.log(result)
}
// console.timeEnd()

// 入力値を読み込む
function load(rows = 1, cols = 1, type = Number) {
    const length = rows * cols
    let result = inputs.splice(0, length)

    if(type !== String) result = result.map(type)
    if(cols > 1) {
        const arrays = new Array(cols)
        for(let col = 0; col < cols; col++) {
            arrays[col] = new Array()
            for(let row = 0; row < rows; row++) {
                arrays[col].push(result[row * cols + col])
            }
        }
        result = arrays
    }

    return result
}

// TruthyならYes, FalsyならNo
function yesno(value) {
    return value ? 'Yes' : 'No'
}

// 数列の和
function array_sum(numbers) {
    return numbers.reduce((acc, cur) => acc + cur, 0)
}

// 対無限ループ安全装置
function inifinite_loop_preventer(max = 1e5) {
    inifinite_loop_prevent_counter++
    if(inifinite_loop_prevent_counter >= max) {
        throw new Error("Infinite loop")
    }
}

// 配列の中から最大値を返す
function array_max(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n > result) result = n
    return result
}

// 配列の中から最小値を返す
function array_min(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n < result) result = n
    return result
}

// オブジェクトのスナップショットをconsole.logする
function log_obj(value) {
    console.log(JSON.parse(JSON.stringify(value)))
}

// 素因数分解 { 素数: n乗 }
function math_prime_factors(n) {
    const result = {}

    for(let i = 2; i * i <= n; i++) {
        if(n % i === 0) {
            n /= i
            result[i] = 1

            while(n % i === 0) {
                n /= i
                result[i]++
            }
        }
    }

    if(n > 1) result[n] = 1

    return result
}

// 2次元配列を作る
function new_array_2d(x_len, y_len = 0, init_value = 0) {

    const array = new Array()
    for(let i = 0; i < x_len; i++) {
        const y = y_len ? new Array(y_len).fill(init_value) : new Array()
        array.push(y)
    }

    return array
}

// 最大公約数
function gcd(a, b) {
    if(b === 0) return a
    return gcd(b, a % b)
}

// 最小公倍数
function lcm(a,b) {
    const g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}

// subsetはsetの部分集合である
function check_if_superset(set, subset) {
    for(let el of subset) {
        if(!set.has(el)) {
            return false
        }
    }
    return true
}

// 和集合
function set_union(a, b) {
    const result = new Set(a)
    for(const el of b) result.add(el)
    return result
}

// 積集合
function set_intersection(a, b) {
    let result = new Set()
    for(let el of b) {
        if(a.has(el)) {
            result.add(el)
        }
    }
    return result
}

// 対称差集合
function set_symmetric_difference(a, b) {
    let result = new Set(a)
    for(let el of b) {
        if(result.has(el)) {
            result.delete(el)
        } else {
            result.add(el)
        }
    }
    return result
}

// 差集合
function set_difference(a, b) {
    let result = new Set(a)
    for(let el of b) result.delete(el)
    return result
}

// 配列からc個取る組み合わせ全列挙
function set_combinations(array, count) {

    const result = []

    function _combi({ pre = [], rest }) {

        if(pre.length + rest.length < count) return

        if(pre.length < count) {
            for(let i = 0; i < rest.length; i++) {
                _combi({
                    pre: [...pre, rest[i]],
                    rest: rest.slice(0,i)
                })
            }
        } else {
            result.push(pre)
        }
    }

    _combi({ rest: array })

    return result
}

function math_permutation(n, r) {
    let res = 1
    for(let i = 0; i < r; i++) {
        res *= n - i
    }
    return res
}

function math_combination(n, r) {
    return math_permutation(n, r) / math_permutation(r, r)
}


function Main(input) {
  input = input.trim().split("\n").map(function(x) { return x.split(" ")});
  var N = parseInt(input[0][0], 10);
  var K = input[0][1];
  var K1, K2;
  if (K.length > 9){
    K1 = parseInt(K.substr(0, K.length - 9), 10);
    K2 = parseInt(K.substr(-9), 10);

  } else {
    K1 = 0
    K2 = parseInt(K, 10);
  }
  var vec_A = input[1].map(e => (parseInt(e, 10)));
  var mapRecord = Array.from({length: N}, () => 0);
  var tmpTown = 1;
  var loopStart, loopEnd ,loopStartTown, ans;
  for (var i = 0; i <= N; i++){
    mapRecord[tmpTown - 1] ++;
    if (mapRecord[tmpTown - 1] > 1){
      loopEnd = i;
      loopStartTown = tmpTown;
      break;
    }
    tmpTown = vec_A[tmpTown - 1];
  }
  tmpTown = 1;
  for (var i = 0; i <= N; i++){
    if (tmpTown === loopStartTown){
      loopStart = i;
      break;
    }
    tmpTown = vec_A[tmpTown - 1];
  }
  if (K2 > loopStart || K1 > 0){
    K2 = (K2 - loopStart) % (loopEnd - loopStart) + (K1 % (loopEnd - loopStart)) * (1e+9 % (loopEnd - loopStart));
	K2 %= (loopEnd - loopStart);
    tmpTown = loopStartTown;
  } else {
    tmpTown = 1;
  }
  for (var i = 0; i <= N; i++){
    if (i === K2){
      ans = tmpTown;
      break;
    }
    tmpTown = vec_A[tmpTown - 1];
  }
  console.log(ans);


"use strict";

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

    const n = BigInt(input[0].split(" ")[0]);
    const k = BigInt(input[0].split(" ")[1]);
    const as = input[1].split(" ").map(n => Number(n));
    as.unshift(0)
    let tmp
    if(n<k){
        let visited = [1]
        let i = 1
        while(!visited.includes(as[i])){
            visited.push(as[i])
            i = as[i]
        }
        let start = visited.indexOf(as[i])
        const len = BigInt(visited.slice(start).length)
        const firstLen = start-1
        tmp = (k-BigInt(start)+1n) % len
        const idx = firstLen + Number(tmp)
        console.log(visited[idx])
    } else {
        tmp = k
        let curr = 1
        while(tmp>0){
            curr = as[curr]
            tmp--
        }
        console.log(curr)
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//1,6,2,5,3,2,5,


"use strict";

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

    const n = BigInt(input[0].split(" ")[0]);
    const k = BigInt(input[0].split(" ")[1]);
    const as = input[1].split(" ").map(n => BigInt(n));
    let tmp
    if(n<k){
        let visited = [1]
        let i = 1
        let cnt = 1
        while(!visited.includes(as[i-1])){
            visited.push(as[i-1])
            i = as[i-1]
            cnt++
        }
        tmp = k % visited.length
    } else {
        tmp = k
    }

    let curr = 1
    while(tmp>0){
        curr = as[curr]
        tmp--
    }
    console.log(curr)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
// 1,2,3,4,5,1,2,3,4


function main(input) {
  const inputs = input.split('\n')
  // console.log(inputs)
  const [N, K] = inputs[0].split(' ').map(BigInt)
  const Ai = inputs[1].split(' ').map(Number)

  // 雑

  // let current = 0
  // const max = 10
  // const path = [1]
  // for(let i = 0; i < K; i++) {
  //   if (max === i) break
  //   current = Ai[current] - 1
  //   path.push(current + 1)
  //   console.log(current)
  // }
  // console.log(path)
  //

  // ループを見つける
  // let loop = [0]
  // let current = 0
  // let count = 0
  // for(let i = 0; i < K; i++) {
  //   console.log(count ++)
  //   current = Ai[current] - 1
  //   if (current === 0) {
  //     console.log('loop found')
  //     break
  //   }
  //   loop.push(current)
  // }
  // console.log(loop)
  // console.log(loop[K % loop.length] + 1)

  // 途中からのループを見つけられない

  let loop = [0]
  let current = 0
  let a = 0
  let visited = []
  for(let i = 0; i < K; i++) {
    current = Ai[current] - 1
    if (visited[current]) {
      // console.log('loop found', current)
      a = loop.indexOf(current)
      loop = loop.slice(loop.indexOf(current))
      break
    }
    visited[current] = true
    loop.push(current)
    // console.log(loop)
  }
  // console.log(a, loop)
  console.log(loop[(K - BigInt(a)) % BigInt(loop.length)] + 1)

}

// main(
//   `6 10
// 6 5 2 5 3 2`
// )
// main(
//   `4 5
// 3 2 4 1`
// )

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


function Main(input) {
  input = input.trim().split("\n");
  const NK = input[0].split(" ");
  var N = parseInt(NK[0], 10);
  var K = parseInt(NK[1], 10);
  var Aarr = input[1].split(" ").map((n) => parseInt(n, 10));
  var now = 1;
  var d = 0;
  if (N > K) {
    for (var i = 0; i < K; i++) {
      now = Aarr[now - 1];
    }
    console.log(now);
    return;
  }

  t = new Array(N).fill(-1);
  t[0] = 0;
  for (var i = 1; i <= N; i++) {
    now = Aarr[now - 1];
    if (t[now - 1] != -1) {
      d = i - t[now - 1]; //ループ幅
      var sa = i - d + 1; //あまりの部分
      K -= sa;
      if ((K %= d) == 0) {
        K = d;
        K += d;
      } else {
        K %= d;
      }
      K += sa;
      break;
    }
    t[now - 1] = i;
  }
  now = 1;
  for (var i = 0; i < K; i++) {
    now = Aarr[now - 1];
  }
  console.log(now);
}

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,
    terminal: false
});
reader.on('line', (line) => {
    lines.push(line);
});
reader.on('close', () => {
    const [n, k] = lines[0].split(" ").map(e => parseInt(e));
    let K = BigInt(k);
    const a = lines[1].split(" ").map(e => parseInt(e));
    let s = [];
    let ord = new Array(n + 1).fill(-1);

    let v = 1;
    while (ord[v] === -1) {
        ord[v] = s.length;
        s.push(v);
        v = a[v - 1];
    }
    let l = ord[v];
    let c = s.length - l;
    if (K < l) {
        console.log(s[k]);
    } else {
        K -= BigInt(l);
        const mod = parseInt(K % BigInt(c));
        console.log(s[l+mod]);
    }
});


function main(input) {
  const lines = input.trim().split("\n");
  let [n, k] = lines[0].split(' ');
  n = +n;
  k = BigInt(k);
  const towns = lines[1].split(' ').map(Number);

  const visited = new Map();
  let pos = 1, i;
  while (i = visited.get(pos), i === undefined && k) {
    visited.set(pos, visited.size);
    pos = towns[pos - 1];
    k--;
  }
  if (k > 0) {
    const cycle = BigInt(visited.size - i);
    const rest = Number( (k % cycle).toString() );
    for (let [key, value] of visited) {
      if (value == i + rest) {
        pos = key;
        break;
      }
    }
  }

  console.log(pos);
}

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


function main(input) {
  const lines = input.trim().split("\n");
  let [n, k] = lines[0].split(' ');
  n = +n;
  k = BigInt(k);
  const towns = lines[1].split(' ').map(Number);

  const visited = new Map();
  let pos = 1;
  while (k > 0) {
    const i = visited.get(pos);
    if (!i) {
      visited.set(pos, visited.size);
      pos = towns[pos - 1];
      k--;
    } else {
      const cycle = BigInt(visited.size - i);
      const rest = Number( (k % cycle).toString() );
      for (let [key, value] of visited) {
        if (value == i + rest) {
          pos = key;
          break;
        }
      }
      k = 0;
    }
  }

  console.log(pos);
}

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


function main(input) {
  let [n, k] = input[0].trim().split(" ").map(i => BigInt(i));
  let a = input[1].trim().split(" ").map(i => parseInt(i-1));

  let flag = [];
  let sum=0;
  let now=0;
  /* ループの検出 */
  while(true){
    if(flag[a[now]]===undefined){
      flag[a[now]]=sum;
      sum++;
      now=a[now];
    }else{
      break;
    }
  }
  /* ループまでの長さ */
  let firstToLoop = BigInt(flag[a[now]]);
  /* ループの長さ */
  let loop = BigInt(sum-flag[a[now]]);

  /* ループ分をmodしてkを小さくする */
  if((k > firstToLoop)){
    k = (k-firstToLoop)%loop+firstToLoop;
  }

  /* 小さくしたkで再度探索 */
  now=0;
  for(let i=0;i<k;i++){
    now=a[now];
  }

  console.log(now+1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


function main(input) {
  let [n, k] = input[0].trim().split(" ").map(i => BigInt(i));
  let a = input[1].trim().split(" ").map(i => parseInt(i));

  let flag = [];
  for(let i=0;i<n;i++){
    flag[i]=-1;
    a[i]--;
  }

  let sum=0;
  let now=0;
  let judge =false;
  while(true){
    if(flag[a[now]]===-1){
      flag[a[now]]=sum;
      sum++;
      now=a[now];
    }else{
      judge = true;
      break;
    }
  }
  let firstToLoop = BigInt(flag[a[now]]);
  let loop = BigInt(sum-flag[a[now]]);
  let ans = 0n;
  if(((k-firstToLoop)<0) || (!judge)){
    ans = k;
  }else{
    ans = (k-firstToLoop)%loop+firstToLoop;
  }
  now=0;
  for(let i=0;i<ans;i++){
    now=a[now];
  }
  console.log((now+1)+"");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


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

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

A = input[1].split(' ').map(i => parseInt(i))

// console.log(N, K, A)

before = []
after = []
pos = 0

for (i = 0; i <= K; i++) {
    // console.log(before, after, pos)
    if (after.length < 1) {
        if (!before.includes(A[pos])) {
            before.push(A[pos])
        } else {
            after.push(A[pos])
        }
    } else {
        before2 = new Array(...before)
        before3 = new Array(...before)
        // console.log('hoge', after, before2.splice(-after.length))
        if (JSON.stringify(after) == JSON.stringify(before3.splice(-after.length))) {
            console.log(A[i - after.length * 2 + K % after.length - 1])
            return
        } else {
            after.push(A[pos])
        }
        // console.log(K, i, K == i)
        if (K == i) {
            console.log(A[pos - 1])
            return
        }
    }
    pos = A[pos] - 1
}


"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 K = BigInt(cin[0]);
    let A = cin.map(i => +i);
    let visit = [];
    let p = 1;
    let offset = 0;
    let interval = 0;
    let map = Array(N);
    for (let i = 0; i < N; i++) {
        visit.push(p);
        map[p] = 1;
        let next = A[p];
        if (map[next]) {
            offset = visit.indexOf(next);
            interval = visit.length - offset;
            break;
        }
        p = next;
    }
    //  console.log(visit)
    // console.log({interval,offset})
    let ans;
    if (K <= offset) {
        ans = visit[K];
    } else {
        let O = BigInt(offset);
        let I = BigInt(interval);
        ans = visit[O + (K - O) % I];
    }
    console.log(ans);
}
main();


"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 K = BigInt(cin[0]);
    let A = cin.map(i=>+i);
    let visit = [];
    let p = 1;
    let offset = BigInt(0);
    let interval = BigInt(0);
    for (let i = 0; i < N; i++) {
        visit.push(p);
        let next = A[p];
        let temp = visit.indexOf(next);
        if (temp >= 0) {
            offset = BigInt(temp);
            interval = BigInt(visit.length - temp);
            break;
        }
        p = next;
    }
    //  console.log(visit)
  	// console.log({interval,offset})
    let ans;
    if (K <= offset) {
        ans = visit[K];
    } else {
        ans = visit[offset + (K - offset) % interval];
    }
    console.log(ans);
}
main();


function Main(input) {
	var str = input;
	var ans = 0;
	var parr =[];
	var arr = [];
	var c = 0;
	var j = 1;
	str = str.split("\n");
	var k = Number(str[0].split(" ")[1]);
	var p = str[1].split(" ");
　for (var i = 0; i < p.length; i++){
		parr[i] = Number(p[i]);
	}
	arr[0]= parr[0];
	loop: while(1){
		arr.push(parr[parr[c] -1]);
		for(var l= 0; l < (j -1) ; l++){
			if(arr[l] === arr[j]){
			break loop;
			}
		}
	c = parr[c] -1;
	j++;
	}
	arr.pop();
		console.log(arr);
	ans = arr[k%(j-1)];
	 console.log(ans);
}
 //*おまじない
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";

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

    const A = arg[1].split(" ").map(n=>parseInt(n-1));

    let array = [0];
    let loopStart;

    let usedIndex = [];

    let next = 0;

    while(true) {
        if(usedIndex.indexOf(A[next]) !== -1) {
            loopStart = A[next];
            array.push(A[next]);
            break;
        }

        usedIndex.push(next);
        array.push(A[next]);
        // console.log("A[next]:" + A[next]);

        next = A[next];
        // console.log("next:" + next);
    }

    // console.log(loopStart)

    const loop = array.slice(loopStart+1);
    array.shift();

    // console.log(loop);
    // console.log(array);

    if(K <= array.length) {
        console.log(array[K-1]+1);
    } else {
        //console.log((K-array.length) % loop.length);
        let temp = (K-array.length) % loop.length;
        // console.log(temp)

        if(temp === 0) {
            console.log(loop[loop.length-1] + 1);
        } else {
            console.log(loop[temp - 1] + 1);
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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;
	}

}

function Main(sc) {

	var N = sc.nextInt();
	var K = sc.nextInt();
	var TBL = {};

	for (var i = 0; i < N; i++) {
		TBL[i + 1] = sc.nextInt();
	}

	var ans = 1;
	var dupli = {};
	for (var i = 0; i < K; i++) {
		ans = TBL[ans];
		if (dupli[ans]) break;
		dupli[ans] = i + 1;
	}

	var waru = i + 1 - dupli[ans];
	K = (K < waru) ? K : K % waru;

	var ans = 1;
	for (var i = 0; i < K; i++) {
		ans = TBL[ans];
	}

	console.log(ans);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("10 1 2 5 3 4 6 7 3 2 4 1 2 2 3 3 4 4 5 3 6 6 7 1 8 8 9 9 10"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得
// for (var i = 0; i < 1000000000; i++) var toDelay = "aaa"; // 1000msくらいの遅延
// console.log(wrtnNos); return;


function main(input) {
  let [n, k] = input[0].trim().split(" ").map(i => BigInt(i));
  let a = input[1].trim().split(" ").map(i => parseInt(i));

  let flag = [];
  for(let i=0;i<n;i++){
    flag[i]=-1;
    a[i]--;
  }

  let sum=0;
  let now=0;
  while(true){
    if(flag[a[now]]===-1){
      //console.log(now+1);
      flag[a[now]]=sum;
      sum++;
      now=a[now];
    }else{
      break;
    }
  }
  let firstToLoop = BigInt(flag[a[now]]);
  //console.log("firsttoloop:"+firstToLoop);
  let loop = BigInt(sum-flag[a[now]]);
  //console.log("loop:"+loop);
  let ans = 0n;
  if((k-firstToLoop)<=0){
    ans = k;
  }else{
    ans = (k-firstToLoop)%loop+firstToLoop;
  }

  now=0;
  for(let i=0;i<ans;i++){
    now=a[now];
  }
  console.log(now+1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


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;
	}

}

function Main(sc) {

	var N = sc.nextInt();
	var K = sc.nextInt();
	var TBL = {};

	for (var i = 0; i < N; i++) {
		TBL[i + 1] = sc.nextInt();
	}

	var ans = 1;
	for (var i = 0; i < K; i++) {
		ans = TBL[ans];
		if (ans == 1) break;
	}
	var waru = i + 1;
	K = K % waru;

	var ans = 1;
	for (var i = 0; i < K; i++) {
		ans = TBL[ans];
	}

	console.log(ans);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("10 1 2 5 3 4 6 7 3 2 4 1 2 2 3 3 4 4 5 3 6 6 7 1 8 8 9 9 10"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得
// for (var i = 0; i < 1000000000; i++) var toDelay = "aaa"; // 1000msくらいの遅延
// console.log(wrtnNos); return;


"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+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(myOut);

function main(){
  var n = next();
  var k = BigInt(next());
  var a = nexts(n);
  var map = xArray(-1,n);
  var x = 0;
  map[0] = 0;
  for(var i = 1; i <= k; i++){
    x = a[x]-1;
    if(map[x] >= 0){
      var r = i - map[x];
      k -= BigInt(i);
      k %= BigInt(r);
      for(var i = 1; i <= k; i++)x = a[x]-1;
    }
    map[x] = i;
  }
  return x+1;
}


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

function main() {
    let [A,B,C,D] = load(4)

    while(true) {
        C -= B
        if(C <= 0) return 'Yes'
        A -= D
        if(A <= 0) return 'No'
    }
}

/*

入力値を読み込む
load(rows = 1, cols = 1, type = Number)

TruthyならYes, FalsyならNo
yesno(boolean) => String

数列の和
array_sum(numbers) => Number

対無限ループ安全装置
inifinite_loop_preventer(max = 1e5)

配列の中から最大値を返す
array_max(numbers, initial_value = null) => Number

配列の中から最小値を返す
array_min(numbers, initial_value = null) => Number

オブジェクトのスナップショットをconsole.logする
log_obj(value)

nを素因数分解
math_prime_factors(n) => { 素数: n乗 }

2次元配列を作る
new_array_2d(x_len, y_len = 0, init_value = 0) => [[]]

最大公約数
gcd(a, b) => Number

最小公倍数
lcm(a,b) => Number

subsetはsetの部分集合である
check_if_superset(set, subset) => Boolean

和集合
set_union(a, b) => Set

積集合
set_intersection(a, b) => Set

対称差集合
set_symmetric_difference(a, b) => Set

差集合
set_difference(a, b) => Set

配列からc個取る組み合わせ全列挙
set_combinations(array, count) => [[]]

文字列版splice（not in place）
string_splice(str, index, delete_count, add_str = '')

*/

let inputs = input.split(/[\s\n]/)
let inifinite_loop_prevent_counter = 0
let result = main()
console.log(result)

if(result === undefined) {
    console.warn("result is undefined")
}
// console.timeEnd()

// 入力値を読み込む
function load(rows = 1, cols = 1, type = Number) {
    const length = rows * cols
    let result = inputs.splice(0, length)

    if(type !== String) result = result.map(type)
    if(cols > 1) {
        const arrays = new Array(cols)
        for(let col = 0; col < cols; col++) {
            arrays[col] = new Array()
            for(let row = 0; row < rows; row++) {
                arrays[col].push(result[row * cols + col])
            }
        }
        result = arrays
    }

    return result
}

// TruthyならYes, FalsyならNo
function yesno(value) {
    return value ? 'Yes' : 'No'
}

// 数列の和
function array_sum(numbers) {
    return numbers.reduce((acc, cur) => acc + cur, 0)
}

// 対無限ループ安全装置
function inifinite_loop_preventer(max = 1e5) {
    inifinite_loop_prevent_counter++
    if(inifinite_loop_prevent_counter >= max) {
        throw new Error("Infinite loop")
    }
}

// 配列の中から最大値を返す
function array_max(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n > result) result = n
    return result
}

// 配列の中から最小値を返す
function array_min(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n < result) result = n
    return result
}

// オブジェクトのスナップショットをconsole.logする
function log_obj(value) {
    console.log(JSON.parse(JSON.stringify(value)))
}

// 素因数分解 { 素数: n乗 }
function math_prime_factors(n) {
    const result = {}

    for(let i = 2; i * i <= n; i++) {
        if(n % i === 0) {
            n /= i
            result[i] = 1

            while(n % i === 0) {
                n /= i
                result[i]++
            }
        }
    }

    if(n > 1) result[n] = 1

    return result
}

// 2次元配列を作る
function new_array_2d(x_len, y_len = 0, init_value = 0) {

    const array = new Array()
    for(let i = 0; i < x_len; i++) {
        const y = y_len ? new Array(y_len).fill(init_value) : new Array()
        array.push(y)
    }

    return array
}

// 最大公約数
function gcd(a, b) {
    if(b === 0) return a
    return gcd(b, a % b)
}

// 最小公倍数
function lcm(a,b) {
    const g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}

// subsetはsetの部分集合である
function check_if_superset(set, subset) {
    for(let el of subset) {
        if(!set.has(el)) {
            return false
        }
    }
    return true
}

// 和集合
function set_union(a, b) {
    const result = new Set(a)
    for(const el of b) result.add(el)
    return result
}

// 積集合
function set_intersection(a, b) {
    let result = new Set()
    for(let el of b) {
        if(a.has(el)) {
            result.add(el)
        }
    }
    return result
}

// 対称差集合
function set_symmetric_difference(a, b) {
    let result = new Set(a)
    for(let el of b) {
        if(result.has(el)) {
            result.delete(el)
        } else {
            result.add(el)
        }
    }
    return result
}

// 差集合
function set_difference(a, b) {
    let result = new Set(a)
    for(let el of b) result.delete(el)
    return result
}

// 配列からc個取る組み合わせ全列挙
function set_combinations(array, count) {

    const result = []

    function _combi({ pre = [], rest }) {

        if(pre.length + rest.length < count) return

        if(pre.length < count) {
            for(let i = 0; i < rest.length; i++) {
                _combi({
                    pre: [...pre, rest[i]],
                    rest: rest.slice(0,i)
                })
            }
        } else {
            result.push(pre)
        }
    }

    _combi({ rest: array })

    return result
}

function math_permutation(n, r) {
    let res = 1
    for(let i = 0; i < r; i++) {
        res *= n - i
    }
    return res
}

function math_combination(n, r) {
    return math_permutation(n, r) / math_permutation(r, r)
}

// 文字列版splice（not in place）
function string_splice(str, index, delete_count, add_str = '') {
    if(index < 0) {
        index = str.length + index
        if(index < 0) index = 0
    }
    return str.slice(0, index) + add_str + str.slice(index + delete_count)
}

Score : 200 points

Problem Statement

Takahashi and Aoki will have a battle using their monsters.

The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.

The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ...
Here, an attack decreases the opponent's health by the value equal to the attacker's strength.
The monsters keep attacking until the health of one monster becomes 0 or below. The person with the monster whose health becomes 0 or below loses, and the other person wins.

If Takahashi will win, print Yes; if he will lose, print No.

Constraints

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

If Takahashi will win, print Yes; if he will lose, print No.

Sample Input 1

10 9 10 10

Sample Output 1

No

First, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.

Next, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.

Takahashi's monster is the first to have 0 or less health, so Takahashi loses.

Sample Input 2

46 4 40 5

Sample Output 2

Yes


function Main(input) {
	var str = input;
	str = str.split("\n")[0];
    str = str.split(' ');
    var thp = Number(str[0]);
    var tpw = Number(str[1]);
    var ahp = Number(str[2]);
    var apw = Number(str[3]);
    while(thp > 0 && ahp > 0 ){
   		ahp = ahp - tpw;
   		if(ahp <=0){
   			console.log("Yes");
   			break;
   		}
   		thp = thp - apw;
   		if(thp <=0){
   			console.log("No");
   			break;
   		}
    }
}
 //*おまじない
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  input = input.split(' ');
  const takahashi = {
    strength: parseInt(input[0]),
    attack: parseInt(input[1])
  };
  const aoki = {
    strength: parseInt(input[2]),
    attack: parseInt(input[3])
  };

  while(takahashi.strength > 0 && aoki.strength > 0) {
    aoki.strength -= takahashi.attack;
    if (aoki.strength <= 0) {
      console.log('%s', 'Yes');
      break;
    }
    takahashi.strength -= aoki.attack;
    if (takahashi.strength <= 0) console.log('%s', 'No');
  }
}

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


const Main = (input) => {
  input = input.trim().split('\n')
  const tmp = input[0].split(' ')

  let result = ''
  while (true) {
    tmp[2] = tmp[2] - tmp[1]
    if (tmp[2] <= 0) {
      result = 'yes'
      break
    }

    tmp[0] = tmp[0] - tmp[3]
    if (tmp[0] <= 0) {
      result = 'no'
      break
    }
  }

  console.log(result)
  return result
}

Main()


const Main = (input) => {
  const tmp = input.split(' ')
  const takahashi = { hp: tmp[0], atk: tmp[1] }
  const aoki = { hp: tmp[2], atk: tmp[3] }

  let i = 0
  let result = ''
  let winner = ''

  const player = { takahashi: takahashi, aoki: aoki }
  const players = ['takahashi', 'aoki']
  while (true) {
    const attacker = players[i % 2]
    const defender = players[(i + 1) % 2]
    player[defender].hp = player[defender].hp - player[attacker].atk
    if (player[defender].hp <= 0) {
      winner = attacker
      break
    }
    i += 1
  }

  if (winner === 'takahashi') {
    result = 'yes'
  } else {
    result = 'no'
  }

  console.log(result)
}

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


function Main (input) {
  var t_life = parseInt(input.split(" ")[0]);
  var t_atk = parseInt(input.split(" ")[1]);
  var a_life = parseInt(input.split(" ")[2]);
  var a_atk = parseInt(input.split(" ")[3]);

  for (var counter = 0; counter < 100; counter++) {
    if (counter % 2 === 0) {
        // 高橋君の番
        a_life = a_life - t_atk
        if (a_life <= 0) {
        console.log("Yes")
        }
    } else {
        // 青木君の番
        t_life = t_life - a_atk
        if (t_life <= 0) {
        console.log("Yes")
        }
    }
  }
}

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


function Main(input) {
	input = input.split(" ");
	var tHP = parseInt(input[0], 10);
	var tAT = parseInt(input[1], 10);
	var aHP = parseInt(input[2], 10);
	var aAT = parseInt(input[3], 10);

var a =  Math.ceil(aHP  /  tAT )

var t =  Math.ceil(tHP  /  aAT )

if (t >= a){
	console.log('Yes');
}else{
	console.log('No');

}

}

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


'use strict'

function main(input) {
    let a = Number(input.split('\n')[0].split(' ')[0]);
    let b = Number(input.split('\n')[0].split(' ')[1]);
    let c = Number(input.split('\n')[0].split(' ')[2]);
    let d = Number(input.split('\n')[0].split(' ')[3]);
    let count1 = 0;
    let count2 = 0;
    while(1) {
        if ((c - b) > 0) {
            count1++;
            c = c - b;
        } else {
            break;
        }
    }
    while(1) {
        if ((a - d) > 0) {
            count2++;
            a = a - d;
        } else {
            break;
        }
    }
    if (count1 <= count2) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}

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(a){return a?cin[cid++]:+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(myOut);

function main(){
  var [a,b,c,d] = nexts(4);
  while(a > 0 && c > 0){
    c -= b;
    a -= d;
  }
  return c <= 0 ? "Yes" : "No";
}


const Main = input => {
  const sp = input.split(' ').map(e => Number(e));

  const a = Math.floor( sp[2] / sp[1] );
  const b = Math.floor( sp[0] / sp[3] );
  const beta = sp[0] % sp[3];

  console.log(( a < b || ( a === b && beta === 0 ) ) ? 'No' : 'Yes' );
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//Main(`10 9 10 10`);
//Main(`46 4 40 5`)


'use strict';
const main = arg => {
  const input = arg.trim().split(' ');
  const A = parseInt(input[0], 10);
  const B = parseInt(input[1], 10); // 攻撃力
  const C = parseInt(input[2], 10);
  const D = parseInt(input[3], 10); // 攻撃力
  // 高橋の攻撃回数
  const timesTakahashi = Math.ceil(C / B);
  // 青木の攻撃回数
  const timesAoki = Math.ceil(A / D);

  // 青木が下回ったら青木のかち、同じなら高橋が先行でかち
  if (timesTakahashi > timesAoki ) {
    console.log('No');
  } else {
    console.log('Yes');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
    let takahashiHP = Number(tmp[0])
    let takahashiAtk = Number(tmp[1])
    let aokiHP = Number(tmp[2])
    let aokiAtk = Number(tmp[3])
    aokiHP -= takahashiAtk
  	if(aokiHP <= 0) return console.log('Yes')
  	let i = 1
    while(takahashiHP > 0 || aokiHP > 0) {
      if(i % 2 === 0) aokiHP -= takahashiAtk
      else takahashiAtk -= aokiHP

      if(takahashiHP <= 0) {
        return console.log('No')
      } else if(aokiHP <= 0) {
        return console.log('Yes')
      }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    let A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    let C = parseInt(arg[0].split(" ")[2]);
    const D = parseInt(arg[0].split(" ")[3]);

    let i = 0;

    while(A > 0 && C > 0) {
        if(i % 2 === 0) {
            C -= B;
        } else {
            A -= D;
        }
        i++;
    }

    if(A > C) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

;(S => {
    const mod = 2019
    const map = Array(2019).fill(0)
    map[0] = 1
    let c = 0
    let p = 1
    let m = 0

    for (let i = S.length - 1; i >= 0; i--) {
        m = (m + S[i] * p) % mod
        c += map[m]
        map[m]++
        p = p * 10 % 2019
    }

    console.log(2)

})(input)

Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.


"use strict";

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

;(S => {
    const mod = 2019
    const map = Array(2019).fill(0)
    map[0] = 1
    let c = 0
    let p = 1
    let m = 0

    for (let i = S.length - 1; i >= 0; i--) {
        m = (m + S[i] * p) % mod
        c += map[m]
        map[m]++
        p = p * 10 % 2019
    }

    console.log(c)

})(input)


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

;(S => {
    const mod = 2019
    const map = Array(2019).fill(0)
    map[0] = 1
    let c = 0
    let p = 1
    let m = 0

    for (let i = S.length - 1; i >= 0; i--) {
        m = (m + S[i] * p) % mod
        c += map[m]
        map[m]++
        p = p * 10 % 2019
    }

    console.log(c)

})(input)


function main(lines) {
  const input = lines
  let count = 0

  for(let i=0; i<input.length-1; i++){
    for(let j=i+1; j<=input.length; j++){
      if(input.slice(i,j)%2019 === 0){
        count++
      }
    }
  }
  console.log(count)

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


function main(lines) {
  const input = lines
  let count = 0

  for(let i=0; i<input.length-3; i++){
    for(let j=i+3; j<=input.length; j++){
      if(input.slice(i,j)%2019 === 0){
        count++
      }
    }
  }
  console.log(count)

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


function main(lines) {
  const input = lines
  let count = 0

  for(let i=0; i<input.length; i++){
    for(let j=i+1; j<=input.length; j++){
      if(input.slice(i,j)%2019 === 0){
        count += 1
      }
    }
  }
  console.log(count)

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


function main(lines) {
  const input = lines
  let count = 0

  for(let i=0; i<input.length; i++){
    for(let j=i; j<=input.length; j++){
      if(input.slice(i,j)%2019 === 0 && i != j){
        count += 1
      }
    }
  }
  console.log(count)

}
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,
    terminal: false
});
reader.on('line', (line) => {
    lines.push(line);
});
reader.on('close', () => {
    const s = parseInt(lines[0]);
    const str = lines[0]; //.split("");
    let ans = 0;
    const s1 = Math.floor(s / 2019);
    console.log(`s1=${s1}`);
    for (let i = 1; i <= 10000; i++) {
        //console.log(`${i} str:${(2019 * i).toString()}`);
        for(let j = 0; j < str.length; j++){
            if (str.startsWith( (2019 * i).toString(), j)){
                ans++;
            }
        }
        // const re = new RegExp("(" + (2019 * i).toString() + ")", "g");
        // const group = str.match(re);
        // console.log(group);
        // if (group !== null) {
        //     ans += group.length;
        // }
    }

    // for(let i = 0; i <= str.length - 1; i++){
    //     for(let j = i + 4; j <= str.length; j++){
    //         const num = parseInt(str.slice(i, j).join(""));
    //         if (num % 2019 === 0){
    //             ans++;
    //             console.log(`${i} ${j} num:${num} *`);
    //         }else{
    //             console.log(`${i} ${j} num:${num}`);
    //         }
    //     }
    // }
    console.log(ans);
});


function main(input) {
  const s = input
  let array = []
  for(let i=1; i<100; i++){
    array.push(2019*i)
  }

  let matchCounter = ''
  for(let j=0; j<array.length; j++){
    let regNumber = array[j]
    let match = s.match( new RegExp(`${regNumber}`, 'g'))
    if ((match || '').length > 0){
      matchCounter += '#'
    }
  }

  console.log(matchCounter.length)

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


const Main = input => {
  let count = 0;
  for(let i = 0; i < input.length; i++) {
    for(let j = 0; j < input.length; j++) {
      if(j < i) continue;//条件より
      const result = input.substr(i, j - i + 1);//切り出し
      const num = parseInt(result, 10);

      if(num % 2019 === 0) count++;
    }
  }

  console.log(count);
}

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


"use strict"
function main(arg) {
    let s = arg.trim().split("\n")[0]
    let counter = 0
    for (let i = 0; i < s.length - 4; i++) {
        for (let j = i + 4; j < s.length + 1; j++) {
            // console.log()
            if (Number(s.slice(i, j)) % 2019 === 0) {
                counter++
            }
        }
    }
    console.log(counter)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function solve(src, str) {
    let counter = 0
    let start = 0
    for (;;) {
        let n = src.indexOf(str, start)
        if (n < 0) {
            return counter
        }
        if (n >= 0) {
            counter++
            start = n + 1
        }
    }
    return counter
}


input = require('fs').readFileSync('/dev/stdin','utf8');
N = input.split('');
r = 0;
for(i = 0; i < N.length; i++) {
  if(i<=200000) {
    for(j = i + 4; j <= N.length - 1; j++) {
      if(j <= 200000) {
        v = parseInt(input.substring(i,j),10);
        if(v % 2019 == 0) r++;
      }
    }
  }
}
console.log(r);


"use strict"
function main(arg) {
    let s = arg.trim().split("\n")[0]
    let counter = 0
    for (let i = 0; i < 1000; i++) {
        let x = i * 2019
        if (x > Number(s)) {
            break
        }
        let num = solve(s, String(x))
        counter += num
        // if (num.length > 0) {
        //     console.log(JSON.stringify(num))
        //     // counter += num
        // }
        // console.log(i * 2019)
    }
    console.log(counter)
    // console.log(JSON.stringify(solve("1212121", '121')))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function solve(src, str) {
    let counter = 0
    let start = 0
    for (let i = 0; i < 10000; i++) {
        let n = src.indexOf(str, start)
        // console.log(counter)
        if (n < 0) {
            return counter
        }
        if (n >= 0) {
            counter++
            start = n + 1
        }
    }
    return counter
}


const Main = S => {
  let count = 0;
  for(let i=0; i<=S.length-1; i++) {
    for(let j=i+1; j<=S.length; j++) {
      const num = Number(S.slice(i, j));
      if(num % 2019 === 0) count++;
    }
  }
  console.log(count);
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
/*Main(`1817181712114`);
Main(`14282668646`)
Main(`2119`)*/


"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+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);}

class dijkstra{
  constructor(n){
    this.graph = Array(n).fill().map(a=>[]);
  }
  add(u,v,cost){
    this.graph[u].push(v,cost);
  }
  add2(u,v,cost){
    this.graph[u].push(v,cost);
    this.graph[v].push(u,cost);
  }
  solve(start){
    const INF = 1e18;
    const g = this.graph;
    var pq = new priorityQueue();
    pq.push([0,start]);
    var dp = Array(g.length).fill(INF);
    dp[start] = 0;
    while(pq.size){
      var [t,v] = pq.pop();
      if(dp[v] < t)continue;
      for(var i = 0; i < g[v].length; i+=2){
        var V = g[v][i], c = g[v][i+1] + t;
        if(dp[V] <= c)continue;
        dp[V] = c;
        pq.push([c,V]);
      }
    }
    return dp;
  }
}

class priorityQueue{
  constructor(){
    this.a=[];
  }
  push(x){
    const a = this.a;
    for(var i = a.length, j; i; i = j){
      j = i - 1 >> 1;
      if(x[0] >= a[j][0])break;
      a[i] = a[j];
    }
    a[i] = x;
  }
  pop(){
    const a = this.a;
    var r = a[0];
    var x = a.pop();
    var k = a.length >> 1;
    for(var i = 0, j; i < k; i = j){
      j = (i << 1) + 1;
      if(a[j+1] && a[j][0] > a[j+1][0])j++;
      if(a[j][0] >= x[0])break;
      a[i] = a[j];
      i = j;
    }
    if(a.length)a[i] = x;
    return r;
  }
  get size(){
    return this.a.length;
  }
  get top(){
    return this.a[0];
  }
}

const mx = 2500;

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

function main(){
  var [n,m,s] = nexts(3);
  var g = new dijkstra(mx * n);
  for(var i = 0; i < m; i++){
    var [u,v,a,b] = nexts(4);
    u--,v--;
    u *= mx, v *= mx;
    for(var j = mx; j-- > a;){
      g.add(u+j,v+j-a,b);
      g.add(v+j,u+j-a,b);
    }
  }
  for(var i = 0; i < n; i++){
    var [c,d] = nexts(2);
    var v = i * mx;
    for(var j = 0; j < mx-1; j++)g.add(v+j,v+Math.min(mx-1,j+c),d);
  }
  var dp = g.solve(Math.min(mx-1,s));
  var ans = xArray(1e18,n);
  for(var i = 1; i < n; i++){
    var v = i*mx;
    for(var j = 0; j < mx; j++){
      ans[i] = Math.min(ans[i],dp[v+j]);
    }
  }
  return ans.slice(1).join("\n");
}

Score : 500 points

Problem Statement

There are N cities numbered 1 to N, connected by M railroads.

You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket.

The i-th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silver coins and takes B_i minutes.
You cannot use gold coins to pay the fare.

There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin.
The transaction takes D_i minutes for each gold coin you give.
You can exchange any number of gold coins at each exchange counter.

For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains.

Constraints

2 \leq N \leq 50

N-1 \leq M \leq 100

0 \leq S \leq 10^9

1 \leq A_i \leq 50

1 \leq B_i,C_i,D_i \leq 10^9

1 \leq U_i < V_i \leq N

There is no pair i, j(i \neq j) such that (U_i,V_i)=(U_j,V_j).

Each city t=2,...,N can be reached from City 1 with some number of railroads.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M S
U_1 V_1 A_1 B_1
:
U_M V_M A_M B_M
C_1 D_1
:
C_N D_N

Output

For each t=2, ..., N in this order, print a line containing the minimum time needed to travel from City 1 to City t.

Sample Input 1

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

Sample Output 1

2
14

The railway network in this input is shown in the figure below.

In this figure, each city is labeled as follows:

The first line: the ID number i of the city (i for City i)

The second line: C_i / D_i

Similarly, each railroad is labeled as follows:

The first line: the ID number i of the railroad (i for the i-th railroad in input)

The second line: A_i / B_i

You can travel from City 1 to City 2 in 2 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 2 minutes.

You can travel from City 1 to City 3 in 14 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 2 minutes.

At the exchange counter in City 2, exchange 3 gold coins for 3 silver coins in 6 minutes.

Use the 1-st railroad to move from City 2 to City 1 in 2 minutes.

Use the 2-nd railroad to move from City 1 to City 3 in 4 minutes.

Sample Input 2

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

Sample Output 2

5
5
7

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 4 in 7 minutes, as follows:

At the exchange counter in City 1, exchange 2 gold coins for 6 silver coins in 2 minutes.

Use the 2-nd railroad to move from City 1 to City 3 in 4 minutes.

Use the 4-th railroad to move from City 3 to City 4 in 1 minutes.

Sample Input 3

6 5 1
1 2 1 1
1 3 2 1
2 4 5 1
3 5 11 1
1 6 50 1
1 10000
1 3000
1 700
1 100
1 1
100 1

Sample Output 3

1
9003
14606
16510
16576

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 6 in 16576 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.

At the exchange counter in City 2, exchange 3 gold coins for 3 silver coins in 9000 minutes.

Use the 1-st railroad to move from City 2 to City 1 in 1 minute.

Use the 2-nd railroad to move from City 1 to City 3 in 1 minute.

At the exchange counter in City 3, exchange 8 gold coins for 8 silver coins in 5600 minutes.

Use the 2-nd railroad to move from City 3 to City 1 in 1 minute.

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.

Use the 3-rd railroad to move from City 2 to City 4 in 1 minute.

At the exchange counter in City 4, exchange 19 gold coins for 19 silver coins in 1900 minutes.

Use the 3-rd railroad to move from City 4 to City 2 in 1 minute.

Use the 1-st railroad to move from City 2 to City 1 in 1 minute.

Use the 2-nd railroad to move from City 1 to City 3 in 1 minute.

Use the 4-th railroad to move from City 3 to City 5 in 1 minute.

At the exchange counter in City 5, exchange 63 gold coins for 63 silver coins in 63 minutes.

Use the 4-th railroad to move from City 5 to City 3 in 1 minute.

Use the 2-nd railroad to move from City 3 to City 1 in 1 minute.

Use the 5-th railroad to move from City 1 to City 6 in 1 minute.

Sample Input 4

4 6 1000000000
1 2 50 1
1 3 50 5
1 4 50 7
2 3 50 2
2 4 50 4
3 4 50 3
10 2
4 4
5 5
7 7

Sample Output 4

1
3
5

The railway network in this input is shown in the figure below:

Sample Input 5

2 1 0
1 2 1 1
1 1000000000
1 1

Sample Output 5

1000000001

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 2 in 1000000001 minutes, as follows:

At the exchange counter in City 1, exchange 1 gold coin for 1 silver coin in 1000000000 minutes.

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.


"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+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);}

class dijkstra{
  constructor(n){
    this.graph = Array(n).fill().map(a=>[]);
  }
  add(u,v,cost){
    this.graph[u].push(v,cost);
  }
  add2(u,v,cost){
    this.graph[u].push(v,cost);
    this.graph[v].push(u,cost);
  }
  solve(start){
    const INF = 1e18;
    const g = this.graph;
    var pq = new priorityQueue();
    pq.push([0,start]);
    var dp = Array(g.length).fill(INF);
    dp[start] = 0;
    while(pq.size){
      var [t,v] = pq.pop();
      if(dp[v] < t)continue;
      for(var i = 0; i < g[v].length; i+=2){
        var V = g[v][i], c = g[v][i+1] + t;
        if(dp[V] <= c)continue;
        dp[V] = c;
        pq.push([c,V]);
      }
    }
    return dp;
  }
}

class priorityQueue{
  constructor(){
    this.a=[];
  }
  push(x){
    const a = this.a;
    var i = a.length;
    while(i){
      var j = i - 1 >> 1;
      if(x[0] >= a[j][0])break;
      a[i] = a[j];
      i = j;
    }
    a[i] = x;
  }
  pop(){
    const a = this.a;
    var r = a[0];
    var x = a.pop();
    var i = 0;
    var k = a.length >> 1;
    while(i < k){
      var j = (i << 1) + 1;
      if(a[j+1] && a[j][0] > a[j+1][0])j++;
      if(a[j][0] >= x[0])break;
      a[i] = a[j];
      i = j;
    }
    if(a.length)a[i] = x;
    return r;
  }
  get size(){
    return this.a.length;
  }
  get top(){
    return this.a[0];
  }
}

const mx = 2500;

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

function main(){
  var [n,m,s] = nexts(3);
  var g = new dijkstra(mx * n);
  for(var i = 0; i < m; i++){
    var [u,v,a,b] = nexts(4);
    u--,v--;
    u *= mx, v *= mx;
    for(var j = mx; j-- > a;){
      g.add(u+j,v+j-a,b);
      g.add(v+j,u+j-a,b);
    }
  }
  for(var i = 0; i < n; i++){
    var [c,d] = nexts(2);
    var v = i * mx;
    for(var j = 0; j < mx-1; j++)g.add(v+j,v+Math.min(mx-1,j+c),d);
  }
  var dp = g.solve(Math.min(mx-1,s));
  var ans = xArray(1e18,n);
  for(var i = 1; i < n; i++){
    var v = i*mx;
    for(var j = 0; j < mx; j++){
      ans[i] = Math.min(ans[i],dp[v+j]);
    }
  }
  return ans.slice(1).join("\n");
}


"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+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 priorityQueue=(function(){
  function f(){return new PriorityQueue();}
  function PriorityQueue(){
    this.heap=[];
  }
  PriorityQueue.prototype.push=function(x){
    var h=this.heap,i=h.length++,j;
    while(i){
      j=i-1>>1;
      if(h[j][0]<=x[0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
  };
  PriorityQueue.prototype.pop=function(){
    var h=this.heap,r=h[0],x=h.pop(),l=h.length,i=0,j;
    if(l===0)return r;
    var k=l>>1;l--;
    while(i<k){
      j=(i<<1)+1;
      if(j<l&&h[j+1][0]<h[j][0])j++;
      if(x[0]<=h[j][0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
    return r;
  };
  return f;
})();

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

function main(){
  var [n,m,s] = nexts(3);
  var graph = xArray("[]",n);
  for(var i = 0; i < m; i++){
    var [u,v,a,b] = nexts(4);
    u--,v--;
    graph[u].push([v,a,b]);
    graph[v].push([u,a,b]);
  }
  var d = nextm(n,2);
  var map = xArray(1e18,n,2501);
  var rem = n;
  var ans = xArray(1e18,n);
  var pq = new priorityQueue();
  if(s > 2500)s = 2500;
  pq.push([0,0,s]);
  while(rem){
    var [t,v,c] = pq.pop();
    if(ans[v] === 1e18)rem--, ans[v] = t;
    if(map[v][c] < t)continue;
    if(c < 2500){
      var tt = t + d[v][1];
      var cc = c + d[v][0];
      if(cc >= 2500)cc = 2500;
      if(map[v][cc] > t)map[v][cc] = tt, pq.push([tt,v,cc]);
    }
    for(var i = 0; i < graph[v].length; i++){
      var cc = c - graph[v][i][1];
      if(cc < 0)continue;
      var tt = t + graph[v][i][2], V = graph[v][i][0];
      if(map[V][cc] <= tt)continue;
      pq.push([tt,V,cc]);
    }
  }
  return ans.slice(1).join("\n");
}


function main(input) {
  const R = Number(input)
  console.log(Math.PI * 2 * R)

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

Score : 100 points

Problem Statement

Print the circumference of a circle of radius R.

Constraints

1 \leq R \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

R

Output

Print the circumference of the circle.
Your output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.

Sample Input 1

1

Sample Output 1

6.28318530717958623200

Since we accept an absolute or relative error of at most 10^{-2}, 6.28 is also an acceptable output, but 6 is not.

Sample Input 2

73

Sample Output 2

458.67252742410977361942


"use strict";
function main(input) {
    var line = input.split("\n");
    const pi = 3.14159265359;
    let R = parseInt(line[0]);
    var circumference = 2*pi*R;
    console.log(circumference.toPrecision(20));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


  function circumference(r)　{
  circumference = r*2*3.14
  return circumference
  }
console.log(circumference(R))


const main = input => parseInt(input)*2*Math.PI

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


const Main = (input) => {
  const r = parseInt(input)

  const result = 2 * Math.PI * r
  console.log(result)
  return result
}

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


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	//出力
	console.log(Number(input)*2*Math.PI);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input){
    console.log(2*3.14*input);
}

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


var radius = R
var circumference = 6.28 * R
circumference==circumference


"use strict";

var processData = function processData(lines) {
  var r = +lines[0];
  console.log(r * Math.PI * 2);
};

var i = '';
process.stdin.on('data', function (c) {
  return i += c;
});
process.stdin.on('end', function () {
  var _require = require('os'),
      EOL = _require.EOL;

  var lines = i.split(EOL);
  /*your input text, split by lines*/

  processData(lines);
});


const main = (inputs) => {
  console.log(calculateCircumference(inputs[0] - 0));
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

function calculateCircumference(radius) {
  return 2 * Math.PI * radius;
}


function Main(input){
    console.log(Math.PI*input*2)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


"use strict"
function main(arg) {
    let r = arg.trim().split("\n")[0]
    r = Number(r)
    console.log(2* r * Math.PI)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
  let n = parseInt(input, 10);
  let ans = n * 2 * Math.PI;

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


const n = 1;

function Main(input) {
  let a = parseInt(n, 10);
  let ans = a * 2 * Math.PI;

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


process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!

const gcdArr = function(arr) {
  let gcdres = gcd(arr[0], arr[1])
  for (let i=2; i<arr.length; i++) {
    gcdres = gcd(gcdres, arr[i])
  }
  return gcdres
}

function gcd_impl(n,m) {
        for( let i = 0; i < 10; ++i ) {
                let t = n - m;
                let q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

function gcd( n, m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

const Main = (p)=>{
	// 1行目がinput[0], 2行目がinput[1], …に入る

	let t = parseInt(p);//p.split(" ").map(Number);
	//文字列から10進数に変換するときはparseIntを使います
	//出力

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


function Main(input) {
    var a = input[0]-0;
    console.log(a*2*Math.PI);

}

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


const Main = input => {
  const R = Number(input);
  const result = Math.PI * 2 * R;
  console.log(result);
};

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


const rl = require("readline").createInterface(process.stdin, process.stdout);

rl.on("line", str => {
    console.log([0, 1, 2].filter(e => str.charAt(e) === '7').length > 0 ? "Yes" : "No");
});

Score : 100 points

Problem Statement

Given is a three-digit integer N. Does N contain the digit 7?

If so, print Yes; otherwise, print No.

Constraints

100 \leq N \leq 999

Input

Input is given from Standard Input in the following format:

N

Output

If N contains the digit 7, print Yes; otherwise, print No.

Sample Input 1

117

Sample Output 1

Yes

117 contains 7 as its last digit.

Sample Input 2

123

Sample Output 2

No

123 does not contain the digit 7.

Sample Input 3

777

Sample Output 3

Yes


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

    let message = 'No';

    for (let i = 0, len = array.length; i < len; i++) {
        if (array[i] == '7') {
            message = 'Yes';
            break;
         }
    }

    console.log(message);
}

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


const Main = (input) => {
  const tmp = input.trim().split('')

  let result = ''

  if (tmp.indexOf('7') === -1) {
    result = 'No'
  } else {
    result = 'Yes'
  }

  console.log(result)
  return result
}

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


const Main = (input) => {
  const tmp = input.trim().toString().split('')

  const exist = tmp.indexOf('7')

  let result = ''
  if (exist === -1) {
    result = 'No'
  } else {
    result = 'Yes'
  }

  console.log(result)
  return result
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


var input = process.argv[1];
var result = 0;
for (var a = 1; a <= input; a++) {
  for (var b = 1; b <= input; b++) {
    for (var c = 1; c <= input; c++) {
      // console.log(a + " " + b + " " + c);
      result += gcd(gcd(a, b), c);
    }
  }
}
console.log(result);

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


function Main(input) {
  const nums = input.toString().split("");
  if (nums.some(v => v === '7')){
    console.log('Yes');
  }else{
    console.log('No');
  }
}

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


'use strict';
function main(input) {
  input = input.split("\n");
  const a = input[0];

  if (a.match(/7/)) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

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


function Main(input) {
	console.log(String(input).indexOf('7')>=0 ? 'Yes' : 'No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(x) {
    if (x >99 || x <1000) {
        let _n = [];
let n = x.toString();
        _n[0] = n.charAt(0);
        _n[1] = n.charAt(1);
        _n[2] = n.charAt(2);
        const a = _n.filter(_a => _a === '7');
        if(a.length < 1){
            console.log('No');
        } else {
            console.log('Yes');
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(x) {
    if (x >99 || x <1000) {
        let _n = [];
let n = x.toString();
        _n[0] = n.charAt(0);
        _n[1] = n.charAt(1);
        _n[2] = n.charAt(2);
        const a = _n.filter(_a => _a === '7');
        if(a.length < 1){
            return 'No';
        } else {
            return 'Yes';
        }
    }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


function gcd(i,j,k){
    var max = 0;
    if(max<i){max = i;}
    if(max<j){max = j;}
    if(max<k){max = k;}
    var a =0;
    for(var count=1;count<=max;count++){
        if(count <= 2 || count%2==1){
            if((i%count ==0 && i>=count) && (j%count == 0 && j>=count) && (k%count == 0 && k>=count)){a = count;}
        }
    }

    return a;

}

function Main(input) {
    var N = parseInt(input,10);
    var sum = 0;
    for(var i=1;i<=N;i++){
        for(var j=1;j<=N;j++){
            for(var k=1;k<=N;k++){
                //console.log(i+","+j+","+k)
                sum += gcd(i,j,k);
            }
        }
    }

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


'use strict';
const p = s => console.log(s);

// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  let N = input[0].split(" ")[0];

  let isSeven = false;

  while(N>1) {
    let num = Math.floor(N % 10)
    if(num === 7) {
      isSeven = true;
      break;
    }
    N = Math.floor(N / 10)
  }
  if(isSeven) p('Yes');
  else p('No');
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


let a = N;
let stringarr = String(a).split("");

let seven = function (arr){
    if (arr.some(value => value == 7)) {
    	return "Yes"
    }else {
    	return "No"
    }
}

seven(stringarr);


process.stdin.resume();
function Main(input){
	input = input.split("");
	console.log((input[0]==7||input[1]==7||input[2]==7)?"Yes":"No");
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  inputs = input.split("\n");

  console.log( inputs[0].includes('7') ? 'Yes' :'No');

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


const gcd = (m, n) => {
  while (n > 0) {
    const r = m % n
    m = n
    n = r
  }
  return m
}

const Main = (input) => {
  const tmp = parseInt(input.trim())

  let result = 0

  for (let i = 1; i <= tmp; ++i) {
    for (let j = 1; j <= tmp; ++j) {
      for (let k = 1; k <= tmp; ++k) {
        result += gcd(gcd(i, j), k)
      }
    }
  }

  console.log(result)
  return result
}

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

Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692


let input = process.argv[2];
var result = 0;
for (var a = 1; a <= input; a++) {
  for (var b = 1; b <= input; b++) {
    for (var c = 1; c <= input; c++) {
      // console.log(a + " " + b + " " + c);
      result += gcd(gcd(a, b), c);
    }
  }
}
console.log(result);

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


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 k = Number(lines[0]);
 var one = 1;
 var two = 1;
 var three = 1;
 var ans = 0;
 var n = 0;

 while(n !== k){
   ans += gcd(one,two,three);
   if(one == two && two == three){
     three = three + 1;
   }else if((one == two && two !== three) && one < three){
     two = two + 1;
     three = three - 1;
   }else if((one == three && one !== two) && one < two){
     three = three + 1;
   }else if((two == three && one != two) && (one < two)){
     one = one + 1;
   }else if((two == three && one != two) && (one > two)){
     three = three + 1;
   }else if((one == three && one !== two) && (one > two)){
     two = two + 1;
     three = three - 1;
   }else if((one == two && two !== three) && (one > three)){
     three = three + 1;
   }

   n++;
 }

 console.log(ans);

function gcd() {
     var f = (a, b) => b ? f(b, a % b) : a
     var ans = arguments[0]
     for (var i = 1; i < arguments.length; i++) {
         ans = f(ans, arguments[i]);
     }
     return ans;

}

});


// inputに入力データ全体が入る
function Main(input) {
  const RECORDS = [];
  const gcd = (a,b,c) => {
    if(RECORDS[`${a}${b}${c}`] ){
      return RECORDS[`${a}${b}${c}`];
    }

    // 最大公約数を求める
    const max = Math.max( a , Math.max( b, c));
    let ans = 0;

    for( let i = 1 ; i <= max ; i++ ){
      if( a % i === 0 && b % i === 0 && c % i === 0){
        ans = i;
      }
    }

    RECORDS[`${a}${b}${c}`] = ans;

    return ans ;
  };

  // 1行目がinput[0], 2行目がinput[1], …に入る
  inputs = input.split("\n");

  const K = Number(inputs[0]);

  let sum = 0 ;
  const tupples = [];
  for( let a = 1 ; a <= K ; a++ ){
    for( let b= 1 ; b <= K ; b++ ){
      for( let c= 1 ; c <= K ; c++ ){
        sum += gcd(...[a,b,c].sort((a,b)=> a -b ));
      }
    }
  }

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


"use strict";

// 最大公約数その2（多入力対応）
const getGcd = array => {
  let len, a, b;

  len = array.length;
	a   = array[0];

  for (let i=1; i<len; i++) {
		b = array[i];
		a = gcdTwoNumbers(a, b);
	}

	return a;
}

function gcdTwoNumbers(x, y) {
  x = Math.abs(x);
  y = Math.abs(y);
  while(y) {
    let t = y;
    y = x % y;
    x = t;
  }
  return x;
}

//　組み合わせ 被りなし
const combineWithoutRepetitions = (comboOptions, comboLength) => {
  if (comboLength === 1) {
    return comboOptions.map(comboOption => [comboOption]);
  }

  // Init combinations array.
  const combos = [];

  // Eliminate characters one by one and concatenate them to
  // combinations of smaller lengths.
  comboOptions.forEach((currentOption, optionIndex) => {
    const smallerCombos = combineWithoutRepetitions(
      comboOptions.slice(optionIndex + 1),
      comboLength - 1
    );

    smallerCombos.forEach((smallerCombo) => {
      combos.push([currentOption].concat(smallerCombo));
    });
  });

  return combos;
}

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

    let answer = 0;
    let A = [];

    for(let i=1; i<=K; i++) {
        A.push(i);
    }

    // 1種類の時
    for(let i=1; i<=K; i++) {
        answer += i;
    }

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

    // 2種類の時
    const combos2 = combineWithoutRepetitions(A, 2);
    const N2 = combos2.length;

    for(let i=0; i<N2; i++) {
        answer += gcdTwoNumbers(combos2[i][0], combos2[i][1]) * 6;
    }

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

    // 3種類の時
    const combos3 = combineWithoutRepetitions(A, 3);
    const N3 = combos3.length;

    for(let i=0; i<N3; i++) {
        answer += getGcd(combos3[i]) * 6;
    }

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

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


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

const lines = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line)
});
reader.on('close', () => {
  const inputLength = Number(lines[0])
  const inputString = lines[1]
  const inputArray = inputString.split('')
  const rArray = inputArray.filter(element => element === 'R')
  const gArray = inputArray.filter(element => element === 'G')
  const bArray = inputArray.filter(element => element === 'B')

  let sum = 0
  for (let i = 1; i < Number(inputLength) + 1; i++) {
    for (let j = i + 1; j < Number(inputLength) + 1; j++) {
      for (let k = j + 1; k < Number(inputLength) + 1; k++) {
        if(j - i === k - j && inputArray[i - 1] !== inputArray[j - 1]  && inputArray[j - 1] !== inputArray[k - 1] && inputArray[i - 1] !== inputArray[k - 1]){
          sum = sum + 1
        }
      }
    }
  }

  console.log(rArray.length * gArray.length * bArray.length - sum)

});

Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800


    // inputに入力データ全体が入る
    function Main(inputString) {
        // 1行目がinput[0], 2行目がinput[1], …に入る
        arrInputString = inputString.trim().split("\n");
        const ARR_LENGTH = parseInt(arrInputString[0], 10);
        const RGB_STRING  = arrInputString[1];
        let sum = 0;
        let arrR = [];
        let arrG = [];
        let arrB = [];

        // 仕分け
        for(let i = 0; i<ARR_LENGTH; i++){
            let tmpChar = RGB_STRING.substr(i,1)
            if(tmpChar = 'R'){
                arrR.push(i+1);
            }else if (tmpChar = 'G'){
                arrG.push(i+1);
            }else if(tmpChar = 'B'){
                arrB.push(i+1);
            }
        }

        arrR.forEach( (tmpRNumber) => {
            arrG.forEach( (tmpGNumber) => {
                arrB.forEach( (tmpBNumber) => {
                    if( (tmpGNumber - tmpRNumber) != (tmpBNumber - tmpGNumber)){
                        sum++;
                    }
                })
            })
        })

    	//出力
    	console.log(sum);
    }

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