# AGOC - Editorial

Contest

Setter: a0n0k0i0t
Tester: a0n0k0i0t
Editorialist: a0n0k0i0t

Easy

Basic Maths

# Explanation:

### Observation:

The most optimum approach to reach 0 is obivously to use 5 to subtract maximum possible times.
For a number N let X = N % 5
So,
if (X is even):
you can subtract 5 unti N is X
if(X in odd):
you can subtract 5 until N is X+5

rest of the operations will be subtracting 2.

### Time complexity:

O(1) for each test case

# SOLUTION

``````#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
ll T;
cin>>T;
for(int _=0;_<T;_++){
ll x,y;
cin>>x>>y;
ll cnt1=0,cnt2=0;
ll a=x/5;
cnt1+=a;
x-=a*5;
if(x%2){
x+=5;
cnt1--;
}
cnt1+=x/2;

ll b=y/5;
cnt2+=b;
y-=b*5;
if(y%2){
y+=5;
cnt2--;
}
cnt2+=y/2;

if(cnt1<cnt2)cout<<"Ram\n";
else if(cnt1>cnt2)cout<<"Shyam\n";
else cout<<"Draw\n";

}
return 0;
}
``````

What’s up it’s me, I am also visiting this website daily, this website is really pleasant and the viewers are really sharing good thoughts.