# FASTWAY - Editorial

Tester: sayan_244, dhrub_kumar, ominking, a_18o3, ashish_aryan02

Cakewalk

Basic Maths

# Explanation

The problem asks us to find the minimum possible number of days required for Joseph Cooper to reach his daughter Murph Cooper, given their current days of the week.

If Murph’s day M is on or after Joseph’s day N, then he can simply wait until day M arrives. The number of days he needs to wait is M - N.

As Joseph can travel in both directions in time the obvious case is him travelling either forward or backward in time which can be found by using abs(M - N). The second case we need to consider is that since the timeline is circular we should also find the number of days Joseph has to wait if he chooses the other path by using the formula (7 - abs(M - N)).

Now that we have found the number of days required to travel in both directions, to get the minimum possible number of days required, we can take the minimum of the two cases, i.e., min(abs(M - N), 7 - abs(M - N)).

# SOLUTIONS:

Setter's Solution
``````def solve():
c,g = list(map(int,input().split()))
print(min(abs(g-c),(7-abs(g-c))))

t = int(input())
for i in range(t):
solve()
``````
Tester's Solution
``````// #define _GLIBCXX_DEBUG 1
// #define _GLIBCXX_DEBUG_PEDANTIC 1
// #define _FORTIFY_SOURCE 2

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int lli;
typedef long double ld;
#define plli pair<lli,lli>
#define pb push_back
#define fir first
#define sec second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
constexpr lli mod=(1000*1000*1ll*1000)+7;
// constexpr lli mod=998244353;
constexpr lli inf=4ll*(((1000*1000*1ll*1000)*(1000*1000*1ll*1000))+50);
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<lli,null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
// remove _equal from less_equal to make it ordered set , currently it is ordered_multiset

// lli powermod(lli a, lli b,lli mod)
// {
//     lli res = 1;
//     while (b > 0) {
//         if (b & 1)
//             res = ((res%mod)*(a%mod))%mod;
//         a = (a * a)%mod;
//         b >>= 1;
//     }
//     return res%mod;
// }

// used for custom hashing in unordered_map , unordered_set
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};

int main(){
lli T,i=0,j;
T=1;
cin>>T;
while(T--){
lli x,y;
cin>>x>>y;
lli ans;
if(y<x)
ans=min(7ll-x+y,x-y);
else
ans=min(x+7ll-y,y-x);
cout<<ans<<"\n";
}
return 0;
}
``````