#include<bits/stdc++.h> using namespace std; #define inf 1e18 #define endl '\n' #define int long long typedef long long ll; typedef pair<int,int> pii; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ksm(int base,int p,int mod){ int res=1; while(p){ if(p&1) res=res*base%mod; bas...