EQUINOX - Editorial


Contest Division 1
Contest Division 2
Contest Division 3

Setter: Anshul Garg
Tester & Editorialist: Taranpreet Singh






Given N words consisting of Uppercase English characters and two integers A and B, two players Sarthak and Anuradha play a game. For each word, if the first character of the word appears in string “EQUINOX”, Sarthak gets A points, otherwise Anuradha gets B points. The person with higher score wins.


  • Simulate the process, maintaining the scores and compare them.


Since this is an easier problem, all we need to do is to simulate the game. Start with scores for both players being zero and consider word one by one.

To check if first characters appears in string EQUINOX, one naive way would be to write 7 if conditions. It works, but too much work for nothing. We can simplify it.

One way would be to us would be to create a string EQUINOX and use the inbuild find function to check whether the character appears in string EQUINOX or not.

Another way would be to make an array or a set.

Following code snippet depict the intended solution

SarthakScore = 0
AnuradhaScore = 0
for word in wordList:
     if word[0] in EQUINOX:
          SarthakScore += A
          AnuradhaScore += B

Don’t forget to use long data type, since the scores can easily go beyond 32 bit integer range.


The time complexity is O(\sum |S_i|) per test case, since we read that as input.


Setter's Solution
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define int long long
string tt = "EQUINOX";
void solve(){
    int n, a, b;
    int ans1 = 0, ans2 = 0; cin >> n >> a >> b;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        int f = 0;
        for(int j = 0; j < tt.size(); j++){
            if(tt[j] == s[0]) f = 1;
        if(f) ans1 += a;
        else ans2 += b;
    if(ans1 == ans2) cout << "Draw\n";
    else if(ans1 > ans2) cout << "Sarthak\n";
    else cout << "Anuradha\n";
signed main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    int t;
    cin >> t;
    while(t--) solve();
Tester's Solution
import java.util.*;
import java.io.*;
class EQUINOX{
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int N = ni();
        long A = nl(), B = nl();
        long sarthak = 0, anuradha = 0;
        String pattern = "EQUINOX";
        for(int i = 0; i< N; i++){
            String word = n();
            if(pattern.contains(word.substring(0,1)))sarthak += A;
            else anuradha += B;
        if(sarthak > anuradha)pn("SARtHak");
        else if(sarthak < anuradha)pn("aNUrAdHA");
        else pn("draW");
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    static boolean multipleTC = true;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
    public static void main(String[] args) throws Exception{
        new EQUINOX().run();
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
            return st.nextToken();

        String nextLine() throws Exception{
            String str = "";
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            return str;

Feel free to share your approach. Suggestions are welcomed as always. :slight_smile:

can you please share editorial in java…it was giving me TLE.

Solution: 45687865 | CodeChef

why my sol not working i feel my logic right

1 Like

Try this input:

2 1 100

It should answer ANURADHA but your code answered SARTHAK.

1 Like

why my code is not working just throwing WA.

I write perfect code. but it shows wrong ans. Can anyone tell me whats wrong in my code?

#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
int main()
long long int t;
cin >> t;
long long int n, a, b;
cin >> n >> a >> b;
int sc1 = 0;
int sc2 = 0;
string s;
for(int i = 0; i < n; i++)
cin >> s;
if(s[0] == ‘E’ || s[0] == ‘Q’ || s[0] == ‘U’ || s[0] == ‘I’ || s[0] == ‘N’ || s[0] == ‘O’ || s[0] == ‘X’)
sc1 += a;
} else {
sc2 += b;
if(sc1 > sc2)
cout << “SARTHAK” << endl;
else if (sc1 < sc2)
cout << “ANURADHA” << endl;
else {
cout << “DRAW” << endl;
return 0;


My code is in java only.

Where is the mistake . pls anyone can tell?


@cubefreak777 and other coders please try to debug the error. Because of this problem I lost 70 points


On again going back to successful solutions. I am shocked to see a correct answer with same logic


using namespace std;

int main() {
int t,n,a,b;
char ch;

for(int i=0;i<t;i++)
int sarthak=0,anuradha=0;

 for(int i=0;i<=n;i++)
     string S;
     getline(cin, S);
     if(S[0]=='E' || S[0]=='Q' || S[0]=='U' || S[0]=='I' || S[0]=='N' || S[0]=='O' || S[0]=='X')

 std::cout << "SARTHAK" << std::endl;
 else if(anuradha>sarthak)
 std::cout << "ANURADHA" << std::endl;
 std::cout << "DRAW" << std::endl;


return 0;


Can anyone tell what’s wrong
It’s running correct for every test case.

1 Like

Hi Shubh, if you see above replies, most of them are having same problem. I am not understanding why the solutions are not getting accepted while if you see my answer there is another solution I have linked which is having exact same solution and received correct answer

Yeah exactly
I saw other people’s code and all of them are same still no running, should I mail to codechef or something because I spent too much time on this one

1 Like

I dont know, if this fault of the system or the code, but whatever it is. It should be taken under notice. I will also mail the codechef team. In your code I think the mistake was in “anuradha=anuradha-b” which can even lead anuradhas points in negative. Other than that the whole solution is correct as per my logic

int sarthak = 0, annu = 0;
instead of int use long long

Ohh okay
Let me check again

Your logic is correct but you forgot to use long long.


same here.

what is wrong in this code of mine.?


Ohh okay
Thanks for the help

I think you can make the long long before sarthak and anuradha as well as A ans B. Then submit the code.