Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(K, J) {
  2.     const diff = Math.abs(K - J);
  3.     const max = Math.max(K, J);
  4.     const result = max - diff;
  5.     if (result === 0)
  6.         console.log(0);
  7.     else
  8.         console.log(Math.floor((result *2) / 3));
  9. }
  10.  
  11. function main() {
  12.     // write your code here.
  13.     // call functions `nextString`, `nextFloat` and `nextInt`
  14.     // to read the next token of input (ignoring whitespace)
  15.     // Alternatively, you can create your own input parser functions
  16.     // use console.log() to write to stdout
  17.  
  18.     var K = nextInt();
  19.     var J = nextInt();
  20.     solution(K, J);
  21.     // var s = nextString();
  22.     // var c = nextChar();
  23.     // var f = nextFloat();
  24. }
  25.  
  26. // default parsers for JS.
  27. function nextInt() {
  28.     return parseInt(nextString());
  29. }
  30.  
  31. function nextFloat() {
  32.     return parseFloat(nextString());
  33. }
  34.  
  35. function nextString() {
  36.     var next_string = "";
  37.     clearWhitespaces();
  38.     while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {
  39.         next_string += input_stdin[input_cursor];
  40.         input_cursor += 1;
  41.     }
  42.     return next_string;
  43. }
  44.  
  45. function nextChar() {
  46.     clearWhitespaces();
  47.     if (input_cursor < input_stdin.length) {
  48.         return input_stdin[input_cursor++];
  49.     } else {
  50.         return '\0';
  51.     }
  52. }
  53.  
  54. process.stdin.resume();
  55. process.stdin.setEncoding('ascii');
  56.  
  57. var input_stdin = "";
  58. var input_cursor = 0;
  59. process.stdin.on('data', function (data) {
  60.     input_stdin += data;
  61. });
  62. process.stdin.on('end', function () {
  63.     main();
  64. });
  65.  
  66. function isWhitespace(character) {
  67.     return ' \t\n\r\v'.indexOf(character) > -1;
  68. }
  69.  
  70. function clearWhitespaces() {
  71.     while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {
  72.         // ignore the next whitespace character
  73.         input_cursor += 1;
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement