Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Codeforces Round 1056/A. El fucho
Next
CodeforcesCodeforces
Newbie
Codeforces Round 1056

A. El fucho

Math
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

Juan and his friends are going to split themselves into π‘›

 teams and play a modified double-elimination football tournament, consisting of a winners' group and a losers' group. Initially, all teams belong to the winners' group.

In each round of the tournament, the following happens as long as one of the groups has at least two teams:

  • All teams in the winners' group pair up.
  • If there is an odd number of teams in the winners' group, there would be a team that didn't get paired up (and wouldn't play a match). That team stays in the winners' group.
  • For teams in the winners' that got paired up, each pair plays a football match in which there are no ties.
  • If a team wins, it stays in the winners' group.
  • If a team loses, it drops down to the losers' group in the next round.
  • All teams in the losers' group pair up.
  • If there is an odd number of teams in the losers' group, there would be a team that didn't get paired up (and wouldn't play a match). That team stays in the losers' group.
  • For teams in the losers' that got paired up, each pair plays a football match in which there are no ties.
  • If a team wins, it stays in the losers' group.
  • If a team loses, it gets eliminated from the tournament.

Note that in the above process, when a team loses a match in the winners' group, it drops down to the losers' group in the next round. That means, it is not considered for the pairing process in the current round's losers' group.

After multiple iterations of the aforementioned process, both groups end up with a single team each. When this happens, both teams face off against each other in a match and a victor emerges.

Determine how many matches were played in total. It can be proved that no matter how the teams are paired up and which ones win and lose, the answer remains the same.

Input


Each test contains multiple test cases. The first line contains the number of test cases π‘‘

 (1≀𝑑≀100

). The description of the test cases follows.

The only line of each test case contains one positive integer π‘›

 (2≀𝑛≀500

) β€” the number of teams.

Output


For each test case, print the total number of matches played during the tournament.

Example

Input

Copy

2
2
3

Output

Copy

2
4

Note


In the first test case, it can be proved that exactly 2

 matches are played before a victor is declared.

In the second test case, the image below shows one possible tournament. Notice that 4

 matches were played in total.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Codeforces Round 1056
Next Problem