The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).

The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.

Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

NoteToday is Monday, the 13th of June, 2016.

var year = parseInt(readline());
var isCurrYearLeap = isLeap(year);
var diff = 0;
function isLeap(_year) {
	if (_year%4 !== 0){
		return false;
	} else if (_year%100 !== 0) {
		return true;
	} else if (_year%400 !== 0) {
		return false;
	} else {
		return true;
	}
}

while(true){
	if (isLeap(year)) {
		diff += 2;
	} else {
		diff += 1;
	}
	year++;
	if(diff % 7 === 0 && isLeap(year) === isCurrYearLeap){
		break;
	}
}

print(year);

input = readline().split(' ');
d = 0;
temp_year = year = parseInt(input[0]);
while (true) {
        if (!(d % 7) && is_leap(year) == is_leap(temp_year) && d) {
                print(temp_year);
                break
        }
        temp_year++;
        d += (is_leap(temp_year) ? 366 : 365)
}

function is_leap(year) {
        return (!(year % 400) || (year % 100)) && !(year % 4)
}


A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive.

Input contains one integer number n (1 ≤ n ≤ 3000).

Output the amount of almost prime numbers between 1 and n, inclusive.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const n = +readLine();

  function countAlmostPrimes(n) {
    const primes = getAllPrimesUpto(n);
    let almostPrimeCount = 0;

    for (let i = 1; i <= n; i++) {
      let count = 0;
      let j = 0;
      while (primes[j] < i && j < n) {
        if (i % primes[j] === 0) count++;
        j++;
      }
      if (count === 2) almostPrimeCount++;
    }
    return almostPrimeCount;
  }

  console.log(countAlmostPrimes(n));
}

function getAllPrimesUpto(n) {
  const primes = [];
  for (let i = 2; i <= n; i++) {
    let isPrime = true;
    for (let j = 2; j <= Math.floor(Math.sqrt(i)); j++) {
      if (i % j === 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) primes.push(i);
  }

  return primes;
}

const readline = require('readline');

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

var isPrime = function (n) {
    if (n === 2)
        return true;
    if (n % 2 === 0) return false;
    let limit = parseInt(Math.sqrt(n));
    for (let i = 3; i <= limit; i += 2) {
        if (n % i === 0)
            return false;
    }
    return true;
}

var hasExactlyTwoPrimeDivs = function (n) {
    let counter = 0, limit = parseInt(n / 2);
    for (let i = 2; i <= limit; i++)
        counter += (n % i == 0 && isPrime(i));

    return counter == 2;
}

rl.on('line', function (input) {
    let n = parseInt(input), ans = 0;
    for (let i = 6; i <= n; i++)
        ans += hasExactlyTwoPrimeDivs(i);
    console.log(ans);
    rl.close();

});

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

const getPrimes = (d) => {
  const maxN = d;
  const arr = new Array(maxN + 1).fill(1);
  arr[0] = 0;
  arr[1] = 0;

  for (let i = 2; i*i <= maxN; i++) {
    if (arr[i]) {
      for (let j = i*i; j <= maxN; j += i) {
        arr[j] = 0;
      }
    }
  }

  const primes = [];

  for (let i = 0; i < arr.length; i++) {
    if (arr[i]) {
      primes.push(i);
    }
  }

  return primes;
}

rl.on('line', (d) => {
  const primes = getPrimes(+d);

  let ans = 0;

  for (let i = 6; i <= +d; i++) {
    let primeDivisors = 0;
    for (let p = 0; p < primes.length; p++) {
      if (i % primes[p] === 0) {
        primeDivisors++;
      }
    }

    if (primeDivisors === 2) {
      ans++;
    }
  }

  console.log(ans);
  c++;
});

const readline = require('readline');

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

function isPrime(num) {
    if (num == 2) return true;
    if (num % 2 == 0 || num < 2) return false;
    let s = Math.sqrt(num);
    for (let i = 3; i <= s; i+=2) {
        if (num % i == 0) return false;
    }
    return true;
};

function hasExactlyTwoPrimeDivis(num) {
    var counter = 0;
    for (var i = 2; i < num; i++) {
        if (num % i == 0 && isPrime(i))
            counter++;
        if (counter > 2)
            return false;

    }
    return counter==2;
}

rl.on('line', (input) => {
    var N = parseInt(input);
    var ans = 0;
    for (let i = 6; i <= N; i++)
          ans+=hasExactlyTwoPrimeDivis(i);

     console.log(ans);
     rl.close();
});

const readline = require('readline');

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

rl.on('line', function (input) {
   // myArr = input.split(' ').map(item => {return parseInt(item);});
var N = parseInt(input);
var Primes = [];
for(var i = 2; i <= N; i++)
    if (IsPrime(i)) Primes.push(i);

var ans = 0;
for (var i = 1; i <= N; i++)
    if (IsAlmostPrime(i, Primes)) ans++;

console.log(ans);

    rl.close();
})

//******************************MY FUNCTIONS */

function IsPrime(n)
{
    if (n == 2 ) return true;
    if (n <= 1|| n%2==0)
        return false;
        //for (int i = 2; i <= n/2; i++)
        //    if (n % i == 0)
        //        return false;
      var limit = parseInt(Math.sqrt(n));
    for (var i = 3; i <= limit; i+=2)
        if (n % i == 0)
           return false;

    return true;
}

function IsAlmostPrime(n, pNums)
{
    var countDivisor = 0;
    for (var i = 0; i < pNums.length; i++)
    {
        if (n % pNums[i] == 0) countDivisor++;
        if (pNums[i] > n / 2) break;
    }
    return countDivisor == 2;
}

'use strict'

const N = +readline()

let s = getSimples(N)

let as = []

o: for (let i = 6; i <= N; i++) {
  let dc = 0
  for (let j = 0; j < s.length; j++) {
    if (!(i % s[j])) dc++
  }
  if (dc == 2) as.push(i)
}

print(as.length)

function getSimples (n) {
  let simples = [2]
  o: for (let i = 3; i <= n; i++) {
    for (let j = 0; j < simples.length | 0; j++) {
      if (!(i % simples[j])) continue o
    }
    simples.push(i)
  }
  return simples
}

var n = +readline(),
    nums = new Array(n + 1).fill(1);

for (var i = 2; i <= n; i ++)
{
  if (nums[i] === 1)
  {
    for (var j = 2 * i; j <= n; j += i)
    {
      nums[j] ++;
    }
  }
}

var total = 0;
for (var i = 2; i <= n; i ++)
{
  if (nums[i] === 3)
  {
    total ++;
  }
}

print(total);

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const n = +readLine();

  function countAlmostPrimes(n) {
    const primes = getAllPrimesUpto(n);
    let almostPrimeCount = 0;

    for (let i = 1; i <= n; i++) {
      let count = 0;
      let j = 0;
      while (primes[j] < i && j <= n) {
        if (i % primes[j] === 0) count++;
        if (count >= 2) {
          almostPrimeCount++;
          break;
        }
        j++;
      }
    }
    return almostPrimeCount;
  }

  console.log(countAlmostPrimes(n));
}

function getAllPrimesUpto(n) {
  const primes = [];
  for (let i = 2; i <= n; i++) {
    let isPrime = true;
    for (let j = 2; j <= Math.floor(Math.sqrt(i)); j++) {
      if (i % j === 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) primes.push(i);
  }

  return primes;
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  function countAlmostPrimes(n) {
    const primes = getAllPrimesUpto(n);
    let almostPrimeCount = 0;

    for (let i = 1; i <= n; i++) {
      let count = 0;
      let j = 0;
      while (primes[j] < i && j <= n) {
        if (i % primes[j] === 0) count++;
        if (count >= 2) {
          almostPrimeCount++;
          break;
        }
        j++;
      }
    }
    return almostPrimeCount;
  }

  console.log(countAlmostPrimes(3000));
}

function getAllPrimesUpto(n) {
  const primes = [];
  for (let i = 2; i <= n; i++) {
    let isPrime = true;
    for (let j = 2; j <= Math.floor(Math.sqrt(i)); j++) {
      if (i % j === 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) primes.push(i);
  }

  return primes;
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

const getPrimes = () => {
  const maxN = 25;
  const arr = new Array(maxN + 1).fill(1);
  arr[0] = 0;
  arr[1] = 0;

  for (let i = 2; i*i <= maxN; i++) {
    if (arr[i]) {
      for (let j = i*i; j <= maxN; j += i) {
        arr[j] = 0;
      }
    }
  }

  const primes = [];

  for (let i = 0; i < arr.length; i++) {
    if (arr[i]) {
      primes.push(i);
    }
  }

  return primes;
}

rl.on('line', (d) => {
  const primes = getPrimes();

  let ans = 0;

  for (let i = 6; i <= +d; i++) {
    let primeDivisors = 0;
    for (let p = 0; p < primes.length; p++) {
      if (primes[p] > i) {
        break;
      }

      if (i % primes[p] === 0) {
        primeDivisors++;
      }
    }

    if (primeDivisors === 2) {
      ans++;
    }
  }

  console.log(ans);
  c++;
});


A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.The tournament takes place in the following way (below, m is the number of the participants of the current round):  let k be the maximal power of the number 2 such that k ≤ m,  k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,  when only one participant remains, the tournament finishes. Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.Find the number of bottles and towels needed for the tournament.Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).

The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.

Print two integers x and y — the number of bottles and towels need for the tournament.

NoteIn the first example will be three rounds:  in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),  in the second round will be only one match, so we need another 5 bottles of water,  in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water.In the second example no participant will move on to some round directly.

var str = readline().split(" ", 3);
var n = Number(str[0]), b = Number(str[1]), p = Number(str[2]);

var pa = n * p;

var sum = 0;
while(n !== 1) {
    var k = 1;
    while (k * 2 <= n) {
        k *= 2;
    }
    n = n % k + k / 2;
    sum += k / 2;
}

print(sum * (2 * b + 1) + " " + pa);

/* TEST CASE
input
5 2 3
output
20 15
input
8 2 4
output
35 32
 */
function main() {
	var splitted = readline().split(" ");
	var nParticipants = parseInt(splitted[0]);
	var nBottlesPerEachPersons = parseInt(splitted[1]);
	var nTowelsPerEachPersons = parseInt(splitted[2]);
	var nTowels = nTowelsPerEachPersons * nParticipants;
	var nBottles = 0;

	while (nParticipants > 1) {
		var nPersons = 1 << Math.floor(Math.log(nParticipants)/Math.LN2);
		var nJudges = nPersons / 2;

		nBottles += nBottlesPerEachPersons * nPersons + nJudges;
		nParticipants -= nJudges;
	}
	print(nBottles, nTowels);
}

main();

function main() {

    var arr = readline().split(' ');
    var n = arr[0], b = arr[1], p = arr[2];

    var numberOfTowels = n*p;
    var bottlePerMatches = 2*b + 1;
    var totalMatches = 0;
    var matchesOfRound = 0;
    var next = 0;

    if(n == 1){
        print(0+' '+p);
    }else {

    while (Math.floor(n/2)){
        matchesOfRound = Math.floor(n/2);
        next  = n%2;
        totalMatches += matchesOfRound;

        n = matchesOfRound + next;
    }

    print(totalMatches*bottlePerMatches + ' ' + numberOfTowels);
    }

}

main();

function main() {

    var arr = readline().split(' ');
    var n = arr[0], b = arr[1], p = arr[2];

    var numberOfTowels = n*p;
    var bottlePerMatches = 2*b + 1;
    var totalMatches = 0;
    var matchesOfRound = 0;
    var next = 0;

    if(n == 1){
        print((b+1)+' '+p);
    }

    while (Math.floor(n/2)){
        matchesOfRound = Math.floor(n/2);
        next  = n%2;
        totalMatches += matchesOfRound;

        n = matchesOfRound + next;
    }

    print(totalMatches*bottlePerMatches + ' ' + numberOfTowels);

}

main();

function main() {

    var arr = readline().split(' ');
    var n = arr[0], b = arr[1], p = arr[2];

    var numberOfTowels = n*p;
    var bottlePerMatches = 2*b + 1;
    var totalMatches = 0;
    var matchesOfRound = 0;
    var next = 0;

    if(n == 1){
        print(0+' '+p);
    }

    while (Math.floor(n/2)){
        matchesOfRound = Math.floor(n/2);
        next  = n%2;
        totalMatches += matchesOfRound;

        n = matchesOfRound + next;
    }

    print(totalMatches*bottlePerMatches + ' ' + numberOfTowels);

}

main();


Salve, mi amice.Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.Rp:    I Aqua Fortis    I Aqua Regia    II Amalgama    VII Minium    IV VitriolMisce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via.Fac et spera,Vale,Nicolas Flamel

The first line of input contains several space-separated integers ai (0 ≤ ai ≤ 100).

const input = readline().split(" ").map(x => Number(x));
print(Math.min(input[0], input[1], Math.floor(input[2] * 0.5), Math.floor(input[3] * 0.14285714285714285), Math.floor(input[4] * 0.25)));

const input = readline().split(" ").map(x => Number(x));
const aquaFortis = input[0];
const aquaRegia = input[1];
const amalgama = input[2];
const minium = input[3];
const vitriol = input[4];
print(Math.min(aquaFortis, aquaRegia, Math.floor(amalgama * 0.5), Math.floor(minium * 0.14285714285714285), Math.floor(vitriol * 0.25)));

var input = readline().split(' ').map(function(e){return parseInt(e);});
var min = function(a){
var res = a[0];
a.forEach(function(e){res=(res>e?e:res);});
return res;
};
print(min([input[0],input[1],Math.floor(input[2]/2), Math.floor(input[3]/7), Math.floor(input[4]/4)    ]    ));

function min(a, b)
{
	if(a < b) return a;
	return b;
}

var a = readline().split(" ").map(function(x) {return parseInt(x);});
var dv = [1, 1, 2, 7, 4], ans;
ans = a[0];
for(var i = 1; i < 5; ++i) ans = min(ans, parseInt(a[i] / dv[i]));
print(ans);

var input = readline().split(' ').map(function(e){return parseInt(e);});
var min = function(a){
var res = a[0];
a.forEach(function(e){res=(res>e?e:res);});
return res;
};
print(min([input[0],input[1],Math.floor(input[2]/2), Math.floor(input[3]/6), Math.floor(input[4]/4)    ]    ));


Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Print the maximum number that Pasha can get if he makes at most k swaps.

var line = readline().split(' ')
var a = line[0].split("")
var k = parseInt(line[1])

for (var i = 0; i + 1 < a.length; i++) {
	var p = i
	for (var j = 1; j <= k && i + j < a.length; j++) {
		var q = i + j
		if (a[q] > a[p]) p = q
	}

	for (var j = p - 1; j >= i; j--) {
		var t = a[j]
		a[j] = a[j + 1]
		a[j + 1] = t
	}

	k -= p - i
}

print(a.join(""))

var nm = readline().trim().split(' ');
var a=nm[0],k=parseInt(nm[1]);

var cursor = 0;
var iMaxi = 0;

while(k>0 && cursor<a.length){
    //print(';;;;cursor',cursor);
    var found = false;
    var maxi=a[cursor];
    for(var i=(cursor+1);i<=Math.min(cursor+k,a.length-1);i++){
        //print('com',maxi,a[i])
        if(maxi<a[i]){
          //  print(maxi,a[i])
            found=true;
            iMaxi=i;
            maxi = a[i];
        }
    }
    if(found){
      //  print("----",a.substring(0,cursor), maxi,a.substring(cursor,iMaxi), a.substring(iMaxi+1))
        a =a.substring(0,cursor)+ maxi+a.substring(cursor,iMaxi)+ a.substring(iMaxi+1);

       // print('nbr',iMaxi,cursor,iMaxi-cursor)
        k-=iMaxi-cursor;

    }
    cursor++;

//n    print("====",a)
}
print(a);

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenize(readline()),
		digits = data[0].split(''), n = digits.length,
		swapNum = parseInt(data[1]);
	for (var i = 0; i < digits.length; ++i) {
		digits[i] = parseInt(digits[i]);
	}
	for (var pos = 0; swapNum > 0 && pos < n; ++pos) {
		var max = digits[pos], best = pos,
			limit = Math.min(pos+swapNum, n-1);
		for (var seek = pos+1; seek <= limit; ++seek) {
			if (digits[seek] > max) {
				best = seek;
				max = digits[seek];
			}
		}
		if (best != pos) {
			for (var i = best; i > pos; --i) {
				digits[i] = digits[i-1];
			}
			digits[pos] = max;
			swapNum -= (best-pos);
		}
	}
	print(digits.join(''));
}

main();

var tmp = readline().split(' '),
    a = tmp[0].split(''), n, m, k = parseInt(tmp[1]), i, j, x,
    swap = function(p, q) {
        var t = a[q], i;
        for (i = q; i > p; i--) {
            a[i] = a[i - 1];
        }
        a[p] = t;
    };

for (i = 0, n = a.length - 1; i < n && k > 0; i++) {
    out:
    for (x = 9; x > a[i]; x--) {
        for (j = i + 1, m = Math.min(n, i + k); j <= m; j++) {
            if (a[j] == x) {
                swap(i, j);
                k -= (j - i);
                break out;
            }
        }
    }
}

print(a.join(''));

var line = readline().split(' ')
var a = line[0].split("")
var k = parseInt(line[1])

for (var i = 0; i + 1 < a.length; i++) {
	var p = i
	for (var j = 1; j <= k && i + j < a.length; j++) {
		var q = i + j
		if (a[q] > a[p]) p = q
	}

	var t = a[i]
	a[i] = a[p]
	a[p] = t

	k -= p - i
}

print(a.join(""))

var line = readline().split(' ')
var a = line[0].split("")
var k = parseInt(line[1])

for (var i = 0; i + 1 < a.length; i++) {
	var p = i
	for (var j = 0; j < k && i + j < a.length; j++) {
		var q = i + j
		if (a[q] > a[p]) p = q
	}

	var t = a[i]
	a[i] = a[p]
	a[p] = t

	k -= p - i
}

print(a.join(""))

var nm = readline().trim().split(' ').map((x)=>parseInt(x));
var a=nm[0]+"",k=nm[1];

var cursor = 0;
var iMaxi = 0;

while(k>0 && cursor<a.length){
    //print(';;;;cursor',cursor);
    var found = false;
    var maxi=a[cursor];
    for(var i=(cursor+1);i<=Math.min(cursor+k,a.length-1);i++){
        //print('com',maxi,a[i])
        if(maxi<a[i]){
          //  print(maxi,a[i])
            found=true;
            iMaxi=i;
            maxi = a[i];
        }
    }
    if(found){
       // print("----",a.substring(0,cursor), maxi,a.substring(cursor,iMaxi), a.substring(iMaxi+1))
        a =a.substring(0,cursor)+ maxi+a.substring(cursor,iMaxi)+ a.substring(iMaxi+1);

       // print('nbr',iMaxi,cursor,iMaxi-cursor)
        k-=iMaxi-cursor;

    }
    cursor++;

//n    print("====",a)
}
print(a);

var nm = readline().trim().split(' ').map((x)=>parseInt(x));
var a=nm[0]+"",k=nm[1];

var cursor = 0;
var iMaxi = 0;

while(k>0 && cursor<a.length){
    //print('cursor',cursor);
    var found = false;
    var maxi=a[cursor];
    for(var i=(cursor+1);i<=(cursor+k);i++){
      //  print('com',maxi,a[i])
        if(maxi<a[i]){
        //    print(maxi,a[i])
            found=true;
            iMaxi=i;
            maxi = a[i];
        }
    }
    if(found){
        //print("----",a.substring(0,cursor), maxi,a.substring(cursor,iMaxi), a.substring(iMaxi+1))
        a =a.substring(0,cursor)+ maxi+a.substring(cursor,iMaxi)+ a.substring(iMaxi+1);

        //print('nbr',iMaxi,cursor,iMaxi-cursor)
        k-=iMaxi-cursor;
        cursor=iMaxi+1;
    }else{
        cursor++;
    }
}
print(a);


Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:  on Mondays, Thursdays and Sundays he eats fish food;  on Tuesdays and Saturdays he eats rabbit stew;  on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains:  $$$a$$$ daily rations of fish food;  $$$b$$$ daily rations of rabbit stew;  $$$c$$$ daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

The first line of the input contains three positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 7\cdot10^8$$$) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.

NoteIn the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday — rabbit stew and during Wednesday — chicken stake. So, after four days of the trip all food will be eaten.In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack.In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be $$$99$$$ portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var a = read.arrNumber(' ');
    var ncount = Math.floor(a[0] / 3);

    var n2 = Math.floor(a[1] / 2);
    if (n2 < ncount) ncount = n2;

    var n3 = Math.floor(a[2] / 2);
    if (n3 < ncount) ncount = n3;

    a[0] -= ncount * 3;
    a[1] -= ncount * 2;
    a[2] -= ncount * 2;

    var sdcount = 0;
    var rf = [0,1,2,0,2,1,0];
    for(var i = 0; i < 7; i++) {
        var test = [...a];
        var end = false;
        var sum = 0;
        var myi = i;

        while (!end) {
            if(test[rf[myi]] === 0) {
                end = true
            }
            else {
                sum ++;
                test[rf[myi]]--;
                myi++;
                if(myi === 7) {
                    myi = 0;
                }
            }

        }
        if(sdcount < sum) {
            sdcount = sum;
        }
    }

    print((ncount * 7) + +sdcount);
}());

'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++].split(' ');
}

function readInt(s) {
    return parseInt(s, 10);
}

function readIntArray(a) {

    return a.map(e => parseInt(e, 10));
}

function solve(n) {
    let a = [0, 1, 2, 0, 2, 1, 0];
    let max = 0;
    for (let i = 0; i < 7; i++) {
        let korm = n.slice(0);
        let days = 0;
        let ok = true;
        for (let j = i; j < 7; j++) {
            if (korm[a[j]] > 0) {
                korm[a[j]]--;
                days++;
            } else {
                ok = false;
                break;
            }
        }
        if (!ok) {
            if (days > max) max = days;
            continue;
        }
        let weeks = Math.min(Math.floor(korm[0] / 3), Math.floor(korm[1] / 2), Math.floor(korm[2] / 2));
        days += weeks * 7;
        korm[0] -= 3 * weeks;
        korm[1] -= 2 * weeks;
        korm[2] -= 2 * weeks;
        for (let j = 0; j < 7; j++) {
            if (korm[a[j]] > 0) {
                korm[a[j]]--;
                days++;
            } else {
                break;
            }
        }
        if (days > max) max = days;
    }
    return max;
}

function main() {

    const a = readIntArray(readLine());
    let result = solve(a);
    console.log(result);
}

'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++].split(' ');
}

function readInt(s) {
    return parseInt(s, 10);
}

function readIntArray(a) {
    return a.map(e => parseInt(e, 10));
}

function solve(n) {
    let a = [0, 1, 2, 0, 2, 1, 0];
    let max = 0;
    for (let i = 0; i < 7; i++) {
        let korm = n.slice(0);
        let days = 0;
        let ok = true;
        for (let j = i; j < 7; j++) {
            if (korm[a[j]] > 0) {
                korm[a[j]]--;
                days++;
            } else {
                ok = false;
                break;
            }
        }
        if (!ok) {
            if (days > max) max = days;
            continue;
        }
        let weeks = Math.min(Math.floor(a[0] / 3), Math.floor(a[1] / 2), Math.floor(a[2] / 2));
        days += weeks * 7;
        korm[0] -= 3 * weeks;
        korm[1] -= 2 * weeks;
        korm[2] -= 2 * weeks;
        for (let j = 0; j < 7; j++) {
            if (korm[a[j]] > 0) {
                korm[a[j]]--;
                days++;
            } else {
                break;
            }
        }
        if (days > max) max = days;
    }
    return max;
}

function main() {

    const a = readIntArray(readLine());

    let result = solve(a);
    console.log(result);
}


Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left.For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.You are given some integer number x. Check if it's a quasi-palindromic number.

The first line contains one integer number x (1 ≤ x ≤ 109). This number is given without any leading zeroes.

Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes).

function pal(s,l,r)
{
    if (r-l<=0)
    {
        return 1;
    }
    return s[l]==s[r]&&pal(s,l+1,r-1);
}

s=readline()
var fl="NO";
for (var i=0;i<=11;i++)
{
    if (pal(s,0,s.length-1))
    {
        fl="YES"
        break;
    }
    s='0'+s
}
print(fl)

/**
 * Created by lukask on 9/24/17.
 */
function isPalindrome(number) {
  var i = 0;
  for (i = 0; i < number.length / 2; i++) {
    // print(number[i] + ' === ' + number[number.length - i - 1]);
    if (number[i] !== number[number.length - i - 1]) {
      return false;
    }
  }
  return true;
}

function isQuasiPalindrome(number) {
  if (isPalindrome(number)) {
    return 'YES';
  }
  var zeroesInFront = 0;
  var zeroesInBack = 0;
  var i = 0;
  while (number[i] === '0') {
    i++;
  }
  zeroesInFront = i;
  i = number.length - 1;
  while (number[i] === '0') {
    i--;
  }
  zeroesInBack = number.length - i - 1;
  if (zeroesInFront > zeroesInBack) {
    // print(zeroesInFront + '  ' + zeroesInBack);
    return 'NO';
  }
  number = number.substring(0, number.length - (zeroesInBack - zeroesInFront));
  // print(number);
  if (isPalindrome(number)) {
    return 'YES'
  }
  // print(zeroesInBack);
  return 'NO';
}

print(isQuasiPalindrome(readline()));

var line = readline();

function isQuasi(input) {
    var end = input.length - 1;
    while (end >= 0 && input[end] === '0') {
        end--;
    }

    var start = 0;
    while (start < end) {
        if (input[start] !== input[end]) {
            return 'NO';
        }

        start++;
        end--;
    }

    return 'YES';
}

print(isQuasi(line));

//var input = readline()

var str = readline().split(' ');
var s = str[0];

// Last char zero delete
var x = s.replace(/0*$/g, '');

// Palindrome check function
function check(str) {
    var s = str.replace(/[^A-Za-z0-9]/g, '').split('').reverse().join('')
    return s == str
}

print(check(x) ? 'YES' : 'NO');

//

var s = readline();

var a = s.replace(/0*$/g, '');
var b = a.replace(/[^A-Za-z0-9]/g, '').split('').reverse().join('');

print(a == b ? 'YES' : 'NO');

var s = readline();

var a = s.replace(/0*$/g, '');
var b = a.split('').reverse().join('');

print(a == b ? 'YES' : 'NO');

//var input = readline()
var str = readline().split(' ');
var s = str[0];

var a = s.replace(/0*$/g, ''); // last char zero delete
var b = a.replace(/[^A-Za-z0-9]/g, '').split('').reverse().join(''); // palindrome check

print(a == b ? 'YES' : 'NO');

//

function trimZeros(num){

    if(!(typeof num == 'number'))
    num = parseInt(num);

    //make a string of the number
    num = num + "";

    //trim leading zeros
    num = parseInt(num);
    num = num + "";

    //trim the last zeros
    num = num.split("").reverse().join("");
    num = parseInt(num);

    return num;
}

function odd(num){
    return ( +num % 2 == 1);
}

function even(num){
    return (!odd(num));
}

function quasiPalindromic(num){

    num = trimZeros(num);
    num = num + "";

    var searchScope;
    if(odd(num)) searchScope = (num.length - 1) / 2;
    else         searchScope =  num.length / 2;

    for(var i = 0; i < searchScope; i++){
        if(!(num[i] == num[num.length-i-1]))
            return "NO";
    }

    return "YES"
}

var inputData = readline();

print(quasiPalindromic(+inputData));

let data = '';
process.stdin.on('data', c => data += c);
const sol = () => {
	let x = Number(data);
	while(x%10 === 0) x /= 10;
	let a = x, b = 0;
	while(x > 0){
		b *= 10;
		b += x%10;
		x = Math.trunc(x/10);
	}
	console.log(a === b?'YES':'NO');
};
process.stdin.on('end', sol);

var line = readline();

function isQuasi(input) {
    var end = input.length - 1;
    while (end >= 0 && input[end] === '0') {
        end--;
    }

    var start = 0;
    while (start < end) {
        if (input[start] !== input[end]) {
            return false;
        }

        start++;
        end--;
    }

    return true;
}

print(isQuasi(line));


Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.

The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).

Print a single integer — the number of hours Vasily can light up the room for.

NoteConsider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.

var str = readline().split(" ");
var n = +str[0];
var m = +str[1];
var res=n;
var r = 0;
while (n>=1) {
    if(n%m==0){
	  n=(n/m);
	  res+=+n;
	  n=n+r;
	  r=0;
    }
	else {
	n--;
	r++;
	}

}
print(res);

var p = readline().split(" ");
var c = parseInt(p[0]);
var s = parseInt(p[1]);
var t;
var w = 0;
var h = 0;

while (c>0) {
	h += c;
	w += c;
	c = ~~(w/s);
	w = w%s;
}

print(h);

var line = readline().split(' ');
var a = parseInt(line[0]);
var b = parseInt(line[1]);

var toRepair = a;
var hours = a;
var leftovers = 0;

while (toRepair >= b) {
  // write(toRepair);

  var repaired = Math.floor(toRepair / b);

  leftovers = toRepair % b;
  hours += repaired;
  toRepair = repaired + leftovers;

  // write(" " + repaired + "\n");
}

print(hours);

/* TEST CASE
Examples
input
4 2
output
7

input
6 3
output
8
*/
function main() {
	var splitted = readline().split(' ');
	var a = parseInt(splitted[0]);
	var b = parseInt(splitted[1]);

	var answer = a;

	if (a >= b) {
		answer += 1 + Math.floor((a - b)/(b - 1));
	}
	print(answer);
}

main();

var l = readline().split(' ')
var a = +l[0], b = +l[1], z = a
for (; a >= b; ) {
	z += Math.floor(a / b)
	a = a % b + Math.floor(a / b)
}
print(z)

var s = readline().split(' ');
var n = Number(s[0]), m = Number(s[1]);

var hours = 0;
hours = n + Math.floor((n-1)/(m-1));

print(hours);

var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var a = ar[0], b = ar[1];
var sum = a;
while(a >= b) {
  var div = Math.floor(a / b);
  var mod = a % b;
  a = mod + div;
  sum += div;
}
print (sum);

function f(a,b,c){
    if (a==0){ return 0; }
    else { return a + f(Math.floor((a+c)/b), b, (a+c)%b); }
}
a = readline().split(' ').map(Number);
print(f(a[0], a[1], 0));

var params = readline().split(" ").map(value => +value);
var a = params[0], b = params[1];
var hours = a, period = b, temp;

while(a >= 1) {
	temp = (a - a % b) / b;
	hours += temp;
	a = temp + (temp > 0) * (a % b);
}

print(hours);

function main() {
    var line = readline().split(' ')
    var a = parseInt(line[0])
    var b = parseInt(line[1])

    var res = solve(a, 0, b, 0)
    print(res);
}

function solve(newc, usedc, b, res) {
    // print(newc, usedc, b, res)
    res += newc
    usedc += newc;
    newc = Math.floor(usedc / b)
    usedc %= b;

    if (newc == 0) {
        return res;
    } else {
        return solve(newc, usedc, b, res);
    }
}

main()

var
    line = readline().split(" "),
    num  = parseInt(line[0]),
    brok = parseInt(line[1])
    h    = num
;

while(num >= brok) {

    var newSt = parseInt(num / brok);
    h += newSt;
    num = newSt + num % brok;

}

print(h);

var line = readline().split(' ').map(Number);

var a = line[0];
var b = line[1];

var leftover = a;

var hours = a;

while(Math.floor(leftover/b)>0){

    hours += Math.floor(leftover/b);
    var temp = leftover%b;
    leftover = Math.floor(leftover/b);
    leftover+=temp;
}

print(hours);

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var ans = 0

while (a >= b)
{
 ans += a - a%b;
 a = a%b + ~~(a/b);
}

print (ans + a)

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var ans = 0

while (a >= b)
{
 ans += a - a%b;
 a = a%b + Math.floor(a/b);
}

print (ans + a)

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var ans = 0

while (a >= b)
{
 ans += a - a%b;
 a = a%b + (a/b)>>0;
}

print (ans + a)

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var cnt = 0, ans = 0

while (a)
{
 a--;
 cnt++;
 ans++;
 if (cnt == b)
 {
  cnt = 0
  a++;
 }
}

print (ans)

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var ans = 0

while (a >= b)
{
 ans += a - a%b;
 a = a%b + (a-a%b)/b;
}

print (ans + a)

var
	r = readline().split(' '),
	a = +r[0],
	b = +r[1],
	result = a
;
while(a >= b){
	var new_value = Math.floor(a / b);
	result += new_value;
	a = a % b + new_value;
}
print(result);

var r= readline().split(' ');
	var a=Number(r[0]);
	var b=Number(r[1]);

	var hours=0;
	hours = a+(Math.floor((a-1)/(b-1)));
	print(hours);

r= readline().split(' ');
a=Number(r[0])
print(a+(Math.floor((a-1)/(Number(r[1])-1))));

        function main(){
            var s = readline().split(' ');
            var a = parseInt(s[0]);
            var b = parseInt(s[1]);

            var answer = a;
            while(parseInt(a/b) > 0){
                answer += parseInt(a / b);
                a = parseInt(a/b) + a % b;
            }
            print(answer);
        }
        main();

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [a, b] = input[0].split(' ').map(x => parseInt(x));
  let answ = a;

  let ost = a;
  while (ost >= b) {
    answ += parseInt(ost/b);
    ost = parseInt(ost/b) + (ost % b);
  }

  console.log(answ);
});

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let [a, b] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let s = a;
	let hours = 0;

	while (Math.floor(a / b) > 0) {
		hours += Math.floor(a / b);
		a = Math.floor(a / b) + (a % b);
	}

	console.log(Math.round(s + hours));
}

var ab = readline().split(' ');
var a = parseInt(ab[0]);
var b = parseInt(ab[1]);

var ret = 0;

while(a >= b){
	ret += b;
	a = a-b+1;
}

ret += a;

print(ret);

var input = readline().split(" "), a = +input[0], b = +input[1], hours = 0, rest = 0;

for(i = 0; a > 0 ;i++){
	hours += a;
	rest += a%b;
	a = Math.floor(a/b) + Math.floor(rest/b);
	if(rest/b >= 1){
		rest -= Math.floor(rest/b)*b;
	}
}
write(hours);

var solve = function(n,m) {
  var res = 0;
  var b = 0;
  while (n > 0) {res ++; n--; b++; if (b == m) {n++; b = 0;}}
  return res;
}

var str = readline().split(' ');
var n = +str[0];
var m = +str[1];
print(solve(n,m));

var line = readline();
var arr = line.split(" ");
var sum = parseInt(arr[0]);
var rest = "0";

while(arr[0]>0) {
    arr[0] = +arr[0] + +rest;
    rest = Math.floor(arr[0]%arr[1]);
    arr[0] = Math.floor(arr[0]/arr[1]);
    sum = +sum + +arr[0];
}

print(sum)

var token = readline().split(' ');

var a = token[0], b = token[1];
var wasted = 0;
var ans = 0;

while(a>0) {
  ++wasted;
  --a;

  ++ans;

  if(wasted==b) {
    wasted=0;
    ++a;
  }
}

print(ans);

var r = readline().split(' ');
var a = +r[0];
var b = +r[1];
var result = a;
while(a >= b){
	result += Math.floor(a / b);
	a = a % b + Math.floor(a / b);
}
print(result);

var
	r = readline().split(' '),
	a = +r[0],
	b = +r[1],
	result = a
;
while(a >= b){
	result += parseInt(a / b);
	a = a % b + parseInt(a / b);
}
print(result);

var data = readline().split(' ').map(function (e) { return parseInt(e) })
a = data[0]
b = data[1]

r = a
burnedCandle = a

while (burnedCandle >= b) {
    newBurndeCandle = Math.trunc(burnedCandle / b)
    r += newBurndeCandle
    burnedCandle -= newBurndeCandle * b
    burnedCandle += newBurndeCandle
}

print(r)

var line = readline().split(' ');
var a = parseInt(line[0]);
var b = parseInt(line[1]);

var res=0;
var rest =0;

	while (a>=1){

	res+= a;
	rest += ( a - Math.floor(a/b)*b);

		a = Math.floor(a/b);

		if (rest>=b) {
		a+=Math.floor(rest/b);
		rest-=b;
		}

	}

print(res);

;(function () {

	var s = readline().split(' ');
	var a = +s[0], b = +s[1], d = 0, t = 0;

	do {
		t += a;
		d += a;
		a = Math.floor(d / b);
		d -= a * b;
	} while ( (d+a) >= b )

	t += a;

	print(t);

}).call(this);

var s = readline().split(" ");
var a = Number(s[0]), b = Number(s[1]);

var hours = 0;
var left = 0;
while(a!==0) {
    hours++;
    left++;
    a--;
    if (left === b) {
        a++;
        left = 0;
    }
}
print(hours);

r= readline().split(' ');
a=Number(r[0])
print(a+(a-1)/(Number(r[1])-1)>>0);

'use strict'

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
}

let temp = readline().getNumArray(),
    a = temp[0],
    b = temp[1],
    usedA = 0,
    hours = 0;

while(a) {
  a--;
  usedA++;
  hours++;
  if(usedA === b) {
    usedA = 0;
    a++;
  }
};

write(hours);

var r= readline().split(" ");
	var a=Number(r[0]) ,  b=Number(r[1]);

	var hours=0;
	hours = a+Math.floor((a-1)/(b-1));
	print(hours);

var line = readline().split(' ');
var a = parseInt(line[0]);
var b = parseInt(line[1]);
var h = a;
var extra = Math.floor(a/b);
var burned = extra;
var rest = a%b;
while(extra>=1){
h=h+burned;
extra = Math.floor((burned+rest)/b);
rest = (burned+rest)%b;
burned = extra;
}

print(h);

var candils= readline().split(' ');
	var a=Number(candils[0]);
	var b=Number(candils[1]);

	var hours=0;
	hours = a+(Math.floor((a-1)/(b-1)));
    print(hours);
    // console.log(hours);

var str = readline().split(" ");
var n = str[0];
var m = str[1];
var res=0;
while (n>=1) {
   res+=+n;
   n=n/m;
}
print(Math.round(res));

var str = readline().split(" ");
var n = str[0];
var m = str[1];
var res=0;
while (n>=1) {
   res+=+n;
   n=n/m;
}
print(res);

var str = readline().split(" ");
var n = str[0];
var m = str[1];
var res=0;
while (n>=1) {
   res+=+n;
   n=n/m;
}
print(Math.ceil(res));

var line = readline().split(' ');
var a = parseInt(line[0]);
var b = parseInt(line[1]);

var toRepair = a;
var hours = a;
var leftovers = 0;

while (toRepair >= b) {
  // write(toRepair);
  toRepair = toRepair + leftovers;

  var repaired = Math.floor(toRepair / b);
  leftovers = toRepair % b;

  hours += repaired;
  toRepair = repaired;

  // write(" " + repaired + "\n");
}

print(hours);

var line = readline().split(' ');
var a = parseInt(line[0]);
var b = parseInt(line[1]);

var toRepair = a;
var hours = a;

// print(6 / 3 / 3);

while (toRepair >= b) {
  var repaired = Math.floor(toRepair / b);

  hours += repaired;
  toRepair = repaired;

  // print(toRepair, repaired);
}

print(hours);

var l = readline().split(' ')
var a = +l[0], b = +l[1], z = 0
for (; a; a = Math.floor(a / b)) {
	z += a
}
print(z)

var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var a = ar[0], b=ar[1], h = a;
while (true){
  a /= b;
  h+=Math.floor(a);
  if (a < 1) break;
}
print (h);

var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var a = ar[0], b=ar[1], h = 0;
while (true){
  h+= a;
  a = a / b;
  if (a < 0.0000000000001) { h += a; break };
}
print (Math.floor(h));

var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var a = ar[0], b=ar[1], h = a;
while (true){
  a /= b;
  h+=Math.floor(a);
  if (a < b) break;
}
print (h);

var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var a = ar[0], b=ar[1], rem = 0, h = a;
while (true){
  h+=Math.floor(a / b);
  a = Math.floor(a / b)  + a % b;
  if (a < b) { h += a; break };
}
print (h);

var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var a = ar[0], b=ar[1], h = 0;
while (true){
  h+= Math.floor(a);
  a = Math.floor(a / b);
  if (a < b) { h += Math.floor(a); break };
}
print (h);

var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var a = ar[0], b=ar[1], h = 0;
while (true){
  h+= Math.floor(a);
  a =a / b;
  if (a < b) { h += Math.floor(a); break };
}
print (h);

function f(a,b,c){
    if (a==0){ return 0; }
    else { return a + f(Math.floor((a+c)/b), b, a%b); }
}
a = readline().split(' ').map(Number);
print(f(a[0], a[1], 0));

print(function f(a,b){
    if (a==0){ return 0;
    } else { return a + f(Math.floor(a/b), b);}
}.apply(0,readline().split(' ').map(Number)));

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var ans = 0

while (a >= b)
{
 ans += a - a%b;
 a = a%b + ~~a/b;
}

print (ans + a)

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var cnt = 0, ans = 0

while (a >= b)
{
 ans += a - a%b;
 a = a%b + a/b;
}

print (ans + a)

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var ans = 0

while (a >= b)
{
 ans += (a / b) * b;
 a = a%b + a/b;
}

print (ans + a)

var l = readline().split (" ");

var a = parseInt(l[0])
var b = parseInt(l[1])
var ans = 0

while (a >= b)
{
 ans += a - a%b;
 a = a%b + a/b;
}

print (ans + a)

var a=readline();
var b=readline();
var sum = a;
while(a>=b){
   sum += parseInt(a / b);
	a = a % b + parseInt(a / b);
}
print(sum);

r= readline().split(' ');
a=Number(r[0])
print(a+(a-1)/(Number(r[1])-1));

function main(){
   var s = readline().split();

   var a = parseInt(s[0]);
   var b = parseInt(s[1]);

   var answer = a;
   while(a/b > 0){
       answer += a / b;
       a /= b;
   }
   print(answer);
}
main();

function main(){
   var s = readline().split();

   var a = parseInt(s[0]);
   var b = parseInt(s[1]);

   var answer = a;
   while(parseInt(a/b) > 0){
       answer += parseInt(a / b);
       a = bparseInt(a/b);
   }
   print(answer);
}
main();

function main(){
   var s = readline().split();

   var a = parseInt(s[0]);
   var b = parseInt(s[1]);

   var answer = a;
   while(parseInt(a/b) > 0){
       answer += parseInt(a / b);
       a = parseInt(a/b);
   }
   print(answer);
}
main();

function main(){
   var s = readline().split(' ');

   var a = parseInt(s[0]);
   var b = parseInt(s[1]);

   var answer = a;
   while(parseInt(a/b) > 0){
       answer += parseInt(a / b);
       a = parseInt(a/b);
   }
   print(answer);
}
main();

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [a, b] = input[0].split(' ').map(x => parseInt(x));
  let answ = a;

  let ost = a;
  while (ost > 0) {
    answ += parseInt(ost/b);
    ost = parseInt(ost/b);
  }

  console.log(answ);
});

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let [a, b] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let s = a;
	let hours = 0;

	while (Math.floor(a / b) !== 0) {
		hours += Math.floor(a / b);
		a = Math.floor(a / b);
	}

	console.log(s + hours);
}

var line = readline().split(' ');
var a = parseInt( line[0] );
var b = parseInt( line[1] );

var ret = b; 2
while( (a = a-b+1) >= b){
	ret += b;
}
ret += a;
print(ret);

var line = readline().split(' ');
var a = parseInt( line[0] );
var b = parseInt( line[1] );

var ret = b;
while( (a = a-b+1) >= b){
	ret += b;
}
ret += a;
print(ret);

var line = readline().split(' ');
var a = parseInt( line[0] );
var b = parseInt( line[1] );

var ret = a;

a = a - b + 1;
while( (a = a-b+1) > 0){

	ret += a;
}
print(ret);

var line = readline().split(' ');
var a = parseInt( line[0] );
var b = parseInt( line[1] );

var ret = a;

while( a=~~(a/b) ){
	ret += a;
}
print(ret);

var line = readline().split(' ');
var a = parseInt( line[0] );
var b = parseInt( line[1] );

var ret = a-b;
while( (a = a-b+1) > 0){

	ret += a;
}
print(ret);

var input = readline().split(" "), a = +input[0], b = +input[1], hours = 0, rest = 0;

for(i = 0; a > 0 ;i++){
	hours += a;
	rest += (a/b > 1) ? a%b : 0;
	a = Math.floor(a/b) + Math.floor(rest/b);
	if(rest/b >= 1){
		rest -= Math.floor(rest/b)*b;
	}
}
write(hours);

var line = readline();
var arr = line.split(" ");
var sum = 0;

while(arr[0]>0) {
    sum+=parseInt(arr[0]);
    arr[0] = Math.floor(arr[0]/arr[1])
}

print(sum)

var token = readline().split(' ');

var a = token[0], b = token[1];
var ans = 0, curr = 1;

while(curr<=a) {
  ans+=((a/curr)>>0);
  curr*=b;
}

print(ans);

var r = readline().split(' ');
var a = +r[0];
var b = +r[1];

var result = 0;
	if(b % 2 == 0 && a !== b){
		result = (a + b) + 1;
	}else if(b % 2 == 0 && a === b){
		result = a + 1;
	}else if(b % 2 !== 0 && a !== b){
		result = (a + b) - 1
	}else if(b % 2 !== 0 && a === b){
		result = a - 1;
	}

print(result);

var r = readline();
var a = +r[0];
var b = +r[1];

if(b % 2 == 0){
	var result = a + a/b + 1;
}else {
	var result = a + a/b;
}
print(result);

var r = readline().split(' ');
var a = +r[0];
var b = +r[1];
var z = a;
for(;a >= b; ){
	z += Math.floor(a / b);
	a = Math.floor(a / b);
}
print(z);

var r = readline();
var a = +r[0];
var b = +r[1];

var result = 0;
if(b % 2 == 0){
	result = a + a/b + 1;
}else {
	result = a + a/b;
}
print(result);

var r = readline();
var a = +r[0];
var b = +r[1];

var result = 0;
	if(b % 2 !== 0){
		result = a + b + 1;
	}else {
		result = a + b - 1;
	}
print(result);

var r = readline();
var a = +r[0];
var b = +r[1];
var result = 0;
var i = 0;

// while(a -= 2){
// 	result += a;
// 	i++;
// }

var result = 0;
if(b % 2 == 0){
	result = a + (a/b) + 1;
}else {
	result = a + (a/b);
}
print(result);

var r = readline();
var a = +r[0];
var b = +r[1];
var result = 0;
var i = 0;

// while(a -= 2){
// 	result += a;
// 	i++;
// }

var result = 0;
if(b % 2 == 0){
	result += (a + (a/b) + 1);
}else {
	result += (a + (a/b));
}
print(result);

var r = readline().split(' ');
var a = +r[0];
var b = +r[1];

var result = 0;
	if(b % 2 == 0){
		result = (a + b) + 1;
	}else {
		result = (a + b) - 1;
	}
print(result);

var r = readline();
var a = +r[0];
var b = +r[1];

var result = 0;
	if(b % 2 == 0){
		result = a + b + 1;
	}else {
		result = a + b - 1;
	}
print(result);

var r = readline().split(' ');
var a = +r[0];
var b = +r[1];

var result = 0;
	if(b % 2 == 0){
		result = (a + (a/b)) + 1;
	}else {
		result = (a + (a/b)) - 1;
	}
print(result);

var data = readline().split(' ').map(function (e) { return parseInt(e) })
a = data[0]
b = data[1]

r = a
burnCandle = a

while (burnCandle >= b) {
    r += Math.trunc(burnCandle / b)
    burnCandle = Math.trunc(burnCandle / b)
}

print(r)

var line = readline().split(' ');
var a = parseInt(line[0]);
var b = parseInt(line[1]);

var res=0;

while (a>=1){

res+= a;

a = Math.floor(a/b);

}

print(res);

var s = readline().split(" ");
var a = Number(s[0]), b = Number(s[1]);

var hours = 0;
var left = 0;
while(a!==0) {
    hours++;
    left++;
    a--;
    if (left === b) {
        a++;
    }
}
print(hours);

var r= readline().split('');
	var a=Number(r[0]);
	var b=Number(r[1]);

	var hours=0;
	hours = a+Math.floor((a-1)/(b-1));
	print(hours);

var r= readline().split("'");
	var a=Number(r[0]) ,  b=Number(r[1]);

	var hours=0;
	hours = a+Math.floor((a-1)/(b-1));
	print(hours);

var r= readline().split('');
	var a=Number(r[0]);
	var b=Number(r[1]);

	var hours=0;
	hours = a+(Math.floor((a-1)/(b-1)));
	print(hours);

var r= readline().split('');
	var a=Number(r[1]);
	var b=Number(r[2]);

	var hours=0;
	hours = a+Math.floor((a-1)/(b-1));
	print(hours);

var r= readline().split("");
	var a=Number(r[0]) ,  b=Number(r[1]);

	var hours=0;
	hours = a+Math.floor((a-1)/(b-1));
	print(hours);


Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.

The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.

Output amount of years from the current year to the next lucky one.

NoteIn the first example next lucky year is 5. In the second one — 300. In the third — 5000.

  var n = parseInt(readline());
  var s = n.toString().split('');

  if(s[0] === '9') {
    print(parseInt('1' + new Array(s.length).fill(0).join('')) - n);
  } else {
    print(parseInt((parseInt(s[0]) + 1).toString() + new Array(s.length - 1).fill(0).join('')) - n);
  }

var a =parseInt(readline());
var sol=2000000000;
function min(a,b){
  if(a<b)return a;
  return b;
}
function recurse(cur){
  if(cur>a){
    sol=min(sol,cur);
    return;
  }
  if(cur==0){
    for (var i = 1; i <= 9; i++) {
     recurse(i);
    }
  }
  else
   recurse(cur*10);
}
recurse(0);
print(sol-a);

var input = readline();
var n = input;
var val = [0];
while (true) {
  val[0] = (val[0] + 1) % 10;
  if (val[0] === 0) {
    val.push(0);
    val[0] = 1;
  }
  if (+(val.join('')) > +n) {
    print(+(val.join('')) - +n);
    break;
  }
}

var data = readline();
var a = String(data);
var b;
var c = '';
var d;

if(a.length == 1) {
  d = parseInt(a) + 1;
  d = d-parseInt(a)
  print(d);

} else {
  b = parseInt(a[0])+1;
  for(var i = 1; i< a.length; i++) {
     c += '0';
  }

  b = parseInt(String(b)+c);

  print(b-parseInt(a));
}

var a = parseInt(readline());
var t = 1;
var b = 0;
for (var i = 1; i <= 10; i ++)
{
	if (a/Math.pow(10, i) < 1)
	{
		t = Math.pow(10, i-1);
		b = parseInt(a/t) * t;
		break;
	}
}
print(t+b-a);

var a =parseInt(readline());
var sol=200000000;
function min(a,b){
  if(a<b)return a;
  return b;
}
function recurse(cur){
  if(cur>a){
    sol=min(sol,cur);
    return;
  }
  if(cur==0){
    for (var i = 1; i <= 9; i++) {
     recurse(i);
    }
  }
  else
   recurse(cur*10);
}
recurse(0);
print(sol-a);

var input = readline();

var n = input;

if (n.indexOf('0') != -1) {
  var m = n.split('');
  for (var i = m.indexOf('0') + 1; i < m.length; i++) {
    if (m[i] === '0') {
      m[i] = '1';
    }
  }
  print(+(m.join('')) - +n);
} else {
  print(10 - (+n[n.length - 1]));
}

var data = readline();
var a = String(data);
var b,c='';

if(a.length == 1) {
  a = parseInt(a) + 1;
  print(a)
} else {
  b = parseInt(a[0])+1;
  for(var i = 1; i< a.length; i++) {
     c += '0';
  }

  b = parseInt(String(b)+c);

  print(b-parseInt(a));
}

var data = readline();
var a = String(data);
var b;
var c = '';
var d;

if(a.length == 1) {
  d = parseInt(a) + 1;
  d = d-parseInt(a)
  print(d);

} else {
  b = parseInt(a[0])+1;
  for(var i = 1; i< a.length; i++) {
     c += '0';
  }

  b = parseInt(String(b)+c);

  print(typeof b-parseInt(a));
}

var data = readline();
var a = String(data);
var b;
var c = '';

if(a.length == 1) {
  a = parseInt(a) + 1;
  print(a);

} else {

  b = parseInt(a[0])+1;
  for(var i = 1; i< a.length; i++) {
     c += '0';
  }

  b = parseInt(String(b)+c);

  print(b-parseInt(a));
}


One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.—No problem! — said Bob and immediately gave her an answer.Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.

The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.

Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var s = trim(readline()), guess = trim(readline());
	if (s == '0') {
		print(guess == '0' ? "OK" : "WRONG_ANSWER");
		return;
	}

	var digits = [];
	for (var i = 0; i < s.length; i += 1) {
		digits.push(s[i]);
	}
	digits.sort();

	if (digits[0] == '0') {
		for (var i = 1; i < digits.length; i += 1) {
			if (digits[i] != '0') {
				digits[0] = digits[i];
				digits[i] = '0';
				break;
			}
		}
	}

	var correct = digits.join('');
	print(guess == correct ? "OK" : "WRONG_ANSWER");
}

main();

var N = readline()
var M = readline()

var n = N.split('').sort()

var i = 0
while (n[i++] == '0') {}
i--

if (i) {
	n[0] = n[i]
	n[i] = '0'
}

n = n.join('')

print(M == n ? 'OK' : 'WRONG_ANSWER')

const readline = require('readline');

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

function main() {
    comparison(stdin[0],stdin[1])
}

var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);
/*
const main = async () => {
  await question1()
  rl.close()
}

main()
*/

function comparison(n, m) {
  var firstStr = String(n);
  if(String(n).length == 1 || String(m).length == 1){
      return n == m ? console.log("OK") : console.log("WRONG_ANSWER")
  }
  var result = '';
  var count = 0
  while( firstStr ) {
    var min = 999;
    for(var i = 0; i < firstStr.length; i++) {
      if(Number(firstStr[i] < min)) {
      	if(count == 0 && Number(firstStr[i]) == 0){
        } else {
        	min = firstStr[i]
        }
      }
  	}
    var index = firstStr.indexOf(min);
    result += firstStr.slice(index, index+1)
    firstStr = firstStr.slice(0, index) + firstStr.slice(index+1, firstStr.length)
    count ++
  }
  if(result == m) {
  	console.log("OK")
  } else {
  	console.log("WRONG_ANSWER")
  }
}

const readline = require('readline');

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

const question1 = () => {
  return new Promise((resolve, reject) => {
    rl.question("", answer );//=>
    rl.question("", answer2 );

  	console.log("answer");
  	console.log(answer);
    {
      comparison(answer, answer2)
      resolve()
    }
  })
}

const main = async () => {
  await question1()
  rl.close()
}

main()

function comparison(n, m) {
  var firstStr = String(n);
  if(String(n).length == 1 || String(m).length == 1){
      return n == m ? console.log("OK") : console.log("WRONG_ANSWER")
  }
  var result = '';
  var count = 0
  while( firstStr ) {
    var min = 999;
    for(var i = 0; i < firstStr.length; i++) {
      if(Number(firstStr[i] < min)) {
      	if(count == 0 && Number(firstStr[i]) == 0){
        } else {
        	min = firstStr[i]
        }
      }
  	}
    var index = firstStr.indexOf(min);
    result += firstStr.slice(index, index+1)
    firstStr = firstStr.slice(0, index) + firstStr.slice(index+1, firstStr.length)
    count ++
  }
  	console.log(result);
  	console.log(m);
  if(result == m) {
  	console.log("OK")
  } else {
  	console.log("WRONG_ANSWER")
  }
}


You are given an integer sequence $$$1, 2, \dots, n$$$. You have to divide it into two sets $$$A$$$ and $$$B$$$ in such a way that each element belongs to exactly one set and $$$|sum(A) - sum(B)|$$$ is minimum possible.The value $$$|x|$$$ is the absolute value of $$$x$$$ and $$$sum(S)$$$ is the sum of elements of the set $$$S$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^9$$$).

Print one integer — the minimum possible value of $$$|sum(A) - sum(B)|$$$ if you divide the initial sequence $$$1, 2, \dots, n$$$ into two sets $$$A$$$ and $$$B$$$.

NoteSome (not all) possible answers to examples:In the first example you can divide the initial sequence into sets $$$A = \{1, 2\}$$$ and $$$B = \{3\}$$$ so the answer is $$$0$$$.In the second example you can divide the initial sequence into sets $$$A = \{1, 3, 4\}$$$ and $$$B = \{2, 5\}$$$ so the answer is $$$1$$$.In the third example you can divide the initial sequence into sets $$$A = \{1, 4, 5\}$$$ and $$$B = \{2, 3, 6\}$$$ so the answer is $$$1$$$.

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

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  if(N % 4 == 2 || N % 4 == 1){
    myout(1);
  }else{
    myout(0);
  }
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (d) => {
  const [n] = [d].map(BigInt);
  const total = n * (n + 1n) / 2n;

  console.log((total % 2n).toString());
});

var n =parseInt(readline());
print(Math.ceil(n/2)%2);

function main() {
    var n = +readline();
    if(n === 1 || n === 2)
        return 1;
    if(n === 3 || n === 0 || n%4 === 0)
        return 0;
    if(n%2 === 0)
        return 1;

    var a = Math.floor((n + 1) / 4);
    if(a * 4 - 1 === n)
        return 0;
    return 1
}

print(main());

function main(n){

    var ans = [0,1,1,0];
    var printe = 0;
    if(n>=4)printe = ans[n%4];
    else  printe = ans[n]
    print(printe);
}

var n = parseInt(readline());

main(n);

var a = readline().split(' ');
print(Math.ceil(a/2)%2)

var n = readline().split(' ');
print(Math.ceil(n/2)%2)

function calc(n) {
  if (n === 0 || n % 4 === 0 || n % 4 === 3) {
    return 0
  } else {
    return 1
  }
}

var n = parseInt(readline());

print(calc(n));

var number = parseInt(readline());
var result = number % 4;
print(result === 1 || result ===2 ? 1 : 0);

var n = readline();
n = parseInt(n);

if (n%4 == 0 || n%4 == 3) print (0)
	else print (1);

 var n = readline();
    print( ((1 + n) * n / 2) % 2 );

var n = readline();
var s = (1 + n) * n / 2;
print( s % 2 === 0 ? 'YES' : 'NO');

function main() {
    var n = +readline();
    if(n === 1 || n === 2)
        return 1;
    if(n === 3 || n === 0 || n%4 ===0)
        return 0;
    if(n%2 === 0)
        return 1;

    var a = Math.floor((n + 1) / 4);
    if(a * 4 + 1 === n)
        return 0;
    return 1
}

print(main());

function main(n){

    var ans = [0,1,1,0];
    var printe = 0;
    if(n>=4)printe = ans[n%4];
    else if (ans < 4) printe = ans[n]
    print(printe);
}

var n = parseInt(readline());

main(n);

var a = readline().split(' ');
print(a);
var sum = 0;
for(var i=1; i<=a; i++) {
    sum+=i;
}

print(sum%2)

var n = readline().split(' ');
var ans = (n*(1+n))/2;
print(ans%2);