-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxavierCppTemplate.cpp
300 lines (247 loc) · 14.9 KB
/
xavierCppTemplate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
▄ ██ ▄ ▄█ ▄███▄ █▄▄▄▄ ███ ▄███▄ ██ ▄▄▄▄▄ ▄▄▄▄▀
▀▄ █ █ █ █ ██ █▀ ▀ █ ▄▀ █ █ █▀ ▀ █ █ █ ▀▄ ▀▀▀ █
█ ▀ █▄▄█ █ █ ██ ██▄▄ █▀▀▌ █ ▀ ▄ ██▄▄ █▄▄█ ▄ ▀▀▀▀▄ █
▄ █ █ █ █ █ ▐█ █▄ ▄▀ █ █ █ ▄▀ █▄ ▄▀ █ █ ▀▄▄▄▄▀ █
█ ▀▄ █ █ █ ▐ ▀███▀ █ ███ ▀███▀ █ ▀
▀ █ █▐ ▀ █
▀ ▐ ▀
*/
/**
* xavierbeast68
* URL : Problem_URL
* AVOIDING COMPLEXITY, REDUCES BUGS.
*/
//*****************************************************TEMPLATE START*****************************************************************
#pragma GCC optimize("O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
// using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define cendl cout << endl;
#define int long long
using ll = long long;
using ull = unsigned long long;
using lld = long double;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vpi> vvpi;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
constexpr ll MOD1 = 1e9 + 7; //1000000007
constexpr ll MOD2 = 1e9 + 9; //1000000009
constexpr ll MOD3 = 998244353;
constexpr lld EPS = 1e-9;
constexpr lld PI = 3.1415926535897932384626;
#define inf INT_MAX
#define minf INT_MIN
#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define pb push_back
#define ppb pop_back
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define mp(x,y) make_pair(x,y)
#define lb(arr, x) lower_bound(arr.begin(), arr.end(), x) - arr.begin();
#define ub(arr, x) upper_bound(arr.begin(), arr.end(), x) - arr.begin();
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} // for Vector v
/*------------------------------------------------------Read & Print Methods------------------------------------------------------*/
#define read(x) cin >> x;
#define readInt(x) int x; cin >> x; // reads long long
#define readStr(x) string x; cin >> x; // reads string(word)
#define readLine(x) string x; getline(cin, x); // reads string(sentence)
#define print(x) cout<<(x)<<" "
#define println(x) cout<<(x)<<endl
// Vector Read & Print ->
// template <class T> vector<T> readvector(T n) { vector<T> arr(n); for (int i = 0; i < n; i++) {cin >> arr[i];} return arr;} // vector<ll> arr = readvector(n);
// template <class T> void printvector(vector<T> arr) {for (int i = 0; i < (int)arr.size(); i++) {cout << arr[i] << " ";} cout << endl;} // printvector(arr, n);
// Streams ->
template<class T, class V>istream& operator>>(istream &in, pair<T, V> &a){in >> a.first >> a.second;return in;}
template<class T>istream& operator>>(istream &in, vector<T> &a){for(auto &i: a){in >> i;} return in;}
template<class T, class V>ostream& operator<<(ostream &os, pair<T, V> &a){os << a.first << " " << a.second;return os;}
template<class T>ostream& operator<<(ostream &os, vector<T> &a){for(int i = 0 ; i < sz(a) ; i++){if(i != 0){os << ' ';}os << a[i];}return os;}
//InputOutputError_From/To_File ->
void file_io()
{
// #ifndef ONLINE_JUDGE
#ifdef XAVIERBEAST
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
}
/*----------------------------------------------------------------PBDS----------------------------------------------------------------*/
// template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // ordered_set <T> a; (work as ordered_set) // ordered_set <pair<T, T>> a; (ordered set of pairs (can also work as ordered_map))
// template <class T> using multi_ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>; // multi_ordered_set <T> a; // multi_ordered_set <pair<T,T>> a;
// order_of_key(k): Returns the number of elements strictly smaller than k.
// find_by_order(k): Returns the address of the element at kth index in the set while using zero-based indexing, i.e the first element is at index zero.
/*--------------------------------------------------------------Debugger--------------------------------------------------------------*/
// [di:b^b-ing]
// -Being the detective in a crime
// where you are also the murderer.
#define test(i) cerr << "(#" << i << ")" << endl
// #ifndef ONLINE_JUDGE
#ifdef XAVIERBEAST
#define dbg(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define dbg(x);
#endif
// #pragma warning disable format
// void _print(int t) {cerr << t;}
void _print(ll t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
// void _print(auto t) {cerr << *t;} // for ordered_set
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(unordered_set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(deque <T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]";}
template <class T> void _print(stack <T> v) { cerr << "[ "; while(!v.empty()) { _print(v.top()); v.pop(); cerr << " "; } cerr << "]";}
// template <class T> void _print(ordered_set<T> v) { cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]";}
// void _print(ordered_set v) {cerr << "[ "; for (int i=0 ; i<(int)v.size();i++) {_print(v.find_by_order(i)); cerr << " ";} cerr << "]";}
/*------------------------------------------------------Functions------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;}
ll countDigit(ll n) {return (floor(log10(n) + 1));}
ll log_a_to_base_b(ll a, ll b) {return log2(a) / log2(b);}
ll isPowerof2(ll x) {return (x && !(x & (x - 1)));} // Checking if given 64 bit integer is power of 2
bool is_whole(ll a) {return (a - floor(a) < 1e-9);} // floor(a)==ceil(a)
ll factorial(const int& p) {if (p <= 1) {return 1;} return p * factorial(p - 1);}
double nCr(ll n, ll r) {double sum = 1; for(int i = 1; i <= r; ++i){sum = sum * (n - r + i) / i;} return sum;}
// ll binpow(ll a , ll b,ll mod) {if (b == 0) {return 1;} if (b == 1) {return a;} if (b % 2 == 0) {return binpow((a * a) % mod, b / 2, mod);} else {return (a * binpow((a * a) % mod, b / 2, mod)) % mod;}} // binary exponentiation
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
ll mod_inv(ll x, ll mod) {return binpow(x, mod-2, mod);}
ll _mod(ll x, ll mod) {return (((x) % mod + mod) % mod);}
ll mod_add(ll a, ll b, ll mod) {a = a % mod; b = b % mod; return (_mod(a+b, mod));}
ll mod_mul(ll a, ll b, ll mod) {a = a % mod; b = b % mod; return (_mod(a*b, mod));}
ll mod_sub(ll a, ll b, ll mod) {a = a % mod; b = b % mod; return (_mod(a-b, mod));}
ll mod_div(ll a, ll b, ll mod) {return _mod(_mod(a, mod) * _mod(mod_inv(b, mod), mod), mod);}
vector<string> split(string s, char delimeter) {vector <string> tokens; stringstream check1(s); string intermediate; while (getline(check1, intermediate, delimeter)) { tokens.push_back(intermediate); } return tokens;}
ll stringToNo(string s) {stringstream din(s); ll x; din >> x; return x;}
void toLower(string& s) {transform(s.begin(), s.end(), s.begin(), ::tolower);}
void toUpper(string& s) {transform(s.begin(), s.end(), s.begin(), ::toupper);}
// random number generator
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng); }
// Prime utility
bool isPrime(ll n) {if (n == 2 || n == 3) {return true;} if (n <= 1 || n % 2 == 0 || n % 3 == 0) {return false;} for (int i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) {return false;}} return true;}
int sz = 1e6 + 5;
bool PrimeSieve[1000005]; // 1e6+5
void buildSieve(){
for (int i = 2; i <= sz; i++)
PrimeSieve[i] = 1;
PrimeSieve[0] = 0; //
PrimeSieve[1] = 0; // 1 is neither prime nor composite
for (int i = 2; i < sz; i++){
if (PrimeSieve[i] == 0)
continue; // the current number itself is composite
for (int j = 2; j * i < sz; j++){
PrimeSieve[i * j] = 0;
}
}
}
/*
//--- Custom Hash(for random hashing)---
// https://codeforces.com/blog/entry/62393
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);
}
};
template <typename T> // Key should be integer type
using safe_set = unordered_set<T, custom_hash>;
template <typename T1, typename T2> // Key should be integer type
using safe_map = unordered_map<T1, T2, custom_hash>;
*/
//--for grid operations--
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
// #pragma warning restore format
//*********************************************************TEMPLATE ENDS***************************************************************
/*-------------------------------------------------------||||||||||-----------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
|H| |e| |r| |e| |w| |e| |g| |o| |!| |!| |!|
+-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------||||||||||------------------------------------------------------------------------*/
/*
! THINGS TO KEEP IN MIND BEFORE SUBMITTTING
* Always Check Which MOD it is Asking For
* Unique function return iterator Then We can resize the container
* Look for Possible Edge Cases
* int overflows, array bounds, etc.
* https://oeis.org/ Sequence Related Problem
* DO NOT GET STUCK ON ONE APPROACH
*/
/*
*Thought Process*
!---------------!
*/
void solve(){
//--Let's Code--
}
//---------------------------------------- DON'T TOUCH IT ----------------------------------------
// signed main(signed argc, char const *argv[])
signed main(){
fastio;
cout << fixed << setprecision(10);
// file_io();
auto start = high_resolution_clock::now();
//testcases=1: default value for single test case
int testcases = 1;
// cin >> testcases;
while (testcases--){
solve();
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
// #ifndef ONLINE_JUDGE
#ifdef XAVIERBEAST
cerr << endl << "Time: " << (float)duration.count()/1000000 << " s" << endl;
#endif
return 0;
}