Chef and An Ideal Problem Codechef Solution

Chef and An Ideal Problem Codechef Solution: “An ideal problem has no test data.” – aryanc403

This is an interactive problem.

Chef likes probability puzzles a lot, almost as much as interactive problems. Today, he learned about the Monty Hall Paradox.

Suppose that Chef is participating in a game show, where he has to choose between three doors numbered 11 through 33. There is a car behind one of the doors and goats behind the other two. Chef does not know what is behind which door, but there is a game host who knows where the car is.

First, you need to help Chef pick a door (let’s denote it by XX). Then, the host opens a different door (let’s denote it by YY) such that there is a goat behind this door, and asks Chef to pick an arbitrary door again (let’s denote it by ZZ). You need to help Chef pick door ZZ too. You should do it in such a way that the probability of a car being behind door ZZ is maximised. If there are multiple optimal possible ways to pick doors for Chef, you may choose any one.


  • First, you should print a line containing a single integer XX (1≤X≤31≤X≤3).
  • Then, you should read a line containing a single integer YY.
  • Finally, you should print a line containing a single integer ZZ (1≤Z≤31≤Z≤3).

Don’t forget to flush the output after printing each line!


  • 1≤Y≤31≤Y≤3
  • X≠YX≠Y


You                     Grader

Chef and An Ideal Problem CodeChef Solution in JAVA

import java.util.*;
import java.lang.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
	public static void main (String[] args) throws java.lang.Exception
			Scanner input = new Scanner(;
		int x = input.nextInt();
		System.out.println((x == 2 ? 3 : 2));

Chef and An Ideal Problem CodeChef Solution in CPP

using namespace std;
int main(){
    int x = 1, y , z;
    cout << x << endl;
    cin >> y;
    cout << 6 - x - y << endl;
    return 0;

Chef and An Ideal Problem CodeChef Solution in Python

if n==2:

Disclaimer: The above Problem (Chef and An Ideal Problem) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring

Leave a Comment