Jack and Jill (1 Point)


Jack and Jill

Jack and Jill went up the hill Swapping neighbour numbers. With n at 11 and k at 7, Jack felt unencumbered.

To his dismay, Jill did play, A rather cunning game. One by one, the numbers come, With victory there to claim

Next came 1, the game not done And with that the air had tensed. With Jack to play, 10 he did say But their difference, too immense!

Jack and Jill are climbing up a hill, and to pass the time they are playing a game of neighbour numbers. In the game, they start by picking two values, nn and kk. The game then consists of them taking turns saying numbers from 11 to nn.

There are only two rules in neighbour numbers:

  • No number can be repeated
  • For the iith turn, that number must have a distance of kk or less from the i−1i-1th number.

In this problem, we are Jill, and we'll simply be implementing a player for the game of neighbour numbers. We don't need to win, just not to make any illegal moves.

Interaction

This problem is interactive, which means you will need to collect input and print output multiple times.

The interaction will start with a line containing two space-separated integers, nn and kk. Next, you should output a single integer, your first move in the game. Each time you print an integer, the judge will then respond with another integer.

You should interact in one of three possible ways:

  • If their move was invalid, print "I win!", and the program ends.
  • If you have no possible move, "You win!", and the program ends.
  • Otherwise, print a valid integer response, and interaction continues.

Interaction Examples

Example 1: Jack (judge) prints an invalid answer
Sample 1
[Jack]: 5 2
[Jill]: 3
[Jack]: 1
[Jill]: 2
[Jack]: 5
[Jill]: I win!

This is invalid because 5 and 2 are distance 3 (>k=2>k=2) distance apart.

Example 2: Jill has no response
Sample 2
[Jack]: 10 1
[Jill]: 2
[Jack]: 1
[Jill]: You win!

Interaction Template (Python)

Code 1
# Alternatively, this can be done with
# n, k = list(map(int, input().split()))
n_str, k_str = input().split()
n, k = int(n_str), int(k_str)

first_num = ...
# Jill's first number
print(first_num)
# Judge's first number
judge_response = int(input())
# Jill's response
print(...)

Constraints

  • 1≤n≤1031 \leq n \leq 10^3
  • 1≤k≤1021 \leq k \leq 10^2
  • Every integer answer from Jack will be a number from 11 to nn.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.