# Bear and Milky Cookies Codechef Solution

Limak is a little polar bear, who loves eating cookies and drinking milk. For this reason he often visits Chef’s kitchen.

Limak is going to spend N minutes in the kitchen. Each minute he either eats a cookie or drinks milk. Cookies are very sweet and thus Limak’s parents have instructed him, that after eating a cookie, he has to drink milk in the next minute.

You are given whether he ate a cookie or drank milk in each of the N minutes. Your task is to check if Limak followed his parents’ instructions. That is, you need to verify whether after each eaten cookie he drinks milk in the next minute. Print “YES” or “NO” for each test case accordingly.

### Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each test case contains an integer N denoting the number of minutes.

The second line of a test case contains N space-separated strings S1S2, …, SN. The string Si is either “cookie” (if Limak eats a cookie in the i-th minute) or “milk” (otherwise).

### Output

For each test case, output a single line containing the answer — “YES” if Limak followed his parents’ instructions, and “NO” otherwise, both without the quotes.

### Constraints

• 1 ≤ T ≤ 50
• 1 ≤ N ≤ 50
• Each Si is either “cookie” or “milk” (without the quotes).

• Subtask #1 (40 points) N = 2
• Subtask #2 (60 points) Original constraints

### Sample Input 1

```4
7
5
4
milk milk milk milk
1
```

```YES
NO
YES
NO```

## Bear and Milky Cookies   – CodeChef Solution in JAVA

```import java.util.*;
import java.io.*;
public class Main {

public static void main(String[] args) throws IOException {
try{
Scanner sc=new Scanner(System.in);
while(t-->0){
String[] s=s1.split(" ");
boolean flag=true;
if(s[n-1].compareTo(c)==0)
flag=false;
for(int i=0;i<n-1;i++){
if(s[i].compareTo(s[i+1])==0&&s[i].compareTo(c)==0)
flag=false;
}

if(flag)
System.out.println("YES");
else
System.out.println("NO");
}

}catch(Exception e){return;}
}
}```

## Bear and Milky Cookies – CodeChef Solution in CPP

```#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s[n];
For(i,0,n){
cin>>s[i];
}
bool ans=1;
For(i,0,n){
ans=0;
break;
}
}
if(ans) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
```

## Bear and Milky Cookies   -CodeChef Solution in Python

```for t in range(int(input())):
N = int(input())
S = input()
if (S[-4:] != "milk"):
print("NO")
else: