Skip to main content
Back to problems
Codeforces
Easy
Math
Arrays
Even Odds

Find the kk-th number in a sequence formed by listing all odd numbers up to nn first, then all even numbers up to nn.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

You are given two integers nn and kk. Consider the sequence of numbers from $1toton$ arranged in this order:

  1. All odd numbers in increasing order
  2. All even numbers in increasing order

Your task is to output the kk-th number in this sequence.

For example, when n=10n=10, the sequence is:

1 3 5 7 9 2 4 6 8 10

and the 7-th element is 4.

Goal

Return the value at position kk without constructing the entire sequence if possible.

Input Format

  • A single line contains two integers nn and kk.
  • 1kn1 \le k \le n.

Output Format

  • Print one integer: the kk-th element of the described ordering.

Constraints

  • 1kn1 \le k \le n
  • 1n1091 \le n \le 10^9

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.