forked from rakes-git/Hacktoberfest2K21-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpp template.txt
245 lines (213 loc) · 5.5 KB
/
cpp template.txt
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
Template
//--------------------------//
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
double eps = 1e-12;
ll MOD = 998244353;
ll mod = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define nl "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define MAXN 1e5 + 5
#define int long long
// -------------------Modular Operations------------------- //
int add(int x, int y)
{
int res = x + y;
return(res >= mod ? res - mod : res);
}
int multiply(int x, int y)
{
int res = x * y;
return(res >= mod ? res % mod : res);
}
int subtract(int x, int y)
{
int res = x - y;
return(res < 0 ? res + mod : res);
}
int power(long long x, unsigned int y, int p)
{
int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// -------------------Sieve of Erastothenes------------------- //
bool sieve_of_eratosthenes(int n)
{
vector<bool> is_prime(n+1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i] && (long long)i * i <= n) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
return is_prime[n];
}
// -------------------Number of Divisors------------------- //
int NODiv(int n)
{
int cnt = 0;
for(int i = 1;i * i <= n;i++)
{
if(i * i == n)
{
cnt++;
continue;
}
cnt += 2;
}
return cnt;
}
// -------------------nCr(Binomial)------------------- //
int nCr(int n, int k)
{
if(n < k)
{
return 0;
}
if(k == 0)
{
return 1;
}
int res = 1;
for (int i = n - k + 1; i <= n; ++i)
res *= i;
for (int i = 2; i <= k; ++i)
res /= i;
return res;
}
// -------------------Checking Prime (O(root(n))------------------- //
bool isPrime(int x) {
for (int d = 2; d * d <= x; d++) {
if (x % d == 0)
return false;
}
return true;
}
// -------------------Adding Egdes to the Graph------------------- //
vector<vector<int>>adj;
void addEdge(int x, int y)
{
adj[x].push_back(y);
adj[y].push_back(x);
}
// -------------------DFS------------------- //
// vector<bool>visited; // resize in the solve() with n + 1
// void dfs(int v)
// {
// visited[v] = true;
// for(auto i:adj[v])
// {
// if(!visited[i])
// {
// dfs(i);
// }
// }
// }
// -------------------DIJKSTRA------------------- //
// vector<int>d;
// vector<int>p;
// void dijkstra(int s)
// {
// int n = adj.size();
// d.assign(n, INF);
// p.assign(n, -1);
// d[s] = 0;
// using pii = pair<int, int>;
// priority_queue<pii, vector<pii>, greater<pii>>q;
// q.push({0, s});
// while(!q.empty())
// {
// int v = q.top().second;
// int d_v = q.top().first;
// q.pop();
// if(d_v != d[v])
// {
// continue;
// }
// for (auto edge : adj[v])
// {
// int to = edge.first;
// int len = edge.second;
// if (d[v] + len < d[to])
// {
// d[to] = d[v] + len;
// p[to] = v;
// q.push({d[to], to});
// }
// }
// }
// }
// -------------------RESTORING SHORTEST PATH------------------- //
// vector<int>path;
// void restore_path(int s, int t)
// {
// for(int v = t;v != s;v = p[v])
// {
// path.push_back(v);
// }
// path.push_back(s);
// reverse(path.begin(), path.end());
// }
// -------------------Important Notes------------------- //
// For Interactive Problems remember to remove multi test cases condition //
// (int)log2(x) + 1 -> to calculate number of bits of a number
// s.erase(0, min(s.find_first_not_of('0'), s.size()-1)); //for removing leading zero's
// (int index = str.find(substr, pos)) != string::npos // for checking substring 'substr' in string 'str'
// -----------------------Solve------------------------ //
int main()
{
return 0;