304 North Cardinal St.
Dorchester Center, MA 02124

# Dark Light CodeChef Solution

## Problem – Dark Light CodeChef Solution

Tonmoy has a special torch. The torch has 4 levels numbered 1 to 4 and 2 states (On and Off). Levels 1,2, and 3 correspond to the On state while level 4 corresponds to the Off state.

The levels of the torch can be changed as:

• Level 1 changes to level 2.
• Level 2 changes to level 3.
• Level 3 changes to level 4.
• Level 4 changes to level 1.

Given the initial state as K and the number of changes made in the levels as N, find the final state of the torch. If the final state cannot be determined, print Ambiguous instead.

### Input Format

• First line will contain T, the number of test cases. Then the test cases follow.
• Each test case contains of a single line of input, two integers N,K – the number of changes made in the levels and initial state of the torch. Here, K=0 denotes Off state while K=1 denotes On state.

### Output Format

For each test case, output in a single line, the final state of the torch, i.e. On or Off. If the final state cannot be determined, print Ambiguous instead.

You may print each character of the string in uppercase or lowercase (for example, the strings On, ON, on and oN will all be treated as identical).

• 1≤T≤10^5
• 0≤N≤10^9
• 0≤K≤1

### Sample 1:

``````Input:
3
4 0
0 1
3 1
Output:
Off
On
Ambiguous``````

### Explanation:

Test Case 1: Initially, the torch is in Off state. Since only level 4 corresponds to the Off state, the torch is at level 4 initially. After 4 changes, the final level would be 4. Level 4 corresponds to the Off state. Hence, finally the torch is Off.

Test Case 2: Initially, the torch is in On state. After 0 changes, the torch remains in the On state.

Test Case 3: Initially, the torch is in On state. This can correspond to any of the first 3 levels. Thus, we cannot determine the final level after 3 changes. Hence, the final state is Ambiguous.

## Dark Light CodeChef Solution in C++17

``````#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
int t,k;
ll n;
cin>>t;
while(t--){
cin>>n>>k;
if(k==0){
if(n%4==0)
cout<<"Off"<<endl;
else
cout<<"On"<<endl;
}
else{
if(n%4==0)
cout<<"On"<<endl;
else
cout<<"Ambiguous"<<endl;
}
}
return 0;
}
``````

## Dark Light CodeChef Solution in Pyth 3

``````# cook your dish here
t=int(input())
for i in range(t):
n,k=map(int, input().split(' '))
if( n %  4 == 0 ):
if(k==1):
print("On")
else:
print("Off")
elif( n % 4 != 0 ):
if( k == 0 ):
print("On")
elif( k == 1 ):
print("Ambiguous")``````

## Dark Light CodeChef Solution in Java

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args){
Scanner scan =new Scanner(System.in);
int t = scan .nextInt();
while(t-->0){
int n= scan.nextInt();
int k= scan.nextInt();
int a= n%4;
if(k==0){
if(a==0){
System.out.println("Off");
}
else{
System.out.println("On");
}
}
else if(k==1){
if(a==0){
System.out.println("On");
}
else{
System.out.println("Ambiguous");
}
}
}
}
}
``````
##### Dark Light CodeChef Solution Review:

In our experience, we suggest you solve this Dark Light CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Dark Light CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Dark Light CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions